summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2022-07-30 11:40:09 +0200
committerMikhail Burakov <mburakov@mailbox.org>2022-07-30 11:40:09 +0200
commitcc9e94c1bc73891dbdad37fcdfa8b6b21b5a2bb6 (patch)
treecf73eb98a253597eceed6f9ce4bdce93ebe7a9b7
parentf5d91c44031aac643ea68903f7b50b126fd0c7b2 (diff)
Only return from muxer on error or timeout
-rw-r--r--io_muxer.c17
-rw-r--r--io_muxer.h2
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