Re: [PATCHv3 02/13] xread: poll on non blocking fds

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCHv3 02/13] xread: poll on non blocking fds

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:06:39

Eric Sunshine [off-list ref] writes:
quoted
        while (1) {
                nr = read(fd, buf, len);
-               if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
-                       continue;
+               if (nr < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                               struct pollfd pfd;
+                               int i;
+                               pfd.events = POLLIN;
+                               pfd.fd = fd;
+                               i = poll(&pfd, 1, 100);
Why is this poll() using a timeout? Isn't that still a busy wait of
sorts (even if less aggressive)?
Good point.  If we _were_ to have this kind of "hiding issues under
the rug and continuing without issues" approach, I do not think we
would need timeout for this poll(2).  The caller accepted that it is
willing to wait until we read up to len (which is capped, though) by
not calling the nonblocking variant.

Re: [PATCHv3 02/13] xread: poll on non blocking fds

From: Stefan Beller <hidden>
Date: 2016-06-15 23:06:39

On Tue, Sep 22, 2015 at 8:58 AM, Junio C Hamano [off-list ref] wrote:
Eric Sunshine [off-list ref] writes:
quoted
quoted
        while (1) {
                nr = read(fd, buf, len);
-               if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
-                       continue;
+               if (nr < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                               struct pollfd pfd;
+                               int i;
+                               pfd.events = POLLIN;
+                               pfd.fd = fd;
+                               i = poll(&pfd, 1, 100);
Why is this poll() using a timeout? Isn't that still a busy wait of
sorts (even if less aggressive)?
True. Maybe we could have just a warning for now?

    if (errno == EAGAIN) {
        warning("Using xread with a non blocking fd");
        continue; /* preserve previous behavior */
    }

I think I am going to drop this patch off the main series and spin it out
as an extra patch as the discussion is a bit unclear to me at the moment
where we're heading.
Good point.  If we _were_ to have this kind of "hiding issues under
the rug and continuing without issues" approach, I do not think we
would need timeout for this poll(2).  The caller accepted that it is
willing to wait until we read up to len (which is capped, though) by
not calling the nonblocking variant.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help