From patchwork Tue May 4 10:52:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51588 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 11884B6F11 for ; Tue, 4 May 2010 21:16:48 +1000 (EST) Received: from localhost ([127.0.0.1]:37105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Fwr-0006ks-4R for incoming@patchwork.ozlabs.org; Tue, 04 May 2010 07:05:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9FmQ-0003Z9-LR for qemu-devel@nongnu.org; Tue, 04 May 2010 06:55:10 -0400 Received: from [140.186.70.92] (port=33602 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9FmB-0003VP-Ci for qemu-devel@nongnu.org; Tue, 04 May 2010 06:55:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9Fm1-0006A1-HL for qemu-devel@nongnu.org; Tue, 04 May 2010 06:54:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42520) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9Fm0-00069k-TM for qemu-devel@nongnu.org; Tue, 04 May 2010 06:54:45 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44Asb8h031267 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 May 2010 06:54:38 -0400 Received: from localhost (vpn-224-130.phx2.redhat.com [10.3.224.130]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44AsaH2007599; Tue, 4 May 2010 06:54:37 -0400 From: Amit Shah To: qemu list Date: Tue, 4 May 2010 16:22:44 +0530 Message-Id: <1272970367-24647-4-git-send-email-amit.shah@redhat.com> In-Reply-To: <1272970367-24647-3-git-send-email-amit.shah@redhat.com> References: <1272970367-24647-1-git-send-email-amit.shah@redhat.com> <1272970367-24647-2-git-send-email-amit.shah@redhat.com> <1272970367-24647-3-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 v5 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 | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 65cb3f5..97f2ef6 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,12 @@ 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 (len1 - len) { + return len1 - len; + } + if (errno != EINTR && errno != EAGAIN) { return -1; + } } else if (ret == 0) { break; } else {