From 9e4d3c4a7b248c1e07b50108c0d99dd510178ee8 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Sun, 1 Jun 2014 16:20:33 +0200 Subject: [PATCH] Dirty draft: use signal trigger to notify event loop about incoming data from the application --- src/meshlink.c | 2 +- src/meshlink.h | 7 +++++++ src/meshlink_internal.h | 1 + src/net.c | 4 ++++ src/net.h | 5 ----- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index eac80c27..122afa58 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -859,7 +859,7 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const pthread_mutex_unlock(&(mesh->outpacketqueue_mutex)); //notify event loop - + signal_trigger(&(mesh->loop),&(mesh->datafromapp)); } bool meshlink_send_from_queue (meshlink_handle_t *mesh,outpacketqueue_t* p) { diff --git a/src/meshlink.h b/src/meshlink.h index 36c784c9..342657db 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -39,6 +39,11 @@ typedef enum { MESHLINK_ENOMEM, // Out of memory MESHLINK_ENOENT, // Node is not known } meshlink_errno_t; +typedef struct outpacketqueue { + meshlink_node_t *destination; + const void *data; + unsigned int len; +} outpacketqueue_t; #ifndef MESHLINK_INTERNAL_H @@ -191,6 +196,8 @@ extern void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t le */ extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, unsigned int len); +extern bool meshlink_send_from_queue (meshlink_handle_t *mesh,outpacketqueue_t* p); + /// Get a handle for a specific node. /** This function returns a handle for the node with the given name. * diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index c75311bb..c58c4773 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -64,6 +64,7 @@ struct meshlink_handle { event_loop_t loop; listen_socket_t listen_socket[MAXSOCKETS]; int listen_sockets; + signal_t datafromapp; struct node_t *self; diff --git a/src/net.c b/src/net.c index deac6eee..15a4831f 100644 --- a/src/net.c +++ b/src/net.c @@ -269,6 +269,10 @@ int main_loop(meshlink_handle_t *mesh) { timeout_add(&mesh->loop, &mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval){mesh->pingtimeout, rand() % 100000}); timeout_add(&mesh->loop, &mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timeval){mesh->pingtimeout, rand() % 100000}); + //Add signal handler + //mesh->datafromapp = {0}; + signal_add(&(mesh->loop),&(mesh->datafromapp), meshlink_send_from_queue,NULL, SIGTERM); + if(!event_loop_run(&mesh->loop)) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno)); return 1; diff --git a/src/net.h b/src/net.h index 27ea3d14..55c046ef 100644 --- a/src/net.h +++ b/src/net.h @@ -68,11 +68,6 @@ typedef struct outgoing_t { timeout_t ev; } outgoing_t; -typedef struct outpacketqueue { - meshlink_node_t *destination; - const void *data; - unsigned int len; -} outpacketqueue_t; extern int maxoutbufsize; extern int addressfamily; -- 2.39.5