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