Commit 319eb27f authored by bjovke's avatar bjovke

Unnecessary dynamic memory allocation for zmq::socket_poller_t in…

Unnecessary dynamic memory allocation for zmq::socket_poller_t in zmq_poller_poll(). Fixed by allocating zmq::socket_poller_t from stack.
parent 5d5263ed
...@@ -757,10 +757,9 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -757,10 +757,9 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// implement zmq_poll on top of zmq_poller // implement zmq_poll on top of zmq_poller
int rc; int rc;
zmq_poller_event_t *events; zmq_poller_event_t *events;
zmq::socket_poller_t poller;
events = new (std::nothrow) zmq_poller_event_t[nitems_]; events = new (std::nothrow) zmq_poller_event_t[nitems_];
alloc_assert(events); alloc_assert(events);
void *poller = zmq_poller_new ();
alloc_assert(poller);
bool repeat_items = false; bool repeat_items = false;
// Register sockets with poller // Register sockets with poller
...@@ -780,12 +779,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -780,12 +779,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
} }
} }
if (modify) { if (modify) {
rc = zmq_poller_modify (poller, items_[i].socket, e); rc = zmq_poller_modify (&poller, items_[i].socket, e);
} else { } else {
rc = zmq_poller_add (poller, items_[i].socket, NULL, e); rc = zmq_poller_add (&poller, items_[i].socket, NULL, e);
} }
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events; delete [] events;
return rc; return rc;
} }
...@@ -800,12 +798,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -800,12 +798,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
} }
} }
if (modify) { if (modify) {
rc = zmq_poller_modify_fd (poller, items_[i].fd, e); rc = zmq_poller_modify_fd (&poller, items_[i].fd, e);
} else { } else {
rc = zmq_poller_add_fd (poller, items_[i].fd, NULL, e); rc = zmq_poller_add_fd (&poller, items_[i].fd, NULL, e);
} }
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events; delete [] events;
return rc; return rc;
} }
...@@ -813,9 +810,8 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -813,9 +810,8 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
} }
// Wait for events // Wait for events
rc = zmq_poller_wait_all (poller, events, nitems_, timeout_); rc = zmq_poller_wait_all (&poller, events, nitems_, timeout_);
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events; delete [] events;
if (zmq_errno() == ETIMEDOUT) { if (zmq_errno() == ETIMEDOUT) {
return 0; return 0;
...@@ -851,7 +847,6 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -851,7 +847,6 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
} }
// Cleanup // Cleanup
zmq_poller_destroy (&poller);
delete [] events; delete [] events;
return rc; return rc;
} }
......
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