From 9febfc1d688f8633dbcf5cb51174a695e183a91a Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Sun, 19 Oct 2008 10:09:57 -0400 Subject: [PATCH] don't get stuck running the event loop once there are no more clients --- luaeventloop/lel_instance.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/luaeventloop/lel_instance.c b/luaeventloop/lel_instance.c index 4d1de05..ae32aab 100644 --- a/luaeventloop/lel_instance.c +++ b/luaeventloop/lel_instance.c @@ -255,7 +255,7 @@ static void kill_exec (lua_State *L, struct lel_eventloop *el, int fd) int l_eventloop_run_loop (lua_State *L) { struct lel_eventloop *el; - int timeout; + int timeout, status; fd_set rfds, xfds; struct timeval tv; @@ -269,8 +269,8 @@ int l_eventloop_run_loop (lua_State *L) tv.tv_usec = 0; // run the loop - for (;;) { - int i, status, rc; + while (el->progs_count) { + int i, rc; // catchup on programs that quit while (waitpid (-1, &status, WNOHANG) > 0); @@ -303,13 +303,16 @@ int l_eventloop_run_loop (lua_State *L) break; } - if (dead || FD_ISSET (prog->fd, &xfds)) { + if (dead /* || FD_ISSET (prog->fd, &xfds) */ ) { DBGF("** killing %d (fd=%d) **\n", prog->pid, prog->fd); kill_exec(L, el, prog->fd); } } } + + // catchup on programs that quit + while (waitpid (-1, &status, WNOHANG) > 0); return 0; } -- 2.11.4.GIT