From patchwork Wed Apr 7 21:02:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 49647 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 7DCAFB7D17 for ; Thu, 8 Apr 2010 07:16:15 +1000 (EST) Received: from localhost ([127.0.0.1]:45372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nzcbc-0007oz-JZ for incoming@patchwork.ozlabs.org; Wed, 07 Apr 2010 17:16:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NzcQQ-0004E5-V8 for qemu-devel@nongnu.org; Wed, 07 Apr 2010 17:04:39 -0400 Received: from [140.186.70.92] (port=35158 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzcQP-0004DN-3V for qemu-devel@nongnu.org; Wed, 07 Apr 2010 17:04:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NzcQM-0003ED-DI for qemu-devel@nongnu.org; Wed, 07 Apr 2010 17:04:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54044) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NzcQM-0003E3-5o for qemu-devel@nongnu.org; Wed, 07 Apr 2010 17:04:34 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o37L4PKx023146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Apr 2010 17:04:25 -0400 Received: from localhost (vpn-252-12.phx2.redhat.com [10.3.252.12]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o37L4NZo027706; Wed, 7 Apr 2010 17:04:24 -0400 From: Amit Shah To: qemu list Date: Thu, 8 Apr 2010 02:32:34 +0530 Message-Id: <1270674156-9345-7-git-send-email-amit.shah@redhat.com> In-Reply-To: <1270674156-9345-6-git-send-email-amit.shah@redhat.com> References: <1270674156-9345-1-git-send-email-amit.shah@redhat.com> <1270674156-9345-2-git-send-email-amit.shah@redhat.com> <1270674156-9345-3-git-send-email-amit.shah@redhat.com> <1270674156-9345-4-git-send-email-amit.shah@redhat.com> <1270674156-9345-5-git-send-email-amit.shah@redhat.com> <1270674156-9345-6-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Paul Brook , "Michael S. Tsirkin" , Gerd Hoffmann , Juan Quintela Subject: [Qemu-devel] [PATCH 6/8] char: unix: For files that are nonblocking, report -EAGAIN to calling functions 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 If the chardev we're writing to is nonblocking, just report -EAGAIN to the caller so that the caller can take any further action if it so wishes. Signed-off-by: Amit Shah --- qemu-char.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 208466f..57e9af3 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -497,11 +497,23 @@ int send_all(int fd, const void *buf, int len1) static int unix_write(int fd, const uint8_t *buf, int len1) { int ret, len; + int flags; + bool nonblock; + + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + flags = 0; + } + + nonblock = flags & O_NONBLOCK; len = len1; while (len > 0) { ret = write(fd, buf, len); if (ret < 0) { + if (errno == EAGAIN && nonblock) { + return -EAGAIN; + } if (errno != EINTR && errno != EAGAIN) { if (len1 - len) { return len1 - len;