summaryrefslogtreecommitdiff
path: root/atomicio.c
diff options
context:
space:
mode:
Diffstat (limited to 'atomicio.c')
-rw-r--r--atomicio.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/atomicio.c b/atomicio.c
index f32ff85ba..a6b2d127a 100644
--- a/atomicio.c
+++ b/atomicio.c
@@ -34,6 +34,10 @@
34#include <errno.h> 34#include <errno.h>
35#ifdef HAVE_POLL_H 35#ifdef HAVE_POLL_H
36#include <poll.h> 36#include <poll.h>
37#else
38# ifdef HAVE_SYS_POLL_H
39# include <sys/poll.h>
40# endif
37#endif 41#endif
38#include <string.h> 42#include <string.h>
39#include <unistd.h> 43#include <unistd.h>
@@ -57,13 +61,9 @@ atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
57 res = (f) (fd, s + pos, n - pos); 61 res = (f) (fd, s + pos, n - pos);
58 switch (res) { 62 switch (res) {
59 case -1: 63 case -1:
60#ifdef EWOULDBLOCK
61 if (errno == EINTR || errno == EWOULDBLOCK)
62#else
63 if (errno == EINTR) 64 if (errno == EINTR)
64#endif
65 continue; 65 continue;
66 if (errno == EAGAIN) { 66 if (errno == EAGAIN || errno == EWOULDBLOCK) {
67 (void)poll(&pfd, 1, -1); 67 (void)poll(&pfd, 1, -1);
68 continue; 68 continue;
69 } 69 }
@@ -97,20 +97,20 @@ atomiciov(ssize_t (*f) (int, const struct iovec *, int), int fd,
97 /* Make a copy of the iov array because we may modify it below */ 97 /* Make a copy of the iov array because we may modify it below */
98 memcpy(iov, _iov, iovcnt * sizeof(*_iov)); 98 memcpy(iov, _iov, iovcnt * sizeof(*_iov));
99 99
100#ifndef BROKEN_READV_COMPARISON
100 pfd.fd = fd; 101 pfd.fd = fd;
101 pfd.events = f == readv ? POLLIN : POLLOUT; 102 pfd.events = f == readv ? POLLIN : POLLOUT;
103#endif
102 for (; iovcnt > 0 && iov[0].iov_len > 0;) { 104 for (; iovcnt > 0 && iov[0].iov_len > 0;) {
103 res = (f) (fd, iov, iovcnt); 105 res = (f) (fd, iov, iovcnt);
104 switch (res) { 106 switch (res) {
105 case -1: 107 case -1:
106#ifdef EWOULDBLOCK
107 if (errno == EINTR || errno == EWOULDBLOCK)
108#else
109 if (errno == EINTR) 108 if (errno == EINTR)
110#endif
111 continue; 109 continue;
112 if (errno == EAGAIN) { 110 if (errno == EAGAIN || errno == EWOULDBLOCK) {
111#ifndef BROKEN_READV_COMPARISON
113 (void)poll(&pfd, 1, -1); 112 (void)poll(&pfd, 1, -1);
113#endif
114 continue; 114 continue;
115 } 115 }
116 return 0; 116 return 0;