From patchwork Tue May 4 21:39:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 29625B7D42 for ; Thu, 6 May 2010 00:33:50 +1000 (EST) Received: from localhost ([127.0.0.1]:51251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9ffW-0001lc-Od for incoming@patchwork.ozlabs.org; Wed, 05 May 2010 10:33:46 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9Ps3-0006Ot-MY for qemu-devel@nongnu.org; Tue, 04 May 2010 17:41:39 -0400 Received: from [140.186.70.92] (port=45079 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Ps2-0006NA-At for qemu-devel@nongnu.org; Tue, 04 May 2010 17:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9Ps0-00077G-MF for qemu-devel@nongnu.org; Tue, 04 May 2010 17:41:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57299) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9Ps0-000777-C4 for qemu-devel@nongnu.org; Tue, 04 May 2010 17:41:36 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44LfMlq009111 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 May 2010 17:41:22 -0400 Received: from localhost (vpn-240-153.phx2.redhat.com [10.3.240.153]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44LfKNl006569; Tue, 4 May 2010 17:41:21 -0400 From: Amit Shah To: qemu list Date: Wed, 5 May 2010 03:09:27 +0530 Message-Id: <1273009170-17530-4-git-send-email-amit.shah@redhat.com> In-Reply-To: <1273009170-17530-3-git-send-email-amit.shah@redhat.com> 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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Paul Brook , Gerd Hoffmann , Juan Quintela Subject: [Qemu-devel] [PATCH v7 3/6] char: Let writers know how much data was written in case of errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 {