From 12586b6a8a082e712c16c893e9cd727353816f06 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Dec 2014 03:12:58 +0100 Subject: util: minor simplification for loop_write() and loop_read() Signed-off-by: Anthony G. Basile --- src/shared/util.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index b53042182d..633cf437e3 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -809,21 +809,25 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) { ssize_t k; k = read(fd, p, nbytes); - if (k < 0 && errno == EINTR) - continue; + if (k < 0) { + if (errno == EINTR) + continue; + + if (errno == EAGAIN && do_poll) { - if (k < 0 && errno == EAGAIN && do_poll) { + /* We knowingly ignore any return value here, + * and expect that any error/EOF is reported + * via read() */ - /* We knowingly ignore any return value here, - * and expect that any error/EOF is reported - * via read() */ + fd_wait_for_event(fd, POLLIN, USEC_INFINITY); + continue; + } - fd_wait_for_event(fd, POLLIN, USEC_INFINITY); - continue; + return n > 0 ? n : -errno; } - if (k <= 0) - return n > 0 ? n : (k < 0 ? -errno : 0); + if (k == 0) + return n; p += k; nbytes -= k; -- cgit v1.2.3-54-g00ecf