qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file ha


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file handles.
Date: Wed, 9 Jul 2008 14:19:17 +0200

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 vl.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 0e98eef..587b91c 100644
--- a/vl.c
+++ b/vl.c
@@ -2119,14 +2119,24 @@ void socket_set_nonblock(int fd)
 
 static int unix_write(int fd, const uint8_t *buf, int len1)
 {
+    int nonblock = fcntl(fd, F_GETFL) & O_NONBLOCK;
     int ret, len;
 
     len = len1;
     while (len > 0) {
         ret = write(fd, buf, len);
         if (ret < 0) {
-            if (errno != EINTR && errno != EAGAIN)
+            if (errno == EINTR) {
+               continue;
+           } else if (errno == EAGAIN) {
+               if (!nonblock)
+                   continue;
+               if (len1 != len)
+                   break; /* partial write, return written bytes */
+               return -1;
+           } else {
                 return -1;
+           }
         } else if (ret == 0) {
             break;
         } else {
-- 
1.5.4.1





reply via email to

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