From patchwork Tue Mar 19 14:04:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 229078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32DE32C00B0 for ; Wed, 20 Mar 2013 01:04:52 +1100 (EST) Received: from localhost ([::1]:38269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHx9m-0003mF-5R for incoming@patchwork.ozlabs.org; Tue, 19 Mar 2013 10:04:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHx9X-0003mA-Vb for qemu-devel@nongnu.org; Tue, 19 Mar 2013 10:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHx9P-0005ZV-0t for qemu-devel@nongnu.org; Tue, 19 Mar 2013 10:04:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHx9O-0005Y3-Q9 for qemu-devel@nongnu.org; Tue, 19 Mar 2013 10:04:26 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2JE4PXc009910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Mar 2013 10:04:25 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2JE4OZW023332; Tue, 19 Mar 2013 10:04:24 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 95DF942628; Tue, 19 Mar 2013 15:04:23 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 19 Mar 2013 15:04:23 +0100 Message-Id: <1363701863-13004-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, Markus Armbruster , Gerd Hoffmann , anthony@codemonkey.ws, Luiz Capitulino Subject: [Qemu-devel] [PATCH] fix monitor X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org chardev flow control broke monitor, fix it by adding watch support. Signed-off-by: Gerd Hoffmann --- v2: fix tyops --- monitor.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index 112e920..74807f9 100644 --- a/monitor.c +++ b/monitor.c @@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, } } +static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond, + void *opaque) +{ + monitor_flush(opaque); + return FALSE; +} + void monitor_flush(Monitor *mon) { + int rc; + if (mon && mon->outbuf_index != 0 && !mon->mux_out) { - qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index); - mon->outbuf_index = 0; + rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index); + if (rc == mon->outbuf_index) { + /* all flushed */ + mon->outbuf_index = 0; + return; + } + if (rc > 0) { + /* partial write */ + memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc); + mon->outbuf_index -= rc; + } + qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon); } }