All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file handles.
@ 2008-07-09 12:19 Gerd Hoffmann
  2008-07-09 12:19 ` [Qemu-devel] [PATCH 2/2] open ptys in non-blocking mode Gerd Hoffmann
  2008-07-18 13:46 ` [Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file handles Ian Jackson
  0 siblings, 2 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2008-07-09 12:19 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-07-18 13:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-09 12:19 [Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file handles Gerd Hoffmann
2008-07-09 12:19 ` [Qemu-devel] [PATCH 2/2] open ptys in non-blocking mode Gerd Hoffmann
2008-07-18  8:41   ` Kevin Wolf
2008-07-18  9:10     ` Gerd Hoffmann
2008-07-18  9:10       ` Gerd Hoffmann
2008-07-18  9:14       ` Kevin Wolf
2008-07-18 13:56     ` Ian Jackson
2008-07-18 13:47   ` Ian Jackson
2008-07-18 13:46 ` [Qemu-devel] [PATCH 1/2] unix_write: don't block on non-blocking file handles Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.