From patchwork Tue May 4 10:52:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v5, 3/6] char: Let writers know how much data was written in case of errors X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 51588 Message-Id: <1272970367-24647-4-git-send-email-amit.shah@redhat.com> To: qemu list Cc: Amit Shah , Paul Brook , Gerd Hoffmann , Juan Quintela Date: Tue, 4 May 2010 16:22:44 +0530 From: Amit Shah List-Id: qemu-devel.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 {