[zeromq-dev] zeromq2: problem with closing pollable socket
Martin Sustrik
sustrik at fastmq.com
Thu Oct 22 09:15:25 CEST 2009
Hi Vitaliy,
The problem demonstrates itself only on Linux platforms that support
eventfd mechanism. Unfortunately, I have no access to such a system at
the moment. Can you check whether the following patch solves the problem?
Thanks.
Martin
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;
}
Vitaly Mayatskikh wrote:
> At Wed, 21 Oct 2009 13:49:59 +0200, Vitaly Mayatskikh wrote:
>
>> Assertion failed: false (fd_signaler.cpp:72)
>> Aborted
>
> Backtrace:
>
> #0 0x000000329ec33575 in raise () from /lib64/libc.so.6
> #1 0x000000329ec34d55 in abort () from /lib64/libc.so.6
> #2 0x00007ffff7d9dd65 in zmq::fd_signaler_t::poll (this=<value optimized out>) at fd_signaler.cpp:72
> #3 0x00007ffff7d9a60a in zmq::app_thread_t::process_commands (this=0x601120, block_=<value optimized out>, throttle_=<value optimized out>) at app_thread.cpp:104
> #4 0x00007ffff7da86ae in zmq::socket_base_t::close (this=0x601850) at socket_base.cpp:350
> #5 0x00007ffff7dacf39 in zmq_close (s_=<value optimized out>) at zmq.cpp:226
> #6 0x00000000004008e8 in main () at z.cpp:20
>
More information about the zeromq-dev
mailing list