Received: from eggs.gnu.org ([2001:4830:134:3::10]:44887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUZmk-0004iJ-Si for qemu-devel@nongnu.org; Thu, 18 Sep 2014 07:22:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUZmf-0007MR-9m for qemu-devel@nongnu.org; Thu, 18 Sep 2014 07:22:02 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:63413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUZmf-0007Iv-1w for qemu-devel@nongnu.org; Thu, 18 Sep 2014 07:21:57 -0400 Received: by mail-pa0-f44.google.com with SMTP id bj1so1301124pad.31 for ; Thu, 18 Sep 2014 04:21:50 -0700 (PDT) From: Zifei Tong Date: Thu, 18 Sep 2014 19:21:33 +0800 Message-Id: <1411039293-18988-1-git-send-email-zifeitong@gmail.com> Subject: [Qemu-devel] [PATCH v2] qemu-char: Do not disconnect when there's data for reading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kirill Batuzov , Anthony Liguori , Markus Armbruster , Nikolay Nikolaev , Zifei Tong After commit 812c1057f6175ac9a9829fa2920a2b5783814193 (Handle G_IO_HUP in tcp_chr_read for tcp chardev), connections are disconnected when in G_IO_HUP condition. However, it's possible that there is still data for reading in the channel. In that case, the remaining data is not handled. I saw a related bug when running socat in write-only mode, after $ echo "quit" | socat -u - UNIX-CONNECT:qemu-monitor the monitor won't not run the 'quit' command. Instead of GIOCondition, this patch uses the return value of tcp_chr_recv() to check the state of connection as suggested by Kirill. Cc: Kirill Batuzov Cc: Nikolay Nikolaev Cc: Markus Armbruster Cc: Anthony Liguori Signed-off-by: Zifei Tong --- qemu-char.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 2a3cb9f..6cc69fa 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2692,12 +2692,6 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) uint8_t buf[READ_BUF_LEN]; int len, size; - if (cond & G_IO_HUP) { - /* connection closed */ - tcp_chr_disconnect(chr); - return TRUE; - } - if (!s->connected || s->max_size <= 0) { return TRUE; } @@ -2705,7 +2699,7 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) if (len > s->max_size) len = s->max_size; size = tcp_chr_recv(chr, (void *)buf, len); - if (size == 0) { + if (size == 0 || (size < 0 && !(errno == EAGAIN || errno == EINTR))) { /* connection closed */ tcp_chr_disconnect(chr); } else if (size > 0) { -- 2.1.0