d4cdad
From 34736b9b6690054152ae2b9b37f75f7ed720590a Mon Sep 17 00:00:00 2001
d4cdad
From: Amit Shah <amit.shah@redhat.com>
d4cdad
Date: Mon, 21 Mar 2011 21:57:47 +0100
d4cdad
Subject: [PATCH 106/118] char: Split out tcp socket close code in a separate
d4cdad
 function
d4cdad
d4cdad
Signed-off-by: Amit Shah <amit.shah@redhat.com>
d4cdad
---
d4cdad
 qemu-char.c |   25 ++++++++++++++++---------
d4cdad
 1 files changed, 16 insertions(+), 9 deletions(-)
d4cdad
d4cdad
diff --git a/qemu-char.c b/qemu-char.c
d4cdad
index 27abcb9..a5ca611 100644
d4cdad
--- a/qemu-char.c
d4cdad
+++ b/qemu-char.c
d4cdad
@@ -2163,6 +2163,21 @@ typedef struct {
d4cdad
d4cdad
 static void tcp_chr_accept(void *opaque);
d4cdad
d4cdad
+static void tcp_closed(void *opaque)
d4cdad
+{
d4cdad
+    CharDriverState *chr = opaque;
d4cdad
+    TCPCharDriver *s = chr->opaque;
d4cdad
+
d4cdad
+    s->connected = 0;
d4cdad
+    if (s->listen_fd >= 0) {
d4cdad
+        qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
d4cdad
+    }
d4cdad
+    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
d4cdad
+    closesocket(s->fd);
d4cdad
+    s->fd = -1;
d4cdad
+    qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
d4cdad
+}
d4cdad
+
d4cdad
 static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
d4cdad
 {
d4cdad
     TCPCharDriver *s = chr->opaque;
d4cdad
@@ -2313,15 +2328,7 @@ static void tcp_chr_read(void *opaque)
d4cdad
         len = s->max_size;
d4cdad
     size = tcp_chr_recv(chr, (void *)buf, len);
d4cdad
     if (size == 0) {
d4cdad
-        /* connection closed */
d4cdad
-        s->connected = 0;
d4cdad
-        if (s->listen_fd >= 0) {
d4cdad
-            qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
d4cdad
-        }
d4cdad
-        qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
d4cdad
-        closesocket(s->fd);
d4cdad
-        s->fd = -1;
d4cdad
-        qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
d4cdad
+        tcp_closed(chr);
d4cdad
     } else if (size > 0) {
d4cdad
         if (s->do_telnetopt)
d4cdad
             tcp_chr_process_IAC_bytes(chr, s, buf, &size);
d4cdad
-- 
d4cdad
1.7.7.5
d4cdad