From c5334a46523b9ac959c002fbc23a25eeccf63599 Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Sun, 9 Apr 2023 14:13:37 +0200 Subject: Add fd forgetting function to io muxer --- io_muxer.c | 8 +++++++- io_muxer.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/io_muxer.c b/io_muxer.c index 4c4c0e2..e56cb0b 100644 --- a/io_muxer.c +++ b/io_muxer.c @@ -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); diff --git a/io_muxer.h b/io_muxer.h index ae6b88f..de03788 100644 --- a/io_muxer.h +++ b/io_muxer.h @@ -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 -- cgit v1.2.3