qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zifei Tong <zifeitong@gmail.com>
To: qemu-devel@nongnu.org
Cc: Kirill Batuzov <batuzovk@ispras.ru>,
	Anthony Liguori <aliguori@amazon.com>,
	Markus Armbruster <armbru@redhat.com>,
	Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>,
	Zifei Tong <zifeitong@gmail.com>
Subject: [Qemu-devel] [PATCH v3] qemu-char: Do not disconnect when there's data for reading
Date: Fri, 19 Sep 2014 15:12:53 +0800	[thread overview]
Message-ID: <1411110773-489-1-git-send-email-zifeitong@gmail.com> (raw)

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 <batuzovk@ispras.ru>
Cc: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Anthony Liguori <aliguori@amazon.com>
Signed-off-by: Zifei Tong <zifeitong@gmail.com>
---
Changes in v3: handle EWOULDBLOCK, remove inaccurate comment

 qemu-char.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 2a3cb9f..d1893a0 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,8 +2699,8 @@ 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) {
-        /* connection closed */
+    if (size == 0 ||
+        (size < 0 && !(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR))) {
         tcp_chr_disconnect(chr);
     } else if (size > 0) {
         if (s->do_telnetopt)
-- 
2.1.0

             reply	other threads:[~2014-09-19  7:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19  7:12 Zifei Tong [this message]
2014-09-19 14:03 ` [Qemu-devel] [PATCH v3] qemu-char: Do not disconnect when there's data for reading Kirill Batuzov
2014-10-16 11:54   ` Zifei Tong
2014-10-20  8:24 ` Markus Armbruster
2015-09-10  8:04   ` Michael S. Tsirkin
2015-09-10  8:15     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411110773-489-1-git-send-email-zifeitong@gmail.com \
    --to=zifeitong@gmail.com \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=batuzovk@ispras.ru \
    --cc=n.nikolaev@virtualopensystems.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).