#include "dropin.h"
#include "event.h"
+#include "logger.h"
+#include "meshlink.h"
#include "net.h"
#include "splay_tree.h"
#include "utils.h"
loop->idle_data = data;
}
-static void check_bad_fds(event_loop_t *loop) {
+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 {
// 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));
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, pthread_mutex_t *mutex) {
- assert(mutex);
+bool event_loop_run(event_loop_t *loop, meshlink_handle_t *mesh) {
+ assert(mesh);
fd_set readable;
fd_set writable;
}
// release mesh mutex during select
- pthread_mutex_unlock(mutex);
+ pthread_mutex_unlock(&mesh->mutex);
#ifdef HAVE_PSELECT
int n = pselect(fds, &readable, &writable, NULL, &ts, NULL);
int n = select(fds, &readable, &writable, NULL, (struct timeval *)&tv);
#endif
- if(pthread_mutex_lock(mutex) != 0) {
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
abort();
}
errors++;
if(errors > 10) {
+ logger(mesh, MESHLINK_ERROR, "Unrecoverable error from select(): %s", strerror(errno));
return false;
}
- check_bad_fds(loop);
+ logger(mesh, MESHLINK_WARNING, "Error from select(), checking for bad fds: %s", strerror(errno));
+ check_bad_fds(loop, mesh);
continue;
}
}
#define IO_WRITE 2
typedef struct event_loop_t event_loop_t;
+struct meshlink_handle;
typedef void (*io_cb_t)(event_loop_t *loop, void *data, int flags);
typedef void (*timeout_cb_t)(event_loop_t *loop, void *data);
void event_loop_init(event_loop_t *loop);
void event_loop_exit(event_loop_t *loop);
-bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) __attribute__((__warn_unused_result__));
+bool event_loop_run(event_loop_t *loop, struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
void event_loop_flush_output(event_loop_t *loop);
void event_loop_start(event_loop_t *loop);
void event_loop_stop(event_loop_t *loop);
mesh->datafromapp.signum = 0;
signal_add(&mesh->loop, &mesh->datafromapp, meshlink_send_from_queue, mesh, mesh->datafromapp.signum);
- if(!event_loop_run(&mesh->loop, &mesh->mutex)) {
+ if(!event_loop_run(&mesh->loop, mesh)) {
logger(mesh, MESHLINK_ERROR, "Error while waiting for input: %s", strerror(errno));
call_error_cb(mesh, MESHLINK_ENETWORK);
}