From patchwork Mon Apr 5 12:45:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 49381 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 BA9BEB7C33 for ; Mon, 5 Apr 2010 22:53:35 +1000 (EST) Received: from localhost ([127.0.0.1]:58054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nylo4-0001SN-4G for incoming@patchwork.ozlabs.org; Mon, 05 Apr 2010 08:53:32 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NyliJ-0000HZ-6e for qemu-devel@nongnu.org; Mon, 05 Apr 2010 08:47:35 -0400 Received: from [140.186.70.92] (port=47052 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NyliE-0000DL-Qz for qemu-devel@nongnu.org; Mon, 05 Apr 2010 08:47:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nyli3-0007fW-7Q for qemu-devel@nongnu.org; Mon, 05 Apr 2010 08:47:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33850) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nyli2-0007fL-W6 for qemu-devel@nongnu.org; Mon, 05 Apr 2010 08:47:19 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o35ClH20023921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Apr 2010 08:47:17 -0400 Received: from localhost (vpn-236-74.phx2.redhat.com [10.3.236.74]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o35ClF83007739; Mon, 5 Apr 2010 08:47:16 -0400 From: Amit Shah To: qemu list Date: Mon, 5 Apr 2010 18:15:36 +0530 Message-Id: <1270471538-31275-4-git-send-email-amit.shah@redhat.com> In-Reply-To: <1270471538-31275-3-git-send-email-amit.shah@redhat.com> References: <1270471538-31275-1-git-send-email-amit.shah@redhat.com> <1270471538-31275-2-git-send-email-amit.shah@redhat.com> <1270471538-31275-3-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Gerd Hoffmann , Juan Quintela Subject: [Qemu-devel] [PATCH 3/5] 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 as it may see fit. Modify poll call for polling for a timeout of 10ms instead of waiting indefinitely for POLLOUT to get set. Signed-off-by: Amit Shah --- qemu-char.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 48e1e57..b565872 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -516,6 +516,15 @@ static int unix_write(int fd, const uint8_t *buf, size_t *len) { struct pollfd pollfds[1]; ssize_t tmplen, ret; + int flags; + bool nonblock; + + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + flags = 0; + } + + nonblock = flags & O_NONBLOCK; pollfds[0].fd = fd; pollfds[0].events = POLLOUT; @@ -523,13 +532,16 @@ static int unix_write(int fd, const uint8_t *buf, size_t *len) tmplen = *len; *len = 0; while (tmplen > 0) { - ret = poll(pollfds, 1, -1); + ret = poll(pollfds, 1, 10); if (ret == -1) { if (errno == EINTR) { continue; } return -1; } + if (ret == 0 && nonblock) { + return -EAGAIN; + } ret = write(fd, buf, tmplen); if (ret < 0) { if (errno != EINTR && errno != EAGAIN) {