diff options
author | Amit Shah <amit.shah@redhat.com> | 2011-03-21 21:57:47 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2011-05-03 15:56:32 +0200 |
commit | 185ec3f959ec290aa81a553ff5ec046e6471483c (patch) | |
tree | 1369b4d69b9390188b15054d23e2a3439a2d904f | |
parent | 810291ccd67e5ae69e2041034d5d000b690d2a58 (diff) |
char: Split out tcp socket close code in a separate function
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | qemu-char.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/qemu-char.c b/qemu-char.c index 03858d4ef7..4e0f2ecea1 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1915,6 +1915,21 @@ typedef struct { static void tcp_chr_accept(void *opaque); +static void tcp_closed(void *opaque) +{ + CharDriverState *chr = opaque; + TCPCharDriver *s = chr->opaque; + + 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); +} + static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len) { TCPCharDriver *s = chr->opaque; @@ -2065,15 +2080,7 @@ static void tcp_chr_read(void *opaque) 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); + tcp_closed(chr); } else if (size > 0) { if (s->do_telnetopt) tcp_chr_process_IAC_bytes(chr, s, buf, &size); |