From patchwork Tue Oct 30 08:32:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 195357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 506352C007A for ; Tue, 30 Oct 2012 20:48:45 +1100 (EST) Received: from localhost ([::1]:47260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7Gs-0005nx-53 for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 04:34:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GG-0004iF-HJ for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT7GA-0000WL-KY for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:24 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:44582) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GA-0000VO-B2 for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:18 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id 487B7181B6; Tue, 30 Oct 2012 17:33:12 +0900 (JST) Received: (nullmailer pid 29413 invoked by uid 1000); Tue, 30 Oct 2012 08:33:11 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Tue, 30 Oct 2012 17:32:42 +0900 Message-Id: <57bbf61835e29be17e90937bf87c44140b64f958.1351582535.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: benoit.hudzia@gmail.com, aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, t.hirofuchi@aist.go.jp, dlaor@redhat.com, satoshi.itoh@aist.go.jp, mdroth@linux.vnet.ibm.com, yoshikawa.takuya@oss.ntt.co.jp, owasserm@redhat.com, avi@redhat.com, pbonzini@redhat.com, chegu_vinod@hp.com Subject: [Qemu-devel] [PATCH v3 06/35] osdep: add qemu_read_full() to read interrupt-safely X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is read counter part of qemu_write_full(). Signed-off-by: Isaku Yamahata --- osdep.c | 24 ++++++++++++++++++++++++ qemu-common.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/osdep.c b/osdep.c index 3b25297..416ffe1 100644 --- a/osdep.c +++ b/osdep.c @@ -261,6 +261,30 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) return total; } +ssize_t qemu_read_full(int fd, void *buf, size_t count) +{ + ssize_t ret = 0; + ssize_t total = 0; + + while (count) { + ret = read(fd, buf, count); + if (ret < 0) { + if (errno == EINTR) + continue; + break; + } + if (ret == 0) { + break; + } + + count -= ret; + buf += ret; + total += ret; + } + + return total; +} + /* * Opens a socket with FD_CLOEXEC set */ diff --git a/qemu-common.h b/qemu-common.h index b54612b..16128c5 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -214,6 +214,8 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) QEMU_WARN_UNUSED_RESULT; ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags) QEMU_WARN_UNUSED_RESULT; +ssize_t qemu_read_full(int fd, void *buf, size_t count) + QEMU_WARN_UNUSED_RESULT; ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags) QEMU_WARN_UNUSED_RESULT;