summaryrefslogtreecommitdiff
path: root/libguile/poll.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-04-04 12:22:12 +0200
committerAndy Wingo <wingo@pobox.com>2016-04-04 16:30:57 +0200
commit4bd903892535b1b1ddb7a7b09895e85e96736745 (patch)
tree16469e292b1d6ed57b04a6f9d46688255ffdcf6a /libguile/poll.c
parentb77fb752dd7e14876741ecb6360ef0319eae18e0 (diff)
downloadguile-4bd903892535b1b1ddb7a7b09895e85e96736745.tar.gz
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.
Diffstat (limited to 'libguile/poll.c')
-rw-r--r--libguile/poll.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libguile/poll.c b/libguile/poll.c
index 9ea846b6d..90a5c05e1 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;
}
}