qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 3/5] char: unix: For files that are nonblocking, re


From: Amit Shah
Subject: [Qemu-devel] [PATCH 3/5] char: unix: For files that are nonblocking, report -EAGAIN to calling functions
Date: Mon, 5 Apr 2010 18:15:36 +0530

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 <address@hidden>
---
 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) {
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]