static int nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply,

                             int len)

{

    NBDClient *client = req->client;

    int csock = client->sock;

    int rc, ret;



    qemu_co_mutex_lock(&client->send_lock);

    qemu_set_fd_handler2(csock, NULL, nbd_read, nbd_restart_write, client);

    client->send_coroutine = qemu_coroutine_self();



    if (!len) {

        rc = nbd_send_reply(csock, reply);

        if (rc == -1) {

            rc = -errno;

        }

    } else {

        socket_set_cork(csock, 1);

        rc = nbd_send_reply(csock, reply);

        if (rc != -1) {

            ret = qemu_co_send(csock, req->data, len);

            if (ret != len) {

                errno = EIO;

                rc = -1;

            }

        }

        if (rc == -1) {

            rc = -errno;

        }

        socket_set_cork(csock, 0);

    }



    client->send_coroutine = NULL;

    qemu_set_fd_handler2(csock, NULL, nbd_read, NULL, client);

    qemu_co_mutex_unlock(&client->send_lock);

    return rc;

}

static int nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply,

                             int len)

{

    NBDClient *client = req->client;

    int csock = client->sock;

    int rc, ret;



    qemu_co_mutex_lock(&client->send_lock);

    qemu_set_fd_handler2(csock, NULL, nbd_read, nbd_restart_write, client);

    client->send_coroutine = qemu_coroutine_self();



    if (!len) {

        rc = nbd_send_reply(csock, reply);

        if (rc == -1) {

            rc = -errno;

        }

    } else {

        socket_set_cork(csock, 1);

        rc = nbd_send_reply(csock, reply);

        if (rc != -1) {

            ret = qemu_co_send(csock, req->data, len);

            if (ret != len) {

                errno = EIO;

                rc = -1;

            }

        }

        if (rc == -1) {

            rc = -errno;

        }

        socket_set_cork(csock, 0);

    }



    client->send_coroutine = NULL;

    qemu_set_fd_handler2(csock, NULL, nbd_read, NULL, client);

    qemu_co_mutex_unlock(&client->send_lock);

    return rc;

}

static int FUNC_0(NBDRequest *VAR_0, struct nbd_reply *VAR_1,

                             int VAR_2)

{

    NBDClient *client = VAR_0->client;

    int VAR_3 = client->sock;

    int VAR_4, VAR_5;



    qemu_co_mutex_lock(&client->send_lock);

    qemu_set_fd_handler2(VAR_3, NULL, nbd_read, nbd_restart_write, client);

    client->send_coroutine = qemu_coroutine_self();



    if (!VAR_2) {

        VAR_4 = nbd_send_reply(VAR_3, VAR_1);

        if (VAR_4 == -1) {

            VAR_4 = -errno;

        }

    } else {

        socket_set_cork(VAR_3, 1);

        VAR_4 = nbd_send_reply(VAR_3, VAR_1);

        if (VAR_4 != -1) {

            VAR_5 = qemu_co_send(VAR_3, VAR_0->data, VAR_2);

            if (VAR_5 != VAR_2) {

                errno = EIO;

                VAR_4 = -1;

            }

        }

        if (VAR_4 == -1) {

            VAR_4 = -errno;

        }

        socket_set_cork(VAR_3, 0);

    }



    client->send_coroutine = NULL;

    qemu_set_fd_handler2(VAR_3, NULL, nbd_read, NULL, client);

    qemu_co_mutex_unlock(&client->send_lock);

    return VAR_4;

}

static int FUNC_0(NBDRequest *VAR_0, struct nbd_reply *VAR_1,
int VAR_2)
{ NBDClient *client = VAR_0->client; int VAR_3 = client->sock; int VAR_4, VAR_5; qemu_co_mutex_lock(&client->send_lock); qemu_set_fd_handler2(VAR_3, NULL, nbd_read, nbd_restart_write, client); client->send_coroutine = qemu_coroutine_self(); if (!VAR_2) { VAR_4 = nbd_send_reply(VAR_3, VAR_1); if (VAR_4 == -1) { VAR_4 = -errno; } } else { socket_set_cork(VAR_3, 1); VAR_4 = nbd_send_reply(VAR_3, VAR_1); if (VAR_4 != -1) { VAR_5 = qemu_co_send(VAR_3, VAR_0->data, VAR_2); if (VAR_5 != VAR_2) { errno = EIO; VAR_4 = -1; } } if (VAR_4 == -1) { VAR_4 = -errno; } socket_set_cork(VAR_3, 0); } client->send_coroutine = NULL; qemu_set_fd_handler2(VAR_3, NULL, nbd_read, NULL, client); qemu_co_mutex_unlock(&client->send_lock); return VAR_4; }