From patchwork Mon Jul 10 16:45:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Hao X-Patchwork-Id: 9832579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D050A60363 for ; Mon, 10 Jul 2017 08:36:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2E3322638 for ; Mon, 10 Jul 2017 08:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B46CD251F4; Mon, 10 Jul 2017 08:36:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A65CC283DA for ; Mon, 10 Jul 2017 08:36:26 +0000 (UTC) Received: from localhost ([::1]:39255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUUB7-0004O4-0z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Jul 2017 04:36:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUUAG-0004IU-Mf for qemu-devel@nongnu.org; Mon, 10 Jul 2017 04:35:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUUAD-0005Bj-KV for qemu-devel@nongnu.org; Mon, 10 Jul 2017 04:35:32 -0400 Received: from mx7.zte.com.cn ([202.103.147.169]:42104) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUUAB-00058y-QT for qemu-devel@nongnu.org; Mon, 10 Jul 2017 04:35:29 -0400 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,20170710161845 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 10 Jul 2017 08:18:45 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v6A8Utkq084938; Mon, 10 Jul 2017 16:30:55 +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 2017071016305742-3542165 ; Mon, 10 Jul 2017 16:30:57 +0800 From: Peng Hao To: pbonzini@redhat.com, marcandre.lureau@redhat.com Date: Tue, 11 Jul 2017 00:45:21 +0800 Message-Id: <1499705121-71730-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-10 16:30:57, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-07-10 16:30:54, Serialize complete at 2017-07-10 16:30:54 X-MAIL: mse01.zte.com.cn v6A8Utkq084938 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] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Peng Hao Reviewed-by: Wang Yechao --- chardev/char-socket.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index ccc499c..59509d4 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -131,6 +131,14 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len) } } +static gboolean is_parallel_device(Chardev *chr) +{ + if (chr && chr->label && strstr(chr->label, "charparallel")) { + return TRUE; + } + return FALSE; +} + static int tcp_chr_read_poll(void *opaque) { Chardev *chr = CHARDEV(opaque); @@ -138,6 +146,8 @@ static int tcp_chr_read_poll(void *opaque) if (!s->connected) { return 0; } + if (is_parallel_device(chr)) { + return 1; + } s->max_size = qemu_chr_be_can_write(chr); return s->max_size; } @@ -422,6 +432,15 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) uint8_t buf[CHR_READ_BUF_LEN]; int len, size; + /* for parallel-device handle the socket close event here*/ + if (!s->max_size && is_parallel_device(chr)) { + size = tcp_chr_recv(chr, (void *)buf, CHR_READ_BUF_LEN); + if (size == 0 || size == -1) { + tcp_chr_disconnect(chr); + } + return TRUE; + } + if (!s->connected || s->max_size <= 0) { return TRUE; }