Only do one event at a time to a callback.

This commit is contained in:
Nils O. Selåsdal
2013-11-09 11:06:19 +01:00
parent a4c6b65d5f
commit 6b26812cf3
3 changed files with 38 additions and 27 deletions
+16 -15
View File
@@ -150,7 +150,7 @@ static int iomux_select_run(struct IOMux *mux_, struct timeval *timeout)
write_set = mux->master_write_set;
rc = select(mux->max_fd + 1, &read_set, &write_set, NULL, timeout); //we can use timeout directly
while (rc == -1 && errno == EINTR)
} while (rc == -1 && errno == EINTR);
assert(rc >= 0);
if (rc < 0)
@@ -164,25 +164,26 @@ static int iomux_select_run(struct IOMux *mux_, struct timeval *timeout)
for (i = 0; rc > 0 && i < mux->num_descriptors; i++) {
unsigned int events = 0;
if (mux->descriptors[i] == NULL) { //callback might have deleted it
continue;
//deliver only one event at a time , to simplify application
//programming
if (mux->descriptors[i] != NULL &&
FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
rc--;
assert(mux->descriptors[i]->callback != NULL);
mux->descriptors[i]->callback(mux_, mux->descriptors[i], MUX_EV_READ);
events = 1;
}
if (FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
//need to re-check in case the callback deleted the IOMuxFD
if (mux->descriptors[i] != NULL &&
FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
rc--;
events |= MUX_EV_READ;
}
if (FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
rc--;
events |= MUX_EV_WRITE;
assert(mux->descriptors[i]->callback != NULL);
mux->descriptors[i]->callback(mux_, mux->descriptors[i], MUX_EV_WRITE);
events = 1;
}
if (events) {
assert(mux->descriptors[i]->callback != NULL);
mux->descriptors[i]->callback(mux_, mux->descriptors[i], events);
event_cnt++;
}
event_cnt += events;
}
return event_cnt;