aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2011-03-21 21:57:47 +0100
committerDoug Goldstein <cardoe@cardoe.com>2011-07-21 15:16:29 -0500
commitc39468c92c0c80ebeabf83241a4e45c1c2177e37 (patch)
tree37fddf4fd5158f57e120c077a7ddb76bc4236643
parenthw/qxl-render: drop cursor locks, replace with pipe (diff)
downloadqemu-kvm-c39468c92c0c80ebeabf83241a4e45c1c2177e37.tar.gz
qemu-kvm-c39468c92c0c80ebeabf83241a4e45c1c2177e37.tar.bz2
qemu-kvm-c39468c92c0c80ebeabf83241a4e45c1c2177e37.zip
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.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/qemu-char.c b/qemu-char.c
index bd4e944e1..4b57af949 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1911,6 +1911,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;
@@ -2061,15 +2076,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);