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.
This commit is contained in:
parent
5cb503dff4
commit
6249451f38
12
atomicio.c
12
atomicio.c
|
@ -57,9 +57,11 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
|
|||
ssize_t res;
|
||||
struct pollfd pfd;
|
||||
|
||||
#ifndef BROKEN_READ_COMPARISON
|
||||
pfd.fd = fd;
|
||||
#ifndef BROKEN_READ_COMPARISON
|
||||
pfd.events = f == read ? POLLIN : POLLOUT;
|
||||
#else
|
||||
pfd.events = POLLIN|POLLOUT;
|
||||
#endif
|
||||
while (n > pos) {
|
||||
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,
|
|||
if (errno == EINTR)
|
||||
continue;
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
#ifndef BROKEN_READ_COMPARISON
|
||||
(void)poll(&pfd, 1, -1);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
|
@ -114,9 +114,11 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
|
|||
/* Make a copy of the iov array because we may modify it below */
|
||||
memcpy(iov, _iov, (size_t)iovcnt * sizeof(*_iov));
|
||||
|
||||
#ifndef BROKEN_READV_COMPARISON
|
||||
pfd.fd = fd;
|
||||
#ifndef BROKEN_READV_COMPARISON
|
||||
pfd.events = f == readv ? POLLIN : POLLOUT;
|
||||
#else
|
||||
pfd.events = POLLIN|POLLOUT;
|
||||
#endif
|
||||
for (; iovcnt > 0 && iov[0].iov_len > 0;) {
|
||||
res = (f) (fd, iov, iovcnt);
|
||||
|
@ -125,9 +127,7 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
|
|||
if (errno == EINTR)
|
||||
continue;
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
#ifndef BROKEN_READV_COMPARISON
|
||||
(void)poll(&pfd, 1, -1);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue