From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9eRj-0006Aj-FF for qemu-devel@nongnu.org; Wed, 05 May 2010 09:15:27 -0400 Received: from [140.186.70.92] (port=39203 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9eRg-00067Z-PN for qemu-devel@nongnu.org; Wed, 05 May 2010 09:15:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9eRe-0000wT-LK for qemu-devel@nongnu.org; Wed, 05 May 2010 09:15:24 -0400 Received: from mail-yw0-f198.google.com ([209.85.211.198]:48911) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9eRe-0000wG-FU for qemu-devel@nongnu.org; Wed, 05 May 2010 09:15:22 -0400 Received: by ywh36 with SMTP id 36so2186351ywh.4 for ; Wed, 05 May 2010 06:15:21 -0700 (PDT) Message-ID: <4BE16F67.6070901@codemonkey.ws> Date: Wed, 05 May 2010 08:15:19 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1273009170-17530-1-git-send-email-amit.shah@redhat.com> <1273009170-17530-2-git-send-email-amit.shah@redhat.com> <1273009170-17530-3-git-send-email-amit.shah@redhat.com> <1273009170-17530-4-git-send-email-amit.shah@redhat.com> In-Reply-To: <1273009170-17530-4-git-send-email-amit.shah@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH v7 3/6] char: Let writers know how much data was written in case of errors List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah Cc: Paul Brook , Juan Quintela , qemu list , Gerd Hoffmann On 05/04/2010 04:39 PM, Amit Shah wrote: > On writing errors, we just returned -1 even if some bytes were already > written out. Ensure we return the number of bytes written before we > return the error (on a subsequent call to qemu_chr_write()). > > Signed-off-by: Amit Shah > --- > qemu-char.c | 12 +++++++++++- > 1 files changed, 11 insertions(+), 1 deletions(-) > > diff --git a/qemu-char.c b/qemu-char.c > index 76ad12c..decf687 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -507,6 +507,9 @@ int send_all(int fd, const void *buf, int len1) > while (len> 0) { > ret = send(fd, buf, len, 0); > if (ret< 0) { > + if (len1 - len) { > + return len1 - len; > + } > errno = WSAGetLastError(); > if (errno != WSAEWOULDBLOCK) { > return -1; > @@ -531,8 +534,15 @@ static int unix_write(int fd, const uint8_t *buf, int len1) > while (len> 0) { > ret = write(fd, buf, len); > if (ret< 0) { > - if (errno != EINTR&& errno != EAGAIN) > + if (errno == EINTR) { > + continue; > + } > + if (len1 - len) { > + return len1 - len; > + } > + if (errno != EAGAIN) { > return -1; > + } > } else if (ret == 0) { > break; > } else { > This will break lots of things. The contract for send_all and unix_write is that the transmit all data. Regards, Anthony Liguori