mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-29 08:39:42 +08:00
Merge pull request #2141 from minrk/heap-alloc-poll-events
heap-allocate events in zmq_poller_poll
This commit is contained in:
commit
b0df7f1f17
10
src/zmq.cpp
10
src/zmq.cpp
@ -747,10 +747,12 @@ 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[nitems_];
|
||||
zmq_poller_event_t *events;
|
||||
events = new zmq_poller_event_t[nitems_];
|
||||
alloc_assert(events);
|
||||
void *poller = zmq_poller_new ();
|
||||
alloc_assert(poller);
|
||||
|
||||
|
||||
// Register sockets with poller
|
||||
for (int i = 0; i < nitems_; i++) {
|
||||
if (items_[i].socket) {
|
||||
@ -758,6 +760,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
rc = zmq_poller_add (poller, items_[i].socket, NULL, items_[i].events);
|
||||
if (rc < 0) {
|
||||
zmq_poller_destroy (&poller);
|
||||
delete [] events;
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@ -765,6 +768,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
rc = zmq_poller_add_fd (poller, items_[i].fd, NULL, items_[i].events);
|
||||
if (rc < 0) {
|
||||
zmq_poller_destroy (&poller);
|
||||
delete [] events;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@ -774,6 +778,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
rc = zmq_poller_wait_all (poller, events, nitems_, timeout_);
|
||||
if (rc < 0) {
|
||||
zmq_poller_destroy (&poller);
|
||||
delete [] events;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -784,6 +789,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
||||
|
||||
// Cleanup
|
||||
rc = zmq_poller_destroy (&poller);
|
||||
delete [] events;
|
||||
return rc;
|
||||
}
|
||||
#endif // ZMQ_HAVE_POLLER
|
||||
|
Loading…
x
Reference in New Issue
Block a user