int oe_socketpair(int domain, int type, int protocol, int retfd[2])
{
    int ret = -1;
    ssize_t retval;
    oe_fd_t* socks[2] = {0};
    oe_device_t* device;
    uint64_t devid = OE_DEVID_HOST_SOCKET_INTERFACE;

    /* Resolve the device id. */
    if (!(device = oe_device_table_get(devid, OE_DEVICE_TYPE_SOCKET_INTERFACE)))
        OE_RAISE_ERRNO(OE_EINVAL);

    if ((retval = device->ops.socket.socketpair(
             device, domain, type, protocol, socks)) < 0)
    {
        OE_RAISE_ERRNO_MSG(
            OE_EINVAL,
            "retval=%zd devid=%lu, domain=%d type=%d protocol=%d",
            retval,
            devid,
            domain,
            type,
            protocol);
    }

    if ((retfd[0] = oe_fdtable_assign(socks[0])) < 0)
        OE_RAISE_ERRNO(oe_errno);

    if ((retfd[1] = oe_fdtable_assign(socks[1])) < 0)
        OE_RAISE_ERRNO(oe_errno);

    ret = (int)retval;
    socks[0] = NULL;
    socks[1] = NULL;

done:

    if (socks[0])
        socks[0]->ops.fd.close(socks[0]);

    if (socks[1])
        socks[1]->ops.fd.close(socks[1]);

    return ret;
}
int oe_socketpair(int domain, int type, int protocol, int retfd[2])
{
    int ret = -1;
    ssize_t retval;
    oe_fd_t* socks[2] = {0};
    oe_device_t* device;
    uint64_t devid = OE_DEVID_HOST_SOCKET_INTERFACE;

     
    if (!(device = oe_device_table_get(devid, OE_DEVICE_TYPE_SOCKET_INTERFACE)))
        OE_RAISE_ERRNO(OE_EINVAL);

    if ((retval = device->ops.socket.socketpair(
             device, domain, type, protocol, socks)) < 0)
    {
        OE_RAISE_ERRNO_MSG(
            OE_EINVAL,
            "retval=%zd devid=%lu, domain=%d type=%d protocol=%d",
            retval,
            devid,
            domain,
            type,
            protocol);
    }

    if ((retfd[0] = oe_fdtable_assign(socks[0])) < 0)
        OE_RAISE_ERRNO(oe_errno);

    if ((retfd[1] = oe_fdtable_assign(socks[1])) < 0)
        OE_RAISE_ERRNO(oe_errno);

    ret = (int)retval;
    socks[0] = NULL;
    socks[1] = NULL;

done:

    if (socks[0])
        socks[0]->ops.fd.close(socks[0]);

    if (socks[1])
        socks[1]->ops.fd.close(socks[1]);

    return ret;
}