static void tcp_chr_read(void *opaque)

{

    CharDriverState *chr = opaque;

    TCPCharDriver *s = chr->opaque;

    uint8_t buf[READ_BUF_LEN];

    int len, size;



    if (!s->connected || s->max_size <= 0)

        return;

    len = sizeof(buf);

    if (len > s->max_size)

        len = s->max_size;

    size = tcp_chr_recv(chr, (void *)buf, len);

    if (size == 0) {

        /* connection closed */

        s->connected = 0;

        if (s->listen_fd >= 0) {

            qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);

        }

        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);

        closesocket(s->fd);

        s->fd = -1;

        qemu_chr_event(chr, CHR_EVENT_CLOSED);

    } else if (size > 0) {

        if (s->do_telnetopt)

            tcp_chr_process_IAC_bytes(chr, s, buf, &size);

        if (size > 0)

            qemu_chr_read(chr, buf, size);

        if (s->msgfd != -1) {

            close(s->msgfd);

            s->msgfd = -1;

        }

    }

}

static void tcp_chr_read(void *opaque)

{

    CharDriverState *chr = opaque;

    TCPCharDriver *s = chr->opaque;

    uint8_t buf[READ_BUF_LEN];

    int len, size;



    if (!s->connected || s->max_size <= 0)

        return;

    len = sizeof(buf);

    if (len > s->max_size)

        len = s->max_size;

    size = tcp_chr_recv(chr, (void *)buf, len);

    if (size == 0) {

        

        s->connected = 0;

        if (s->listen_fd >= 0) {

            qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);

        }

        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);

        closesocket(s->fd);

        s->fd = -1;

        qemu_chr_event(chr, CHR_EVENT_CLOSED);

    } else if (size > 0) {

        if (s->do_telnetopt)

            tcp_chr_process_IAC_bytes(chr, s, buf, &size);

        if (size > 0)

            qemu_chr_read(chr, buf, size);

        if (s->msgfd != -1) {

            close(s->msgfd);

            s->msgfd = -1;

        }

    }

}

        if (s->msgfd != -1) {             close(s->msgfd);             s->msgfd = -1;
static void FUNC_0(void *VAR_0)

{

    CharDriverState *chr = VAR_0;

    TCPCharDriver *s = chr->VAR_0;

    uint8_t buf[READ_BUF_LEN];

    int VAR_1, VAR_2;



    if (!s->connected || s->max_size <= 0)

        return;

    VAR_1 = sizeof(buf);

    if (VAR_1 > s->max_size)

        VAR_1 = s->max_size;

    VAR_2 = tcp_chr_recv(chr, (void *)buf, VAR_1);

    if (VAR_2 == 0) {

        

        s->connected = 0;

        if (s->listen_fd >= 0) {

            qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);

        }

        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);

        closesocket(s->fd);

        s->fd = -1;

        qemu_chr_event(chr, CHR_EVENT_CLOSED);

    } else if (VAR_2 > 0) {

        if (s->do_telnetopt)

            tcp_chr_process_IAC_bytes(chr, s, buf, &VAR_2);

        if (VAR_2 > 0)

            qemu_chr_read(chr, buf, VAR_2);

        if (s->msgfd != -1) {

            close(s->msgfd);

            s->msgfd = -1;

        }

    }

}

static void FUNC_0(void *VAR_0)
{ CharDriverState *chr = VAR_0; TCPCharDriver *s = chr->VAR_0; uint8_t buf[READ_BUF_LEN]; int VAR_1, VAR_2; if (!s->connected || s->max_size <= 0)
return; VAR_1 = sizeof(buf); if (VAR_1 > s->max_size)
VAR_1 = s->max_size; VAR_2 = tcp_chr_recv(chr, (void *)buf, VAR_1); if (VAR_2 == 0) { s->connected = 0; if (s->listen_fd >= 0) { qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr); } qemu_set_fd_handler(s->fd, NULL, NULL, NULL); closesocket(s->fd); s->fd = -1; qemu_chr_event(chr, CHR_EVENT_CLOSED); } else if (VAR_2 > 0) { if (s->do_telnetopt)
tcp_chr_process_IAC_bytes(chr, s, buf, &VAR_2); if (VAR_2 > 0)
qemu_chr_read(chr, buf, VAR_2); if (s->msgfd != -1) { close(s->msgfd); s->msgfd = -1; } } }