diff --git a/include/zmq.h b/include/zmq.h index 2b3a5ec7..780dfc6c 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -709,6 +709,7 @@ ZMQ_EXPORT int zmq_poller_wait_all (void *poller, zmq_poller_event_t *events, int n_events, long timeout); +ZMQ_EXPORT int zmq_poller_fd (void *poller); #if defined _WIN32 ZMQ_EXPORT int diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index 57360bbc..9aaf4607 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -86,6 +86,17 @@ bool zmq::socket_poller_t::check_tag () return _tag == 0xCAFEBABE; } +int zmq::socket_poller_t::signaler_fd () +{ + if (_signaler) { + return _signaler->get_fd (); + } else { + // Only thread-safe socket types are guaranteed to have a signaler. + errno = EINVAL; + return -1; + } +} + int zmq::socket_poller_t::add (socket_base_t *socket_, void *user_data_, short events_) diff --git a/src/socket_poller.hpp b/src/socket_poller.hpp index 916d98a7..336832d2 100644 --- a/src/socket_poller.hpp +++ b/src/socket_poller.hpp @@ -75,6 +75,8 @@ class socket_poller_t int add_fd (fd_t fd_, void *user_data_, short events_); int modify_fd (fd_t fd_, short events_); int remove_fd (fd_t fd_); + // Returns the signaler's fd if there is one, otherwise errors. + int signaler_fd (); int wait (event_t *event_, int n_events_, long timeout_); diff --git a/src/zmq.cpp b/src/zmq.cpp index 5d186283..521d9939 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -1278,6 +1278,11 @@ int zmq_poller_wait_all (void *poller_, return rc; } +int zmq_poller_fd (void *poller_) +{ + return static_cast (poller_)->signaler_fd (); +} + // Peer-specific state int zmq_socket_get_peer_state (void *s_, diff --git a/src/zmq_draft.h b/src/zmq_draft.h index c8934d45..2bba4133 100644 --- a/src/zmq_draft.h +++ b/src/zmq_draft.h @@ -105,6 +105,7 @@ int zmq_poller_wait_all (void *poller_, zmq_poller_event_t *events_, int n_events_, long timeout_); +int zmq_poller_fd (void *poller_); #if defined _WIN32 int zmq_poller_add_fd (void *poller_,