Problem: Cannot get thread safe socket fd

Solution: Add a method to get the zmq_poller's signaler fd. Then we can
associate a poller instance with every thread safe socket and use its
fd.
This commit is contained in:
jean-airoldie 2019-04-27 20:36:24 -04:00
parent 501f9d8da4
commit 046534480b
5 changed files with 20 additions and 0 deletions

View File

@ -709,6 +709,7 @@ ZMQ_EXPORT int zmq_poller_wait_all (void *poller,
zmq_poller_event_t *events, zmq_poller_event_t *events,
int n_events, int n_events,
long timeout); long timeout);
ZMQ_EXPORT int zmq_poller_fd (void *poller);
#if defined _WIN32 #if defined _WIN32
ZMQ_EXPORT int ZMQ_EXPORT int

View File

@ -86,6 +86,17 @@ bool zmq::socket_poller_t::check_tag ()
return _tag == 0xCAFEBABE; 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_, int zmq::socket_poller_t::add (socket_base_t *socket_,
void *user_data_, void *user_data_,
short events_) short events_)

View File

@ -75,6 +75,8 @@ class socket_poller_t
int add_fd (fd_t fd_, void *user_data_, short events_); int add_fd (fd_t fd_, void *user_data_, short events_);
int modify_fd (fd_t fd_, short events_); int modify_fd (fd_t fd_, short events_);
int remove_fd (fd_t fd_); 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_); int wait (event_t *event_, int n_events_, long timeout_);

View File

@ -1278,6 +1278,11 @@ int zmq_poller_wait_all (void *poller_,
return rc; return rc;
} }
int zmq_poller_fd (void *poller_)
{
return static_cast<zmq::socket_poller_t *> (poller_)->signaler_fd ();
}
// Peer-specific state // Peer-specific state
int zmq_socket_get_peer_state (void *s_, int zmq_socket_get_peer_state (void *s_,

View File

@ -105,6 +105,7 @@ int zmq_poller_wait_all (void *poller_,
zmq_poller_event_t *events_, zmq_poller_event_t *events_,
int n_events_, int n_events_,
long timeout_); long timeout_);
int zmq_poller_fd (void *poller_);
#if defined _WIN32 #if defined _WIN32
int zmq_poller_add_fd (void *poller_, int zmq_poller_add_fd (void *poller_,