diff options
author | Jeremy Allison <jra@samba.org> | 2010-12-14 15:30:06 -0800 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2010-12-15 01:38:16 +0100 |
commit | e071fd711dee0a5b03df53979b355f2e5a2e58b0 (patch) | |
tree | af8ab457e5ac5956b0a9a884438f8cfb2d9d209a /source3/lib/system.c | |
parent | 14c70346fc88d05dfabc14b0a932632470fee6fe (diff) | |
download | samba-e071fd711dee0a5b03df53979b355f2e5a2e58b0.tar.gz samba-e071fd711dee0a5b03df53979b355f2e5a2e58b0.tar.xz samba-e071fd711dee0a5b03df53979b355f2e5a2e58b0.zip |
Fix read/write calls over sockets to cope with EAGAIN/EWOULDBLOCK for non-blocking sockets.
Diffstat (limited to 'source3/lib/system.c')
-rw-r--r-- | source3/lib/system.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c index ee8efe87a4c..1c00ad87e4d 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -123,7 +123,11 @@ ssize_t sys_read(int fd, void *buf, size_t count) do { ret = read(fd, buf, count); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } @@ -137,7 +141,11 @@ ssize_t sys_write(int fd, const void *buf, size_t count) do { ret = write(fd, buf, count); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } @@ -162,7 +170,11 @@ ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt) do { ret = writev(fd, iov, iovcnt); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } @@ -207,7 +219,7 @@ ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off) #endif /******************************************************************* -A send wrapper that will deal with EINTR. +A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. ********************************************************************/ ssize_t sys_send(int s, const void *msg, size_t len, int flags) @@ -216,12 +228,16 @@ ssize_t sys_send(int s, const void *msg, size_t len, int flags) do { ret = send(s, msg, len, flags); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } /******************************************************************* -A sendto wrapper that will deal with EINTR. +A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. ********************************************************************/ ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) @@ -230,12 +246,16 @@ ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct do { ret = sendto(s, msg, len, flags, to, tolen); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } /******************************************************************* -A recv wrapper that will deal with EINTR. +A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. ********************************************************************/ ssize_t sys_recv(int fd, void *buf, size_t count, int flags) @@ -244,7 +264,11 @@ ssize_t sys_recv(int fd, void *buf, size_t count, int flags) do { ret = recv(fd, buf, count, flags); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } @@ -258,7 +282,11 @@ ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *f do { ret = recvfrom(s, buf, len, flags, from, fromlen); - } while (ret == -1 && errno == EINTR); +#if defined(EWOULDBLOCK) + } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); +#else + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); +#endif return ret; } |