vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)

{

    char control[CMSG_SPACE(VHOST_MEMORY_MAX_NREGIONS * sizeof(int))] = { };

    struct iovec iov = {

        .iov_base = (char *)vmsg,

        .iov_len = VHOST_USER_HDR_SIZE,

    };

    struct msghdr msg = {

        .msg_iov = &iov,

        .msg_iovlen = 1,

        .msg_control = control,

        .msg_controllen = sizeof(control),

    };

    size_t fd_size;

    struct cmsghdr *cmsg;

    int rc;



    do {

        rc = recvmsg(conn_fd, &msg, 0);

    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));



    if (rc <= 0) {

        vu_panic(dev, "Error while recvmsg: %s", strerror(errno));

        return false;

    }



    vmsg->fd_num = 0;

    for (cmsg = CMSG_FIRSTHDR(&msg);

         cmsg != NULL;

         cmsg = CMSG_NXTHDR(&msg, cmsg))

    {

        if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {

            fd_size = cmsg->cmsg_len - CMSG_LEN(0);

            vmsg->fd_num = fd_size / sizeof(int);

            memcpy(vmsg->fds, CMSG_DATA(cmsg), fd_size);

            break;

        }

    }



    if (vmsg->size > sizeof(vmsg->payload)) {

        vu_panic(dev,

                 "Error: too big message request: %d, size: vmsg->size: %u, "

                 "while sizeof(vmsg->payload) = %zu\n",

                 vmsg->request, vmsg->size, sizeof(vmsg->payload));

        goto fail;

    }



    if (vmsg->size) {

        do {

            rc = read(conn_fd, &vmsg->payload, vmsg->size);

        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));



        if (rc <= 0) {

            vu_panic(dev, "Error while reading: %s", strerror(errno));

            goto fail;

        }



        assert(rc == vmsg->size);

    }



    return true;



fail:

    vmsg_close_fds(vmsg);



    return false;

}

vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)

{

    char control[CMSG_SPACE(VHOST_MEMORY_MAX_NREGIONS * sizeof(int))] = { };

    struct iovec iov = {

        .iov_base = (char *)vmsg,

        .iov_len = VHOST_USER_HDR_SIZE,

    };

    struct msghdr msg = {

        .msg_iov = &iov,

        .msg_iovlen = 1,

        .msg_control = control,

        .msg_controllen = sizeof(control),

    };

    size_t fd_size;

    struct cmsghdr *cmsg;

    int rc;



    do {

        rc = recvmsg(conn_fd, &msg, 0);

    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));



    if (rc <= 0) {

        vu_panic(dev, "Error while recvmsg: %s", strerror(errno));

        return false;

    }



    vmsg->fd_num = 0;

    for (cmsg = CMSG_FIRSTHDR(&msg);

         cmsg != NULL;

         cmsg = CMSG_NXTHDR(&msg, cmsg))

    {

        if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {

            fd_size = cmsg->cmsg_len - CMSG_LEN(0);

            vmsg->fd_num = fd_size / sizeof(int);

            memcpy(vmsg->fds, CMSG_DATA(cmsg), fd_size);

            break;

        }

    }



    if (vmsg->size > sizeof(vmsg->payload)) {

        vu_panic(dev,

                 "Error: too big message request: %d, size: vmsg->size: %u, "

                 "while sizeof(vmsg->payload) = %zu\n",

                 vmsg->request, vmsg->size, sizeof(vmsg->payload));

        goto fail;

    }



    if (vmsg->size) {

        do {

            rc = read(conn_fd, &vmsg->payload, vmsg->size);

        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));



        if (rc <= 0) {

            vu_panic(dev, "Error while reading: %s", strerror(errno));

            goto fail;

        }



        assert(rc == vmsg->size);

    }



    return true;



