summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.commkdir>2009-10-22 13:21:27 +0200
committerMartin Sustrik <sustrik@fastmq.commkdir>2009-10-22 13:21:27 +0200
commit7cbdcc954213b715ce83316538403bbce1fac99f (patch)
tree9ed5484c553260464d986d62039d4b7e19bd80e8 /src
parent55acf365ea76b908388ca9726232bde90242cdcb (diff)
ZMQII-21: Problem with fd_signaler_t::poll on socket close
Diffstat (limited to 'src')
-rw-r--r--src/fd_signaler.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/fd_signaler.cpp b/src/fd_signaler.cpp
index 293123d..79696a3 100644
--- a/src/fd_signaler.cpp
+++ b/src/fd_signaler.cpp
@@ -67,20 +67,37 @@ void zmq::fd_signaler_t::signal (int signal_)
uint64_t zmq::fd_signaler_t::poll ()
{
- // TODO: Can we do a blocking read on non-blocking eventfd?
- // It's not needed as for now, so let it stay unimplemented.
- zmq_assert (false);
- return 0;
+ // Set to blocking mode.
+ int flags = fcntl (fd, F_GETFL, 0);
+ if (flags == -1)
+ flags = 0;
+ int rc = fcntl (fd, F_SETFL, flags & ~O_NONBLOCK);
+ errno_assert (rc != -1);
+
+ uint64_t signals;
+ ssize_t sz;
+ while (true) {
+ sz = read (fd, &signals, sizeof (uint64_t));
+ if (sz == 0 || (errno != EAGAIN && errno != EINTR))
+ break;
+ }
+ errno_assert (sz != -1);
+
+ // Set to non-blocking mode.
+ rc = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+ errno_assert (rc != -1);
+
+ return signals;
}
uint64_t zmq::fd_signaler_t::check ()
{
- uint64_t val;
- ssize_t sz = read (fd, &val, sizeof (uint64_t));
+ uint64_t signals;
+ ssize_t sz = read (fd, &signals, sizeof (uint64_t));
if (sz == -1 && (errno == EAGAIN || errno == EINTR))
return 0;
errno_assert (sz != -1);
- return val;
+ return signals;
}
zmq::fd_t zmq::fd_signaler_t::get_fd ()