static void vnc_client_write(void *opaque)

{

    long ret;

    VncState *vs = opaque;



#ifdef CONFIG_VNC_TLS

    if (vs->tls_session) {

	ret = gnutls_write(vs->tls_session, vs->output.buffer, vs->output.offset);

	if (ret < 0) {

	    if (ret == GNUTLS_E_AGAIN)

		errno = EAGAIN;

	    else

		errno = EIO;

	    ret = -1;

	}

    } else

#endif /* CONFIG_VNC_TLS */

	ret = send(vs->csock, vs->output.buffer, vs->output.offset, 0);

    ret = vnc_client_io_error(vs, ret, socket_error());

    if (!ret)

	return;



    memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));

    vs->output.offset -= ret;



    if (vs->output.offset == 0) {

	qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);

    }

}

static void vnc_client_write(void *opaque)

{

    long ret;

    VncState *vs = opaque;



#ifdef CONFIG_VNC_TLS

    if (vs->tls_session) {

	ret = gnutls_write(vs->tls_session, vs->output.buffer, vs->output.offset);

	if (ret < 0) {

	    if (ret == GNUTLS_E_AGAIN)

		errno = EAGAIN;

	    else

		errno = EIO;

	    ret = -1;

	}

    } else

#endif 

	ret = send(vs->csock, vs->output.buffer, vs->output.offset, 0);

    ret = vnc_client_io_error(vs, ret, socket_error());

    if (!ret)

	return;



    memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));

    vs->output.offset -= ret;



    if (vs->output.offset == 0) {

	qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);

    }

}

static void FUNC_0(void *VAR_0)

{

    long VAR_1;

    VncState *vs = VAR_0;



#ifdef CONFIG_VNC_TLS

    if (vs->tls_session) {

	VAR_1 = gnutls_write(vs->tls_session, vs->output.buffer, vs->output.offset);

	if (VAR_1 < 0) {

	    if (VAR_1 == GNUTLS_E_AGAIN)

		errno = EAGAIN;

	    else

		errno = EIO;

	    VAR_1 = -1;

	}

    } else

#endif 

	VAR_1 = send(vs->csock, vs->output.buffer, vs->output.offset, 0);

    VAR_1 = vnc_client_io_error(vs, VAR_1, socket_error());

    if (!VAR_1)

	return;



    memmove(vs->output.buffer, vs->output.buffer + VAR_1, (vs->output.offset - VAR_1));

    vs->output.offset -= VAR_1;



    if (vs->output.offset == 0) {

	qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);

    }

}

static void FUNC_0(void *VAR_0)
{ long VAR_1; VncState *vs = VAR_0; #ifdef CONFIG_VNC_TLS
if (vs->tls_session) { VAR_1 = gnutls_write(vs->tls_session, vs->output.buffer, vs->output.offset); if (VAR_1 < 0) { if (VAR_1 == GNUTLS_E_AGAIN)
errno = EAGAIN; else
errno = EIO; VAR_1 = -1; } } else #endif
VAR_1 = send(vs->csock, vs->output.buffer, vs->output.offset, 0); VAR_1 = vnc_client_io_error(vs, VAR_1, socket_error()); if (!VAR_1)
return; memmove(vs->output.buffer, vs->output.buffer + VAR_1, (vs->output.offset - VAR_1)); vs->output.offset -= VAR_1; if (vs->output.offset == 0) { qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); } }