fail:

    vmsg_close_fds(vmsg);



    return false;

}

    if (rc <= 0) {
FUNC_0(VuDev *VAR_0, int VAR_1, VhostUserMsg *VAR_2)

{

    char VAR_3[CMSG_SPACE(VHOST_MEMORY_MAX_NREGIONS * sizeof(int))] = { };

    struct iovec VAR_4 = {

        .iov_base = (char *)VAR_2,

        .iov_len = VHOST_USER_HDR_SIZE,

    };

    struct msghdr VAR_5 = {

        .msg_iov = &VAR_4,

        .msg_iovlen = 1,

        .msg_control = VAR_3,

        .msg_controllen = sizeof(VAR_3),

    };

    size_t fd_size;

    struct cmsghdr *VAR_6;

    int VAR_7;



    do {

        VAR_7 = recvmsg(VAR_1, &VAR_5, 0);

    } while (VAR_7 < 0 && (errno == EINTR || errno == EAGAIN));



    if (VAR_7 <= 0) {

        vu_panic(VAR_0, "Error while recvmsg: %s", strerror(errno));

        return false;

    }



    VAR_2->fd_num = 0;

    for (VAR_6 = CMSG_FIRSTHDR(&VAR_5);

         VAR_6 != NULL;

         VAR_6 = CMSG_NXTHDR(&VAR_5, VAR_6))

    {

        if (VAR_6->cmsg_level == SOL_SOCKET && VAR_6->cmsg_type == SCM_RIGHTS) {

            fd_size = VAR_6->cmsg_len - CMSG_LEN(0);

            VAR_2->fd_num = fd_size / sizeof(int);

            memcpy(VAR_2->fds, CMSG_DATA(VAR_6), fd_size);

            break;

        }

    }



    if (VAR_2->size > sizeof(VAR_2->payload)) {

        vu_panic(VAR_0,

                 "Error: too big message request: %d, size: VAR_2->size: %u, "

                 "while sizeof(VAR_2->payload) = %zu\n",

                 VAR_2->request, VAR_2->size, sizeof(VAR_2->payload));

        goto fail;

    }



    if (VAR_2->size) {

        do {

            VAR_7 = read(VAR_1, &VAR_2->payload, VAR_2->size);

        } while (VAR_7 < 0 && (errno == EINTR || errno == EAGAIN));



        if (VAR_7 <= 0) {

            vu_panic(VAR_0, "Error while reading: %s", strerror(errno));

            goto fail;

        }



        assert(VAR_7 == VAR_2->size);

    }



    return true;



fail:

    vmsg_close_fds(VAR_2);



    return false;

}

FUNC_0(VuDev *VAR_0, int VAR_1, VhostUserMsg *VAR_2)
{ char VAR_3[CMSG_SPACE(VHOST_MEMORY_MAX_NREGIONS * sizeof(int))] = { }; struct iovec VAR_4 = { .iov_base = (char *)VAR_2,
.iov_len = VHOST_USER_HDR_SIZE,
}; struct msghdr VAR_5 = { .msg_iov = &VAR_4,
.msg_iovlen = 1,
.msg_control = VAR_3,
.msg_controllen = sizeof(VAR_3),
}; size_t fd_size; struct cmsghdr *VAR_6; int VAR_7; do { VAR_7 = recvmsg(VAR_1, &VAR_5, 0); } while (VAR_7 < 0 && (errno == EINTR || errno == EAGAIN)); if (VAR_7 <= 0) { vu_panic(VAR_0, "Error while recvmsg: %s", strerror(errno)); return false; } VAR_2->fd_num = 0; for (VAR_6 = CMSG_FIRSTHDR(&VAR_5); VAR_6 != NULL; VAR_6 = CMSG_NXTHDR(&VAR_5, VAR_6))
{ if (VAR_6->cmsg_level == SOL_SOCKET && VAR_6->cmsg_type == SCM_RIGHTS) { fd_size = VAR_6->cmsg_len - CMSG_LEN(0); VAR_2->fd_num = fd_size / sizeof(int); memcpy(VAR_2->fds, CMSG_DATA(VAR_6), fd_size); break; } } if (VAR_2->size > sizeof(VAR_2->payload)) { vu_panic(VAR_0,
"Error: too big message request: %d, size: VAR_2->size: %u, "
"while sizeof(VAR_2->payload) = %zu\n",
VAR_2->request, VAR_2->size, sizeof(VAR_2->payload)); goto fail; } if (VAR_2->size) { do { VAR_7 = read(VAR_1, &VAR_2->payload, VAR_2->size); } while (VAR_7 < 0 && (errno == EINTR || errno == EAGAIN)); if (VAR_7 <= 0) { vu_panic(VAR_0, "Error while reading: %s", strerror(errno)); goto fail; } assert(VAR_7 == VAR_2->size); } return true; fail:
vmsg_close_fds(VAR_2); return false; }