Blame 0101-char-Split-out-tcp-socket-close-code-in-a-separate-f.patch

6986e1
From 973df60b495a87a9cd3b6909d08c148f5fd93691 Mon Sep 17 00:00:00 2001
22d63f
From: Amit Shah <amit.shah@redhat.com>
22d63f
Date: Mon, 21 Mar 2011 21:57:47 +0100
22d63f
Subject: [PATCH] char: Split out tcp socket close code in a separate function
22d63f
22d63f
Signed-off-by: Amit Shah <amit.shah@redhat.com>
22d63f
Signed-off-by: Cole Robinson <crobinso@redhat.com>
22d63f
---
22d63f
 qemu-char.c | 25 ++++++++++++++++---------
22d63f
 1 file changed, 16 insertions(+), 9 deletions(-)
22d63f
22d63f
diff --git a/qemu-char.c b/qemu-char.c
22d63f
index 242b799..77776dc 100644
22d63f
--- a/qemu-char.c
22d63f
+++ b/qemu-char.c
22d63f
@@ -2146,6 +2146,21 @@ typedef struct {
22d63f
 
22d63f
 static void tcp_chr_accept(void *opaque);
22d63f
 
22d63f
+static void tcp_closed(void *opaque)
22d63f
+{
22d63f
+    CharDriverState *chr = opaque;
22d63f
+    TCPCharDriver *s = chr->opaque;
22d63f
+
22d63f
+    s->connected = 0;
22d63f
+    if (s->listen_fd >= 0) {
22d63f
+        qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
22d63f
+    }
22d63f
+    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
22d63f
+    closesocket(s->fd);
22d63f
+    s->fd = -1;
22d63f
+    qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
22d63f
+}
22d63f
+
22d63f
 static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
22d63f
 {
22d63f
     TCPCharDriver *s = chr->opaque;
22d63f
@@ -2304,15 +2319,7 @@ static void tcp_chr_read(void *opaque)
22d63f
         len = s->max_size;
22d63f
     size = tcp_chr_recv(chr, (void *)buf, len);
22d63f
     if (size == 0) {
22d63f
-        /* connection closed */
22d63f
-        s->connected = 0;
22d63f
-        if (s->listen_fd >= 0) {
22d63f
-            qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
22d63f
-        }
22d63f
-        qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
22d63f
-        closesocket(s->fd);
22d63f
-        s->fd = -1;
22d63f
-        qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
22d63f
+        tcp_closed(chr);
22d63f
     } else if (size > 0) {
22d63f
         if (s->do_telnetopt)
22d63f
             tcp_chr_process_IAC_bytes(chr, s, buf, &size);
22d63f
-- 
6986e1
1.8.1
22d63f