>From d9454802fa2105bc399518eebfa1e1415ff07143 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 9 Jul 2008 09:41:31 +0200 Subject: [PATCH 02/12] unix_write: don't block on non-blocking file handles. Signed-off-by: Gerd Hoffmann --- vl.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/vl.c b/vl.c index c8db579..2e2d883 100644 --- a/vl.c +++ b/vl.c @@ -2116,14 +2116,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