summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c75
1 files changed, 23 insertions, 52 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index a437d9b127..945f1525a2 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2037,45 +2037,31 @@ int close_pipe(int p[]) {
}
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
- uint8_t *p;
+ uint8_t *p = buf;
ssize_t n = 0;
assert(fd >= 0);
assert(buf);
- p = buf;
-
while (nbytes > 0) {
ssize_t k;
- if ((k = read(fd, p, nbytes)) <= 0) {
-
- if (k < 0 && errno == EINTR)
- continue;
-
- if (k < 0 && errno == EAGAIN && do_poll) {
- struct pollfd pollfd = {
- .fd = fd,
- .events = POLLIN,
- };
-
- if (poll(&pollfd, 1, -1) < 0) {
- if (errno == EINTR)
- continue;
+ k = read(fd, p, nbytes);
+ if (k < 0 && errno == EINTR)
+ continue;
- return n > 0 ? n : -errno;
- }
+ if (k < 0 && errno == EAGAIN && do_poll) {
- /* We knowingly ignore the revents value here,
- * and expect that any error/EOF is reported
- * via read()/write()
- */
+ /* We knowingly ignore any return value here,
+ * and expect that any error/EOF is reported
+ * via read() */
- continue;
- }
+ fd_wait_for_event(fd, POLLIN, (usec_t) -1);
+ continue;
+ }
+ if (k <= 0)
return n > 0 ? n : (k < 0 ? -errno : 0);
- }
p += k;
nbytes -= k;
@@ -2086,46 +2072,31 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
}
ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
- const uint8_t *p;
+ const uint8_t *p = buf;
ssize_t n = 0;
assert(fd >= 0);
assert(buf);
- p = buf;
-
while (nbytes > 0) {
ssize_t k;
k = write(fd, p, nbytes);
- if (k <= 0) {
-
- if (k < 0 && errno == EINTR)
- continue;
-
- if (k < 0 && errno == EAGAIN && do_poll) {
- struct pollfd pollfd = {
- .fd = fd,
- .events = POLLOUT,
- };
-
- if (poll(&pollfd, 1, -1) < 0) {
- if (errno == EINTR)
- continue;
+ if (k < 0 && errno == EINTR)
+ continue;
- return n > 0 ? n : -errno;
- }
+ if (k < 0 && errno == EAGAIN && do_poll) {
- /* We knowingly ignore the revents value here,
- * and expect that any error/EOF is reported
- * via read()/write()
- */
+ /* We knowingly ignore any return value here,
+ * and expect that any error/EOF is reported
+ * via write() */
- continue;
- }
+ fd_wait_for_event(fd, POLLOUT, (usec_t) -1);
+ continue;
+ }
+ if (k <= 0)
return n > 0 ? n : (k < 0 ? -errno : 0);
- }
p += k;
nbytes -= k;