From patchwork Tue Mar 26 15:11:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 231253 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 05AF12C0084 for ; Wed, 27 Mar 2013 02:12:31 +1100 (EST) Received: from localhost ([::1]:55457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKVY4-0002FY-5Q for incoming@patchwork.ozlabs.org; Tue, 26 Mar 2013 11:12:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKVXf-00027E-UZ for qemu-devel@nongnu.org; Tue, 26 Mar 2013 11:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKVXa-00007m-ON for qemu-devel@nongnu.org; Tue, 26 Mar 2013 11:12:03 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:52687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKVXa-00007E-7T for qemu-devel@nongnu.org; Tue, 26 Mar 2013 11:11:58 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Mar 2013 01:05:21 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 27 Mar 2013 01:05:19 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 12C102BB0050 for ; Wed, 27 Mar 2013 02:11:50 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2QEwnHg55246930 for ; Wed, 27 Mar 2013 01:58:49 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2QFBnG5032604 for ; Wed, 27 Mar 2013 02:11:49 +1100 Received: from titi.austin.ibm.com (titi.austin.ibm.com [9.41.105.190]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2QFBl2L032580; Wed, 27 Mar 2013 02:11:48 +1100 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Tue, 26 Mar 2013 10:11:45 -0500 Message-Id: <1364310706-10851-1-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.8.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13032615-1618-0000-0000-00000393A8A1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.143 Cc: Peter Maydell , Anthony Liguori Subject: [Qemu-devel] [PATCH 1/2] char: introduce a blocking version of qemu_chr_fe_write 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 Signed-off-by: Anthony Liguori --- include/char/char.h | 15 +++++++++++++++ qemu-char.c | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/char/char.h b/include/char/char.h index 0326b2a..5c3a7a5 100644 --- a/include/char/char.h +++ b/include/char/char.h @@ -170,6 +170,21 @@ int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); /** + * @qemu_chr_fe_write_all: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. Unlike @qemu_chr_fe_write, + * this function will block if the back end cannot consume all of the data + * attempted to be written. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); + +/** * @qemu_chr_fe_ioctl: * * Issue a device specific ioctl to a backend. diff --git a/qemu-char.c b/qemu-char.c index 4e011df..936150f 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -140,6 +140,33 @@ int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len) return s->chr_write(s, buf, len); } +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len) +{ + int offset = 0; + int res; + + while (offset < len) { + do { + res = s->chr_write(s, buf + offset, len - offset); + if (res == -1 && errno == EAGAIN) { + g_usleep(100); + } + } while (res == -1 && errno == EAGAIN); + + if (res == 0) { + break; + } + + if (res < 0) { + return res; + } + + offset += res; + } + + return offset; +} + int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg) { if (!s->chr_ioctl)