mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-19 16:56:11 +01:00
Problem: poller implementation of zmq_poll is slow
Solution: use it only if there is at least one thread-safe socket, which is not compatible with the older zmq_poll implementation.
This commit is contained in:
parent
b6f55eac14
commit
ab1607f813
13
src/zmq.cpp
13
src/zmq.cpp
@ -801,9 +801,15 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
// TODO: the function implementation can just call zmq_pollfd_poll with
|
||||
// pollfd as NULL, however pollfd is not yet stable.
|
||||
#if defined ZMQ_HAVE_POLLER
|
||||
// if poller is present, use that.
|
||||
return zmq_poller_poll (items_, nitems_, timeout_);
|
||||
#else
|
||||
// if poller is present, use that if there is at least 1 thread-safe socket,
|
||||
// otherwise fall back to the previous implementation as it's faster.
|
||||
for (int i = 0; i != nitems_; i++) {
|
||||
if (items_[i].socket
|
||||
&& as_socket_base_t (items_[i].socket)->is_thread_safe ()) {
|
||||
return zmq_poller_poll (items_, nitems_, timeout_);
|
||||
}
|
||||
}
|
||||
#endif // ZMQ_HAVE_POLLER
|
||||
#if defined ZMQ_POLL_BASED_ON_POLL || defined ZMQ_POLL_BASED_ON_SELECT
|
||||
if (unlikely (nitems_ < 0)) {
|
||||
errno = EINVAL;
|
||||
@ -1086,7 +1092,6 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
#endif
|
||||
#endif // ZMQ_HAVE_POLLER
|
||||
}
|
||||
|
||||
// The poller functionality
|
||||
|
Loading…
x
Reference in New Issue
Block a user