mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Solution: unreachable code paths in socket_poller_t
Problem: replaced by assertions resp. removed
This commit is contained in:
parent
8ae91fdf9a
commit
f685a3ffd2
@ -106,15 +106,16 @@ int zmq::socket_poller_t::add (socket_base_t *socket_, void* user_data_, short e
|
|||||||
int thread_safe;
|
int thread_safe;
|
||||||
size_t thread_safe_size = sizeof(int);
|
size_t thread_safe_size = sizeof(int);
|
||||||
|
|
||||||
if (socket_->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size) == -1)
|
int rc =
|
||||||
return -1;
|
socket_->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size);
|
||||||
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
if (thread_safe) {
|
if (thread_safe) {
|
||||||
if (signaler == NULL)
|
if (signaler == NULL)
|
||||||
signaler = new signaler_t ();
|
signaler = new signaler_t ();
|
||||||
|
|
||||||
if (socket_->add_signaler (signaler) == -1)
|
rc = socket_->add_signaler (signaler);
|
||||||
return -1;
|
zmq_assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
item_t item = {socket_, 0, user_data_, events_
|
item_t item = {socket_, 0, user_data_, events_
|
||||||
@ -236,7 +237,7 @@ int zmq::socket_poller_t::remove_fd (fd_t fd_)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::socket_poller_t::rebuild ()
|
void zmq::socket_poller_t::rebuild ()
|
||||||
{
|
{
|
||||||
#if defined ZMQ_POLL_BASED_ON_POLL
|
#if defined ZMQ_POLL_BASED_ON_POLL
|
||||||
|
|
||||||
@ -255,8 +256,9 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
int thread_safe;
|
int thread_safe;
|
||||||
size_t thread_safe_size = sizeof(int);
|
size_t thread_safe_size = sizeof(int);
|
||||||
|
|
||||||
if (it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size) == -1)
|
int rc = it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe,
|
||||||
return -1;
|
&thread_safe_size);
|
||||||
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
if (thread_safe) {
|
if (thread_safe) {
|
||||||
if (!use_signaler) {
|
if (!use_signaler) {
|
||||||
@ -273,7 +275,7 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (poll_size == 0)
|
if (poll_size == 0)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
pollfds = (pollfd*) malloc (poll_size * sizeof (pollfd));
|
pollfds = (pollfd*) malloc (poll_size * sizeof (pollfd));
|
||||||
alloc_assert (pollfds);
|
alloc_assert (pollfds);
|
||||||
@ -292,14 +294,14 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
int thread_safe;
|
int thread_safe;
|
||||||
size_t thread_safe_size = sizeof(int);
|
size_t thread_safe_size = sizeof(int);
|
||||||
|
|
||||||
if (it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size) == -1)
|
int rc = it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe,
|
||||||
return -1;
|
&thread_safe_size);
|
||||||
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
if (!thread_safe) {
|
if (!thread_safe) {
|
||||||
size_t fd_size = sizeof (zmq::fd_t);
|
size_t fd_size = sizeof (zmq::fd_t);
|
||||||
if (it->socket->getsockopt (ZMQ_FD, &pollfds [item_nbr].fd, &fd_size) == -1) {
|
rc = it->socket->getsockopt (ZMQ_FD, &pollfds [item_nbr].fd, &fd_size);
|
||||||
return -1;
|
zmq_assert (rc == 0);
|
||||||
}
|
|
||||||
|
|
||||||
pollfds [item_nbr].events = POLLIN;
|
pollfds [item_nbr].events = POLLIN;
|
||||||
item_nbr++;
|
item_nbr++;
|
||||||
@ -336,8 +338,9 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
int thread_safe;
|
int thread_safe;
|
||||||
size_t thread_safe_size = sizeof(int);
|
size_t thread_safe_size = sizeof(int);
|
||||||
|
|
||||||
if (it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size) == -1)
|
int rc = it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe,
|
||||||
return -1;
|
&thread_safe_size);
|
||||||
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
if (thread_safe && it->events) {
|
if (thread_safe && it->events) {
|
||||||
use_signaler = true;
|
use_signaler = true;
|
||||||
@ -359,14 +362,15 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
int thread_safe;
|
int thread_safe;
|
||||||
size_t thread_safe_size = sizeof(int);
|
size_t thread_safe_size = sizeof(int);
|
||||||
|
|
||||||
if (it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe, &thread_safe_size) == -1)
|
int rc = it->socket->getsockopt (ZMQ_THREAD_SAFE, &thread_safe,
|
||||||
return -1;
|
&thread_safe_size);
|
||||||
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
if (!thread_safe) {
|
if (!thread_safe) {
|
||||||
zmq::fd_t notify_fd;
|
zmq::fd_t notify_fd;
|
||||||
size_t fd_size = sizeof (zmq::fd_t);
|
size_t fd_size = sizeof (zmq::fd_t);
|
||||||
if (it->socket->getsockopt (ZMQ_FD, ¬ify_fd, &fd_size) == -1)
|
rc = it->socket->getsockopt (ZMQ_FD, ¬ify_fd, &fd_size);
|
||||||
return -1;
|
zmq_assert (rc == 0);
|
||||||
|
|
||||||
FD_SET (notify_fd, &pollset_in);
|
FD_SET (notify_fd, &pollset_in);
|
||||||
if (maxfd < notify_fd)
|
if (maxfd < notify_fd)
|
||||||
@ -395,7 +399,6 @@ int zmq::socket_poller_t::rebuild ()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
need_rebuild = false;
|
need_rebuild = false;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_events_, long timeout_)
|
int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_events_, long timeout_)
|
||||||
@ -406,13 +409,12 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (need_rebuild)
|
if (need_rebuild)
|
||||||
if (rebuild () == -1)
|
rebuild ();
|
||||||
return -1;
|
|
||||||
|
|
||||||
#if defined ZMQ_POLL_BASED_ON_POLL
|
#if defined ZMQ_POLL_BASED_ON_POLL
|
||||||
if (unlikely (poll_size == 0)) {
|
if (unlikely (poll_size == 0)) {
|
||||||
// We'll report an error (timed out) as if the list was non-empty and
|
// We'll report an error (timed out) as if the list was non-empty and
|
||||||
// no event occured within the specified timeout. Otherwise the caller
|
// no event occurred within the specified timeout. Otherwise the caller
|
||||||
// needs to check the return value AND the event to avoid using the
|
// needs to check the return value AND the event to avoid using the
|
||||||
// nullified event data.
|
// nullified event data.
|
||||||
errno = EAGAIN;
|
errno = EAGAIN;
|
||||||
@ -532,21 +534,18 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The timeout is finite and there are no events. In the first pass
|
// The timeout is finite but non-zero and there are no events. In the
|
||||||
// we get a timestamp of when the polling have begun. (We assume that
|
// first pass, we get a timestamp of when the polling have begun.
|
||||||
// first pass have taken negligible time). We also compute the time
|
// (We assume that first pass have taken negligible time). We also
|
||||||
// when the polling should time out.
|
// compute the time when the polling should time out.
|
||||||
|
now = clock.now_ms ();
|
||||||
if (first_pass) {
|
if (first_pass) {
|
||||||
now = clock.now_ms ();
|
|
||||||
end = now + timeout_;
|
end = now + timeout_;
|
||||||
if (now == end)
|
|
||||||
break;
|
|
||||||
first_pass = false;
|
first_pass = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out whether timeout have expired.
|
// Find out whether timeout have expired.
|
||||||
now = clock.now_ms ();
|
|
||||||
if (now >= end)
|
if (now >= end)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -696,17 +695,14 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
|
|||||||
// we get a timestamp of when the polling have begun. (We assume that
|
// we get a timestamp of when the polling have begun. (We assume that
|
||||||
// first pass have taken negligible time). We also compute the time
|
// first pass have taken negligible time). We also compute the time
|
||||||
// when the polling should time out.
|
// when the polling should time out.
|
||||||
|
now = clock.now_ms ();
|
||||||
if (first_pass) {
|
if (first_pass) {
|
||||||
now = clock.now_ms ();
|
|
||||||
end = now + timeout_;
|
end = now + timeout_;
|
||||||
if (now == end)
|
|
||||||
break;
|
|
||||||
first_pass = false;
|
first_pass = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out whether timeout have expired.
|
// Find out whether timeout have expired.
|
||||||
now = clock.now_ms ();
|
|
||||||
if (now >= end)
|
if (now >= end)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ namespace zmq
|
|||||||
bool check_tag ();
|
bool check_tag ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int rebuild ();
|
void rebuild ();
|
||||||
|
|
||||||
// Used to check whether the object is a socket_poller.
|
// Used to check whether the object is a socket_poller.
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user