sched: allow file handler with multiple events to remove itself
Before dispatching a handler, check if it is still valid. This allows a handler to remove itself when a descriptor has two different events at the same time.
This commit is contained in:
parent
b33b682356
commit
a8167b7959
1 changed files with 6 additions and 3 deletions
3
sched.c
3
sched.c
|
@ -534,6 +534,7 @@ dispatch_filehandlers(int nfd, fd_set *read_fds, fd_set *write_fds, fd_set *exce
|
|||
if (except_fds && FD_ISSET(fd, except_fds)) {
|
||||
/* This descriptor has an exception, dispatch its handler */
|
||||
ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
|
||||
if (ptr->handler)
|
||||
(ptr->handler)(fd, SCH_FILE_EXCEPTION, ptr->arg);
|
||||
nfd--;
|
||||
|
||||
|
@ -547,6 +548,7 @@ dispatch_filehandlers(int nfd, fd_set *read_fds, fd_set *write_fds, fd_set *exce
|
|||
if (read_fds && FD_ISSET(fd, read_fds)) {
|
||||
/* This descriptor can be read from, dispatch its handler */
|
||||
ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
|
||||
if (ptr->handler)
|
||||
(ptr->handler)(fd, SCH_FILE_INPUT, ptr->arg);
|
||||
nfd--;
|
||||
}
|
||||
|
@ -554,6 +556,7 @@ dispatch_filehandlers(int nfd, fd_set *read_fds, fd_set *write_fds, fd_set *exce
|
|||
if (write_fds && FD_ISSET(fd, write_fds)) {
|
||||
/* This descriptor can be written to, dispatch its handler */
|
||||
ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
|
||||
if (ptr->handler)
|
||||
(ptr->handler)(fd, SCH_FILE_OUTPUT, ptr->arg);
|
||||
nfd--;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue