guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 14/18: Fix POLLOUT assignment from port buffers


From: Andy Wingo
Subject: [Guile-commits] 14/18: Fix POLLOUT assignment from port buffers
Date: Wed, 06 Apr 2016 17:27:08 +0000

wingo pushed a commit to branch wip-port-refactor
in repository guile.

commit 4bd903892535b1b1ddb7a7b09895e85e96736745
Author: Andy Wingo <address@hidden>
Date:   Mon Apr 4 12:22:12 2016 +0200

    Fix POLLOUT assignment from port buffers
    
    * libguile/poll.c (scm_primitive_poll): A buffered port's buffer marks
      it as writable only when writing a byte would not block, which is the
      case only if there is more than one byte free in the buffer; writing
      the last byte would block.
---
 libguile/poll.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libguile/poll.c b/libguile/poll.c
index 9ea846b..90a5c05 100644
--- a/libguile/poll.c
+++ b/libguile/poll.c
@@ -111,8 +111,10 @@ scm_primitive_poll (SCM pollfds, SCM nfds, SCM ports, SCM 
timeout)
               if (pt->read_pos < pt->read_end)
                 /* Buffered input waiting to be read. */
                 revents |= POLLIN;
-              if (pt->write_pos < pt->write_end)
-                /* Buffered output possible. */
+              if (SCM_OUTPUT_PORT_P (port)
+                  && pt->write_end - pt->write_pos > 1)
+                /* Buffered output possible.  The "> 1" is because
+                   writing the last byte would flush the port.  */
                 revents |= POLLOUT;
             }
         }
@@ -147,8 +149,10 @@ scm_primitive_poll (SCM pollfds, SCM nfds, SCM ports, SCM 
timeout)
                 if (pt->read_pos < pt->read_end)
                   /* Buffered input waiting to be read. */
                   revents |= POLLIN;
-                if (SCM_OUTPUT_PORT_P (port) && pt->write_pos < pt->write_end)
-                  /* Buffered output possible. */
+                if (SCM_OUTPUT_PORT_P (port)
+                    && pt->write_end - pt->write_pos > 1)
+                  /* Buffered output possible.  The "> 1" is because
+                     writing the last byte would flush the port.  */
                   revents |= POLLOUT;
               }
           }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]