diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2023-04-09 14:13:37 +0200 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2023-04-09 14:13:37 +0200 |
commit | c5334a46523b9ac959c002fbc23a25eeccf63599 (patch) | |
tree | 5f724394e7124bfca803c2c73574b48202db070e | |
parent | 809618988f918d0a54cc67bf416e455517cfc8cd (diff) |
Add fd forgetting function to io muxer
-rw-r--r-- | io_muxer.c | 8 | ||||
-rw-r--r-- | io_muxer.h | 1 |
2 files changed, 8 insertions, 1 deletions
@@ -98,12 +98,18 @@ enum IoMuxerResult IoMuxerIterate(struct IoMuxer* io_muxer, int timeout) { break; } for (size_t i = 0; i < io_muxer->size; i++) { - if (io_muxer->pfds[i].revents) + if (io_muxer->pfds[i].revents && io_muxer->pfds[i].revents != POLLNVAL) io_muxer->tasks[i].fun(io_muxer->tasks[i].user); } return kIoMuxerResultSuccess; } +void IoMuxerForget(struct IoMuxer* io_muxer, int fd) { + for (size_t i = 0; i < io_muxer->size; i++) { + if (io_muxer->pfds[i].fd == fd) io_muxer->pfds[i].revents = POLLNVAL; + } +} + void IoMuxerDestroy(struct IoMuxer* io_muxer) { free(io_muxer->pfds); free(io_muxer->tasks); @@ -47,6 +47,7 @@ bool IoMuxerOnRead(struct IoMuxer* io_muxer, int fd, void (*fun)(void*), bool IoMuxerOnWrite(struct IoMuxer* io_muxer, int fd, void (*fun)(void*), void* user); enum IoMuxerResult IoMuxerIterate(struct IoMuxer* io_muxer, int timeout); +void IoMuxerForget(struct IoMuxer* io_muxer, int fd); void IoMuxerDestroy(struct IoMuxer* io_muxer); #ifdef __cplusplus |