peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

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

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