summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-01-24 10:00:20 +1100
committerDarren Tucker <dtucker@dtucker.net>2019-01-24 10:07:03 +1100
commit6249451f381755f792c6b9e2c2f80cdc699c14e2 (patch)
tree5909fd23edac8e9e304848839b355dbe9fc97a87
parent5cb503dff4db251520e8bf7d23b9c97c06eee031 (diff)
For broken read/readv comparisons, poll(RW).
In the cases where we can't compare to read or readv function pointers for some reason we currently ifdef out the poll() used to block while waiting for reads or writes, falling back to busy waiting. This restores the poll() in this case, but has it always check for read or write, removing an inline ifdef in the process.
-rw-r--r--atomicio.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/atomicio.c b/atomicio.c
index f854a06f5..cffa9fa7d 100644
--- a/atomicio.c
+++ b/atomicio.c
@@ -57,9 +57,11 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
57 ssize_t res; 57 ssize_t res;
58 struct pollfd pfd; 58 struct pollfd pfd;
59 59
60#ifndef BROKEN_READ_COMPARISON
61 pfd.fd = fd; 60 pfd.fd = fd;
61#ifndef BROKEN_READ_COMPARISON
62 pfd.events = f == read ? POLLIN : POLLOUT; 62 pfd.events = f == read ? POLLIN : POLLOUT;
63#else
64 pfd.events = POLLIN|POLLOUT;
63#endif 65#endif
64 while (n > pos) { 66 while (n > pos) {
65 res = (f) (fd, s + pos, n - pos); 67 res = (f) (fd, s + pos, n - pos);
@@ -68,9 +70,7 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
68 if (errno == EINTR) 70 if (errno == EINTR)
69 continue; 71 continue;
70 if (errno == EAGAIN || errno == EWOULDBLOCK) { 72 if (errno == EAGAIN || errno == EWOULDBLOCK) {
71#ifndef BROKEN_READ_COMPARISON
72 (void)poll(&pfd, 1, -1); 73 (void)poll(&pfd, 1, -1);
73#endif
74 continue; 74 continue;
75 } 75 }
76 return 0; 76 return 0;
@@ -114,9 +114,11 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
114 /* Make a copy of the iov array because we may modify it below */ 114 /* Make a copy of the iov array because we may modify it below */
115 memcpy(iov, _iov, (size_t)iovcnt * sizeof(*_iov)); 115 memcpy(iov, _iov, (size_t)iovcnt * sizeof(*_iov));
116 116
117#ifndef BROKEN_READV_COMPARISON
118 pfd.fd = fd; 117 pfd.fd = fd;
118#ifndef BROKEN_READV_COMPARISON
119 pfd.events = f == readv ? POLLIN : POLLOUT; 119 pfd.events = f == readv ? POLLIN : POLLOUT;
120#else
121 pfd.events = POLLIN|POLLOUT;
120#endif 122#endif
121 for (; iovcnt > 0 && iov[0].iov_len > 0;) { 123 for (; iovcnt > 0 && iov[0].iov_len > 0;) {
122 res = (f) (fd, iov, iovcnt); 124 res = (f) (fd, iov, iovcnt);
@@ -125,9 +127,7 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
125 if (errno == EINTR) 127 if (errno == EINTR)
126 continue; 128 continue;
127 if (errno == EAGAIN || errno == EWOULDBLOCK) { 129 if (errno == EAGAIN || errno == EWOULDBLOCK) {
128#ifndef BROKEN_READV_COMPARISON
129 (void)poll(&pfd, 1, -1); 130 (void)poll(&pfd, 1, -1);
130#endif
131 continue; 131 continue;
132 } 132 }
133 return 0; 133 return 0;