Received: from eggs.gnu.org ([2001:4830:134:3::10]:36318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUymu-0004Iy-3u for qemu-devel@nongnu.org; Fri, 19 Sep 2014 10:03:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUyml-000598-NS for qemu-devel@nongnu.org; Fri, 19 Sep 2014 10:03:52 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUyml-00057y-Fq for qemu-devel@nongnu.org; Fri, 19 Sep 2014 10:03:43 -0400 Message-ID: <541C37B4.5070003@ispras.ru> Date: Fri, 19 Sep 2014 18:03:32 +0400 From: Kirill Batuzov MIME-Version: 1.0 References: <1411110773-489-1-git-send-email-zifeitong@gmail.com> In-Reply-To: <1411110773-489-1-git-send-email-zifeitong@gmail.com> Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3] qemu-char: Do not disconnect when there's data for reading List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zifei Tong , qemu-devel@nongnu.org Cc: Markus Armbruster , Nikolay Nikolaev , Anthony Liguori On 19.09.2014 11:12, Zifei Tong wrote: > 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 > --- > 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) > Looks good to me. Reviewed-by: Kirill Batuzov -- Kirill