From nobody Sat May 4 02:10:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499747809469503.824513825141; Mon, 10 Jul 2017 21:36:49 -0700 (PDT) Received: from localhost ([::1]:44104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUmul-0001kq-M9 for importer@patchew.org; Tue, 11 Jul 2017 00:36:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUmtw-0001TZ-4g for qemu-devel@nongnu.org; Tue, 11 Jul 2017 00:35:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUmts-0006aX-TQ for qemu-devel@nongnu.org; Tue, 11 Jul 2017 00:35:56 -0400 Received: from mx7.zte.com.cn ([202.103.147.169]:37968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUmts-0006Za-Ad for qemu-devel@nongnu.org; Tue, 11 Jul 2017 00:35:52 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 11 Jul 2017 04:23:15 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v6B4Zf2A004614; Tue, 11 Jul 2017 12:35:41 +0800 (GMT-8) (envelope-from peng.hao2@zte.com.cn) Received: from localhost.localdomain ([10.74.120.59]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017071111330560-3615060 ; Tue, 11 Jul 2017 11:33:05 +0800 X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170711122315 From: Peng Hao To: pbonzini@redhat.com, marcandre.lureau@redhat.com Date: Tue, 11 Jul 2017 19:47:25 +0800 Message-Id: <1499773645-120137-1-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-07-11 11:33:05, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-07-11 12:35:37, Serialize complete at 2017-07-11 12:35:37 X-MAIL: mse01.zte.com.cn v6B4Zf2A004614 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 202.103.147.169 Subject: [Qemu-devel] [PATCH V2] chardev: fix parallel device can't be reconnect X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Hao , wang.yechao255@zte.com.cn, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Parallel device don't register be->chr_can_read function, but remote disconnect event is handled in chr_read.So connected parallel device can not detect remote disconnect event. The chardevs with chr_can_read=3DNU= LL has the same problem. Signed-off-by: Peng Hao Reviewed-by: Wang Yechao --- chardev/char-socket.c | 11 +++++++++++ chardev/char.c | 10 ++++++++++ include/chardev/char.h | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index ccc499c..aa44f8f 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -139,6 +139,9 @@ static int tcp_chr_read_poll(void *opaque) return 0; } s->max_size =3D qemu_chr_be_can_write(chr); + if (qemu_chr_null_be_can_read(chr)) { + return 1; + } return s->max_size; } =20 @@ -422,6 +425,14 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCond= ition cond, void *opaque) uint8_t buf[CHR_READ_BUF_LEN]; int len, size; =20 + if (qemu_chr_null_be_can_read(chr)) { + size =3D tcp_chr_recv(chr, (void *)buf, CHR_READ_BUF_LEN); + if (size =3D=3D 0 || size =3D=3D -1) { + tcp_chr_disconnect(chr); + } + return TRUE; + } + if (!s->connected || s->max_size <=3D 0) { return TRUE; } diff --git a/chardev/char.c b/chardev/char.c index 2b679a2..7f7f486 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -148,6 +148,16 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int= len, bool write_all) return offset; } =20 +int qemu_chr_null_be_can_read(Chardev *s) +{ + CharBackend *be =3D s->be; + + if (!be || !be->chr_can_read) { + return 1; + } + return 0; +} + int qemu_chr_be_can_write(Chardev *s) { CharBackend *be =3D s->be; diff --git a/include/chardev/char.h b/include/chardev/char.h index 8a9ade4..8dd28a8 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -114,6 +114,15 @@ void qemu_chr_cleanup(void); Chardev *qemu_chr_new_noreplay(const char *label, const char *filename); =20 /** + * @qemu_chr_null_be_can_read: + * + * Check if Chardev's chr_can_read is registered. + * + * Returns: 1 if Chardev's chr_can_read is null. + */ +int qemu_chr_null_be_can_read(Chardev *s); + +/** * @qemu_chr_be_can_write: * * Determine how much data the front end can currently accept. This funct= ion --=20 1.8.3.1