X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fevent.c;h=59b96e37dc3f7d3c7fa80ed96d27be1326a915c9;hp=f34974206b1dac9c140105f4b67230749c5a036b;hb=706d855e507980de3845556989d7de7a3b9c76e8;hpb=313a752cb5fbf27450d34c15b0085d2d8a4147af diff --git a/src/event.c b/src/event.c index f3497420..59b96e37 100644 --- a/src/event.c +++ b/src/event.c @@ -91,8 +91,8 @@ void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags) { #ifdef HAVE_MINGW void io_add_event(io_t *io, io_cb_t cb, void *data, WSAEVENT event) { - io_add(io, cb, data, -1, 0); io->event = event; + io_add(io, cb, data, -1, 0); } #endif @@ -256,10 +256,10 @@ bool event_loop(void) { fd_set writable; while(running) { - memcpy(&readable, &readfds, sizeof readable); - memcpy(&writable, &writefds, sizeof writable); struct timeval diff; struct timeval *tv = get_time_remaining(&diff); + memcpy(&readable, &readfds, sizeof readable); + memcpy(&writable, &writefds, sizeof writable); int fds = 0; @@ -285,6 +285,16 @@ bool event_loop(void) { io->cb(io->data, IO_WRITE); else if(FD_ISSET(io->fd, &readable)) io->cb(io->data, IO_READ); + else + continue; + + /* + There are scenarios in which the callback will remove another io_t from the tree + (e.g. closing a double connection). Since splay_each does not support that, we + need to exit the loop now. That's okay, since any remaining events will get picked + up by the next select() call. + */ + break; } } #else