Problem: Poller event fd unspecified

Solution: Specify an invalid file descriptor for socket events
parent b56195e9
...@@ -104,11 +104,7 @@ The *zmq_poller_event_t* structure is defined as follows: ...@@ -104,11 +104,7 @@ The *zmq_poller_event_t* structure is defined as follows:
typedef struct typedef struct
{ {
void *socket; void *socket;
#if defined _WIN32 zmq_fd_t fd;
SOCKET fd;
#else
int fd;
#endif
void *user_data; void *user_data;
short events; short events;
} zmq_poller_event_t; } zmq_poller_event_t;
...@@ -142,6 +138,9 @@ _zmq_poller_size_. ...@@ -142,6 +138,9 @@ _zmq_poller_size_.
_zmq_poller_wait_all_ returns the number of valid elements. The valid elements _zmq_poller_wait_all_ returns the number of valid elements. The valid elements
are placed in positions '0' to 'n_events - 1' in the 'events' array. All are placed in positions '0' to 'n_events - 1' in the 'events' array. All
members of a valid element are set to valid values by _zmq_poller_wait_all_. members of a valid element are set to valid values by _zmq_poller_wait_all_.
For socket events 'socket' is non-null and 'fd' is an operating system
specific value for an invalid socket (-1 or INVALID_SOCKET). For fd events
'socket' is NULL and 'fd' is a valid file descriptor.
The client does therefore not need to initialize the contents of the events The client does therefore not need to initialize the contents of the events
array before a call to _zmq_poller_wait_all_. It is unspecified whether the array before a call to _zmq_poller_wait_all_. It is unspecified whether the
the remaining elements of 'events' are written to by _zmq_poller_wait_all_. the remaining elements of 'events' are written to by _zmq_poller_wait_all_.
......
...@@ -403,7 +403,7 @@ void zmq::socket_poller_t::zero_trail_events ( ...@@ -403,7 +403,7 @@ void zmq::socket_poller_t::zero_trail_events (
{ {
for (int i = found_; i < n_events_; ++i) { for (int i = found_; i < n_events_; ++i) {
events_[i].socket = NULL; events_[i].socket = NULL;
events_[i].fd = 0; events_[i].fd = zmq::retired_fd;
events_[i].user_data = NULL; events_[i].user_data = NULL;
events_[i].events = 0; events_[i].events = 0;
} }
...@@ -435,7 +435,7 @@ int zmq::socket_poller_t::check_events (zmq::socket_poller_t::event_t *events_, ...@@ -435,7 +435,7 @@ int zmq::socket_poller_t::check_events (zmq::socket_poller_t::event_t *events_,
if (it->events & events) { if (it->events & events) {
events_[found].socket = it->socket; events_[found].socket = it->socket;
events_[found].fd = 0; events_[found].fd = zmq::retired_fd;
events_[found].user_data = it->user_data; events_[found].user_data = it->user_data;
events_[found].events = it->events & events; events_[found].events = it->events & events;
++found; ++found;
......
...@@ -1299,9 +1299,10 @@ int zmq_poller_wait (void *poller_, zmq_poller_event_t *event_, long timeout_) ...@@ -1299,9 +1299,10 @@ int zmq_poller_wait (void *poller_, zmq_poller_event_t *event_, long timeout_)
const int rc = zmq_poller_wait_all (poller_, event_, 1, timeout_); const int rc = zmq_poller_wait_all (poller_, event_, 1, timeout_);
if (rc < 0 && event_) { if (rc < 0 && event_) {
// TODO this is not portable... zmq_poller_event_t contains pointers, event_->socket = NULL;
// for which nullptr does not need to be represented by all-zeroes event_->fd = zmq::retired_fd;
memset (event_, 0, sizeof (zmq_poller_event_t)); event_->user_data = NULL;
event_->events = 0;
} }
// wait_all returns number of events, but we return 0 for any success // wait_all returns number of events, but we return 0 for any success
return rc >= 0 ? 0 : rc; return rc >= 0 ? 0 : rc;
......
...@@ -686,6 +686,9 @@ void test_poll_client_server () ...@@ -686,6 +686,9 @@ void test_poll_client_server ()
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_wait (poller, &event, 500)); TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_wait (poller, &event, 500));
TEST_ASSERT_EQUAL_PTR (server, event.socket); TEST_ASSERT_EQUAL_PTR (server, event.socket);
TEST_ASSERT_NULL (event.user_data); TEST_ASSERT_NULL (event.user_data);
#ifndef _WIN32
TEST_ASSERT (event.fd == -1);
#endif
recv_string_expect_success (server, client_server_msg, 0); recv_string_expect_success (server, client_server_msg, 0);
// Polling on pollout // Polling on pollout
...@@ -694,6 +697,9 @@ void test_poll_client_server () ...@@ -694,6 +697,9 @@ void test_poll_client_server ()
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_wait (poller, &event, 0)); TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_wait (poller, &event, 0));
TEST_ASSERT_EQUAL_PTR (server, event.socket); TEST_ASSERT_EQUAL_PTR (server, event.socket);
TEST_ASSERT_NULL (event.user_data); TEST_ASSERT_NULL (event.user_data);
#ifndef _WIN32
TEST_ASSERT (event.fd == -1);
#endif
TEST_ASSERT_EQUAL_INT (ZMQ_POLLOUT, event.events); TEST_ASSERT_EQUAL_INT (ZMQ_POLLOUT, event.events);
// Stop polling server // Stop polling server
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment