aboutsummaryrefslogtreecommitdiff
path: root/fdm.h
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-01 18:51:33 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-01 18:51:33 +0000
commit80c4721e578ae20f6c5a6b7959fde909582eeb85 (patch)
treefad840396ebe9f7c2e1bff2280264d21c28ea0fa /fdm.h
parentterm: fdm_shutdown(): remove debug output (diff)
fdm: don't free FD data that may be referenced by epoll return data
It is perfectly possible, and legal, for a FDM handler to delete another handler. The problem however is when the epoll returned array of FD events contain the removed FD handler *after* the handler that removed it. That is, if the epoll returned array is: [FD=13, FD=37] and the handler for FD=13 removes FD=37, then given the current implementation, the FD user data (our handler callback etc) will point to a free:d address. Add support for this situation by deferring FD handler removal *when called from another handler*. This is done by "locking" the FDM struct before looping the handlers for FDs with events (and unlocking afterwards). In fdm_del(), we check if the FDM has been locked, in which case the FD is marked as deleted, and put on a deferred list. But not *actually* deleted. Meanwhile, in the FDM poll function, we skip calling handlers for marked-for-deletion FDs. Then, when all FDs have been processed, we loop the deferred list and finally deletes the FDs for real.
Diffstat (limited to 'fdm.h')
-rw-r--r--fdm.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/fdm.h b/fdm.h
index cd0fee2a..fb12bffb 100644
--- a/fdm.h
+++ b/fdm.h
@@ -11,5 +11,6 @@ void fdm_destroy(struct fdm *fdm);
bool fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data);
bool fdm_del(struct fdm *fdm, int fd);
+bool fdm_del_no_close(struct fdm *fdm, int fd);
bool fdm_poll(struct fdm *fdm);