+static void check_bad_fds(event_loop_t *loop, meshlink_handle_t *mesh) {
+ // Just call all registered callbacks and have them check their fds
+
+ do {
+ loop->deletion = false;
+
+ for splay_each(io_t, io, &loop->ios) {
+ if(io->flags & IO_WRITE) {
+ io->cb(loop, io->data, IO_WRITE);
+ }
+
+ if(loop->deletion) {
+ break;
+ }
+
+ if(io->flags & IO_READ) {
+ io->cb(loop, io->data, IO_READ);
+ }
+
+ if(loop->deletion) {
+ break;
+ }
+ }
+ } while(loop->deletion);
+
+ // Rebuild the fdsets
+
+ fd_set old_readfds;
+ fd_set old_writefds;
+ memcpy(&old_readfds, &loop->readfds, sizeof(old_readfds));
+ memcpy(&old_writefds, &loop->writefds, sizeof(old_writefds));
+
+ memset(&loop->readfds, 0, sizeof(loop->readfds));
+ memset(&loop->writefds, 0, sizeof(loop->writefds));
+
+ for splay_each(io_t, io, &loop->ios) {
+ if(io->flags & IO_READ) {
+ FD_SET(io->fd, &loop->readfds);
+ io->cb(loop, io->data, IO_READ);
+ }
+
+ if(io->flags & IO_WRITE) {
+ FD_SET(io->fd, &loop->writefds);
+ io->cb(loop, io->data, IO_WRITE);
+ }
+ }
+
+ if(memcmp(&old_readfds, &loop->readfds, sizeof(old_readfds))) {
+ logger(mesh, MESHLINK_WARNING, "Incorrect readfds fixed");
+ }
+
+ if(memcmp(&old_writefds, &loop->writefds, sizeof(old_writefds))) {
+ logger(mesh, MESHLINK_WARNING, "Incorrect writefds fixed");
+ }
+}
+
+bool event_loop_run(event_loop_t *loop, meshlink_handle_t *mesh) {
+ assert(mesh);