Only do one event at a time to a callback.
This commit is contained in:
+19
-10
@@ -162,7 +162,7 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
|
||||
|
||||
rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms);
|
||||
|
||||
while (rc == -1 && errno == EINTR)
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
|
||||
assert(rc >= 0);
|
||||
if(rc < 0)
|
||||
@@ -177,18 +177,27 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
|
||||
|
||||
for (i = 0; i < rc; i++) {
|
||||
struct IOMuxFD *fd = mux->pending_events[i].data.ptr;
|
||||
if (fd != NULL) { //calling _unregister from a callback could have removed it
|
||||
unsigned int events;
|
||||
unsigned int events;
|
||||
|
||||
events = epoll_2_mux_events(mux->pending_events[i].events);
|
||||
events = epoll_2_mux_events(mux->pending_events[i].events);
|
||||
|
||||
//we want to deliver only one event at a time to simplify
|
||||
//application programming.
|
||||
fd = mux->pending_events[i].data.ptr;
|
||||
|
||||
if (events & MUX_EV_READ && fd != NULL) {
|
||||
assert(fd->callback != NULL);
|
||||
fd->callback(mux_, fd, events);
|
||||
//be sure not to use fd after the callback, it might been removed.
|
||||
|
||||
mux->pending_events[i].data.ptr = NULL; //clear from pending list
|
||||
|
||||
event_cnt++;
|
||||
fd->callback(mux_, fd, MUX_EV_READ);
|
||||
}
|
||||
|
||||
//now re-check, in case the IOMuxFD was removed
|
||||
fd = mux->pending_events[i].data.ptr;
|
||||
if (events & MUX_EV_WRITE && fd != NULL) {
|
||||
assert(fd->callback != NULL);
|
||||
fd->callback(mux_, fd, MUX_EV_WRITE);
|
||||
}
|
||||
|
||||
event_cnt += events != 0;
|
||||
}
|
||||
|
||||
mux->pending = 0;
|
||||
|
||||
Reference in New Issue
Block a user