summaryrefslogtreecommitdiff
path: root/sysdep/unix/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/unix/io.c')
-rw-r--r--sysdep/unix/io.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 29467867..40841ea4 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -2176,6 +2176,15 @@ static int short_loops = 0;
#define SHORT_LOOP_MAX 10
#define WORK_EVENTS_MAX 10
+static int poll_reload_pipe[2];
+
+void
+io_loop_reload(void)
+{
+ char b;
+ write(poll_reload_pipe[1], &b, 1);
+}
+
void
io_loop(void)
{
@@ -2187,6 +2196,9 @@ io_loop(void)
int fdmax = 256;
struct pollfd *pfd = xmalloc(fdmax * sizeof(struct pollfd));
+ if (pipe(poll_reload_pipe) < 0)
+ die("pipe(poll_reload_pipe) failed: %m");
+
watchdog_start1();
for(;;)
{
@@ -2205,7 +2217,12 @@ io_loop(void)
poll_tout = MIN(poll_tout, timeout);
}
- nfds = 0;
+ /* A hack to reload main io_loop() when something has changed asynchronously. */
+ pfd[0].fd = poll_reload_pipe[0];
+ pfd[0].events = POLLIN;
+
+ nfds = 1;
+
WALK_LIST(n, sock_list)
{
pfd[nfds] = (struct pollfd) { .fd = -1 }; /* everything other set to 0 by this */
@@ -2277,6 +2294,14 @@ io_loop(void)
}
if (pout)
{
+ if (pfd[0].revents & POLLIN)
+ {
+ /* IO loop reload requested */
+ char b;
+ read(poll_reload_pipe[0], &b, 1);
+ continue;
+ }
+
times_update(&main_timeloop);
/* guaranteed to be non-empty */