From cc9e94c1bc73891dbdad37fcdfa8b6b21b5a2bb6 Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Sat, 30 Jul 2022 11:40:09 +0200 Subject: Only return from muxer on error or timeout --- io_muxer.c | 17 +++++++++-------- io_muxer.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/io_muxer.c b/io_muxer.c index 31ebc53..3e6514e 100644 --- a/io_muxer.c +++ b/io_muxer.c @@ -84,15 +84,16 @@ int IoMuxer_OnWrite(struct IoMuxer* io_muxer, int fd, return 0; } -int IoMuxer_Iterate(struct IoMuxer* io_muxer) { - CompressRecords(io_muxer); - int result = poll(io_muxer->pfds, io_muxer->size, -1); - if (result <= 0) return -1; - for (size_t i = 0; i < io_muxer->size; i++) { - if (io_muxer->pfds[i].revents) - io_muxer->closures[i].callback(io_muxer->closures[i].user); +int IoMuxer_Iterate(struct IoMuxer* io_muxer, int timeout) { + for (;;) { + CompressRecords(io_muxer); + int result = poll(io_muxer->pfds, io_muxer->size, timeout); + if (result <= 0) return result; + for (size_t i = 0; i < io_muxer->size; i++) { + if (io_muxer->pfds[i].revents) + io_muxer->closures[i].callback(io_muxer->closures[i].user); + } } - return 0; } void IoMuxer_Destroy(struct IoMuxer* io_muxer) { diff --git a/io_muxer.h b/io_muxer.h index 75fa832..1a1c75d 100644 --- a/io_muxer.h +++ b/io_muxer.h @@ -39,7 +39,7 @@ int IoMuxer_OnRead(struct IoMuxer* io_muxer, int fd, void (*read_callback)(void*), void* user); int IoMuxer_OnWrite(struct IoMuxer* io_muxer, int fd, void (*write_callback)(void*), void* user); -int IoMuxer_Iterate(struct IoMuxer* io_muxer); +int IoMuxer_Iterate(struct IoMuxer* io_muxer, int timeout); void IoMuxer_Destroy(struct IoMuxer* io_muxer); #ifdef __cplusplus -- cgit v1.2.3