From 5bae6911afba90de42b9fd21315f6d702e1bb2c6 Mon Sep 17 00:00:00 2001 From: somdoron Date: Mon, 17 Aug 2015 11:50:50 +0300 Subject: [PATCH 1/2] remove poller field, using fd instead --- include/zmq.h | 7 ++++++- src/zmq.cpp | 15 +++++++++------ tests/test_thread_safe_polling.cpp | 12 +++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index 98e13ea5..5f8981b7 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -405,7 +405,6 @@ typedef struct zmq_pollitem_t #endif short events; short revents; - void *poller; } zmq_pollitem_t; #define ZMQ_POLLITEMS_DFLT 16 @@ -414,6 +413,12 @@ ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout); ZMQ_EXPORT void *zmq_poller_new (); ZMQ_EXPORT int zmq_poller_close (void *p); +#if defined _WIN32 +ZMQ_EXPORT SOCKET zmq_poller_fd (void *p); +#else +ZMQ_EXPORT int zmq_poller_fd (void *p); +#endif + /******************************************************************************/ /* Message proxying */ /******************************************************************************/ diff --git a/src/zmq.cpp b/src/zmq.cpp index 9c4048fb..0fc4e047 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -727,8 +727,11 @@ int zmq_poller_close (void* p) } // Get poller fd - -zmq::fd_t zmq_poller_get_fd (void *p) +#if defined _WIN32 +SOCKET zmq_poller_fd (void *p) +#else +int zmq_poller_fd (void *p) +#endif { zmq::signaler_t *s = (zmq::signaler_t*)p; return s->get_fd (); @@ -790,14 +793,14 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) } if (thread_safe) { - if (!items_ [i].poller) { + if (!items_ [i].fd) { if (pollfds != spollfds) free (pollfds); errno = EINVAL; return -1; } - pollfds [i].fd = zmq_poller_get_fd (items_ [i].poller); + pollfds [i].fd = items_ [i].fd; } else { size_t zmq_fd_size = sizeof (zmq::fd_t); @@ -974,12 +977,12 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) zmq::fd_t notify_fd; if (thread_safe) { - if (!items_ [i].poller) { + if (!items_ [i].fd) { errno = EINVAL; return -1; } - notify_fd = zmq_poller_get_fd (items_ [i].poller); + notify_fd = items_ [i].fd; } else { size_t zmq_fd_size = sizeof (zmq::fd_t); diff --git a/tests/test_thread_safe_polling.cpp b/tests/test_thread_safe_polling.cpp index 7aa7f7de..09dcdbb6 100644 --- a/tests/test_thread_safe_polling.cpp +++ b/tests/test_thread_safe_polling.cpp @@ -49,15 +49,9 @@ int main (void) rc = zmq_add_poller (server2, poller); assert (rc == 0); - zmq_pollitem_t items[2]; - - items[0].socket = server; - items[0].poller = poller; - items[0].events = ZMQ_POLLIN; - - items[1].socket = server2; - items[1].poller = poller; - items[1].events = ZMQ_POLLIN; + zmq_pollitem_t items[] = { + {server, zmq_poller_fd(poller), ZMQ_POLLIN, 0}, + {server2, zmq_poller_fd(poller), ZMQ_POLLIN, 0}}; rc = zmq_bind (server, "tcp://127.0.0.1:5560"); assert (rc == 0); From d83b04534792e4ff285c0b4c4c22cdd51d15c8f8 Mon Sep 17 00:00:00 2001 From: somdoron Date: Mon, 17 Aug 2015 14:20:49 +0300 Subject: [PATCH 2/2] rename poller to pollfd --- include/zmq.h | 12 ++++++------ src/zmq.cpp | 18 +++++++++--------- tests/test_thread_safe_polling.cpp | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index 5f8981b7..b07bf60d 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -383,8 +383,8 @@ ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags); ZMQ_EXPORT int zmq_send_const (void *s, const void *buf, size_t len, int flags); ZMQ_EXPORT int zmq_recv (void *s, void *buf, size_t len, int flags); ZMQ_EXPORT int zmq_socket_monitor (void *s, const char *addr, int events); -ZMQ_EXPORT int zmq_add_poller (void *s, void *p); -ZMQ_EXPORT int zmq_remove_poller (void *s, void *p); +ZMQ_EXPORT int zmq_add_pollfd (void *s, void *p); +ZMQ_EXPORT int zmq_remove_pollfd (void *s, void *p); /******************************************************************************/ /* I/O multiplexing. */ @@ -410,13 +410,13 @@ typedef struct zmq_pollitem_t #define ZMQ_POLLITEMS_DFLT 16 ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout); -ZMQ_EXPORT void *zmq_poller_new (); -ZMQ_EXPORT int zmq_poller_close (void *p); +ZMQ_EXPORT void *zmq_pollfd_new (); +ZMQ_EXPORT int zmq_pollfd_close (void *p); #if defined _WIN32 -ZMQ_EXPORT SOCKET zmq_poller_fd (void *p); +ZMQ_EXPORT SOCKET zmq_pollfd_fd (void *p); #else -ZMQ_EXPORT int zmq_poller_fd (void *p); +ZMQ_EXPORT int zmq_pollfd_fd (void *p); #endif /******************************************************************************/ diff --git a/src/zmq.cpp b/src/zmq.cpp index 0fc4e047..68a4ee4b 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -562,9 +562,9 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) return nread; } -// Add/remove poller from a socket +// Add/remove pollfd from a socket -int zmq_add_poller (void *s_, void *p_) +int zmq_add_pollfd (void *s_, void *p_) { if (!s_ || !((zmq::socket_base_t*) s_)->check_tag ()) { errno = ENOTSOCK; @@ -576,7 +576,7 @@ int zmq_add_poller (void *s_, void *p_) return s->add_signaler(p); } -int zmq_remove_poller (void *s_, void *p_) +int zmq_remove_pollfd (void *s_, void *p_) { if (!s_ || !((zmq::socket_base_t*) s_)->check_tag ()) { errno = ENOTSOCK; @@ -709,16 +709,16 @@ const char *zmq_msg_gets (zmq_msg_t *msg_, const char *property_) } } -// Create poller +// Create pollfd -void *zmq_poller_new () +void *zmq_pollfd_new () { return new zmq::signaler_t (); } -// Close poller +// Close pollfd -int zmq_poller_close (void* p) +int zmq_pollfd_close (void* p) { zmq::signaler_t *s = (zmq::signaler_t*)p; delete s; @@ -728,9 +728,9 @@ int zmq_poller_close (void* p) // Get poller fd #if defined _WIN32 -SOCKET zmq_poller_fd (void *p) +SOCKET zmq_pollfd_fd (void *p) #else -int zmq_poller_fd (void *p) +int zmq_pollfd_fd (void *p) #endif { zmq::signaler_t *s = (zmq::signaler_t*)p; diff --git a/tests/test_thread_safe_polling.cpp b/tests/test_thread_safe_polling.cpp index 09dcdbb6..ad8d8d62 100644 --- a/tests/test_thread_safe_polling.cpp +++ b/tests/test_thread_safe_polling.cpp @@ -39,19 +39,19 @@ int main (void) void *server = zmq_socket (ctx, ZMQ_SERVER); void *server2 = zmq_socket (ctx, ZMQ_SERVER); - void *poller = zmq_poller_new (); + void *pollfd = zmq_pollfd_new (); int rc; - rc = zmq_add_poller (server, poller); + rc = zmq_add_pollfd (server, pollfd); assert (rc == 0); - rc = zmq_add_poller (server2, poller); + rc = zmq_add_pollfd (server2, pollfd); assert (rc == 0); zmq_pollitem_t items[] = { - {server, zmq_poller_fd(poller), ZMQ_POLLIN, 0}, - {server2, zmq_poller_fd(poller), ZMQ_POLLIN, 0}}; + {server, zmq_pollfd_fd(pollfd), ZMQ_POLLIN, 0}, + {server2, zmq_pollfd_fd(pollfd), ZMQ_POLLIN, 0}}; rc = zmq_bind (server, "tcp://127.0.0.1:5560"); assert (rc == 0); @@ -94,13 +94,13 @@ int main (void) rc = zmq_msg_close(&msg); assert (rc == 0); - rc = zmq_remove_poller (server, poller); + rc = zmq_remove_pollfd (server, pollfd); assert (rc == 0); - rc = zmq_remove_poller (server2, poller); + rc = zmq_remove_pollfd (server2, pollfd); assert (rc == 0); - rc = zmq_poller_close (poller); + rc = zmq_pollfd_close (pollfd); assert (rc == 0); rc = zmq_close (server);