From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKkh7-0001Sm-Ux for qemu-devel@nongnu.org; Wed, 27 Mar 2013 03:22:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKkh5-0007IV-VD for qemu-devel@nongnu.org; Wed, 27 Mar 2013 03:22:49 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:43869) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKkh5-0007IC-EN for qemu-devel@nongnu.org; Wed, 27 Mar 2013 03:22:47 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Mar 2013 17:11:59 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 100202BB0051 for ; Wed, 27 Mar 2013 18:22:36 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2R79XvT3866952 for ; Wed, 27 Mar 2013 18:09:34 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2R7MYfT019527 for ; Wed, 27 Mar 2013 18:22:34 +1100 Message-ID: <51529E01.8030302@linux.vnet.ibm.com> Date: Wed, 27 Mar 2013 15:21:37 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1364310706-10851-1-git-send-email-aliguori@us.ibm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_chr_fe_write List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Anthony Liguori , qemu-devel@nongnu.org 于 2013-3-26 23:21, Peter Maydell 写道: > On 26 March 2013 15:11, Anthony Liguori wrote: >> +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len) >> +{ >> + int offset = 0; >> + int res; >> + >> + while (offset < len) { >> + do { >> + res = s->chr_write(s, buf + offset, len - offset); >> + if (res == -1 && errno == EAGAIN) { >> + g_usleep(100); >> + } >> + } while (res == -1 && errno == EAGAIN); > > for (;;) { > res = s->chr_write(s, buf + offset, len - offset); > if (!(res == -1 && errno == EAGAIN)) { > break; > } > g_usleep(100); > } > > would avoid the duplication of the retry condition. > > -- PMM > I think adjust like following make code easier to read: while (offset < len) { res = s->chr_write(s, buf + offset, len - offset); if (res == -1 && errno == EAGAIN) { g_usleep(100) continue; } ..... } -- Best Regards Wenchao Xia