[systemd-devel] [PATCH 2/2] util.c: hook loop_read/loop_write to fd_pollin/fd_pollout

chenj at lemote.com chenj at lemote.com
Mon Dec 19 02:23:47 PST 2011


From: cee1 <fykcee1 at gmail.com>

---
 src/util.c |   34 ++++++----------------------------
 1 files changed, 6 insertions(+), 28 deletions(-)

diff --git a/src/util.c b/src/util.c
index a46897a..1cb2626 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2858,21 +2858,10 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
                                 continue;
 
                         if (k < 0 && errno == EAGAIN && do_poll) {
-                                struct pollfd pollfd;
+                                int r = fd_pollin(fd, true);
 
-                                zero(pollfd);
-                                pollfd.fd = fd;
-                                pollfd.events = POLLIN;
-
-                                if (poll(&pollfd, 1, -1) < 0) {
-                                        if (errno == EINTR)
-                                                continue;
-
-                                        return n > 0 ? n : -errno;
-                                }
-
-                                if (pollfd.revents != POLLIN)
-                                        return n > 0 ? n : -EIO;
+                                if (r < 0)
+                                        return n > 0 ? n : r;
 
                                 continue;
                         }
@@ -2906,21 +2895,10 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
                                 continue;
 
                         if (k < 0 && errno == EAGAIN && do_poll) {
-                                struct pollfd pollfd;
-
-                                zero(pollfd);
-                                pollfd.fd = fd;
-                                pollfd.events = POLLOUT;
-
-                                if (poll(&pollfd, 1, -1) < 0) {
-                                        if (errno == EINTR)
-                                                continue;
-
-                                        return n > 0 ? n : -errno;
-                                }
+                                int r = fd_pollout(fd, true);
 
-                                if (pollfd.revents != POLLOUT)
-                                        return n > 0 ? n : -EIO;
+                                if (r < 0)
+                                        return n > 0 ? n : r;
 
                                 continue;
                         }
-- 
1.7.7.4



More information about the systemd-devel mailing list