From daee99be3e42946e3b554150c32d310836b37da6 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 21 Apr 2014 21:05:36 +0200 Subject: [PATCH] Move outgoing_list to mesh->outgoings. --- src/meshlink_internal.h | 2 +- src/net.c | 12 ++++++------ src/net.h | 2 -- src/net_setup.c | 4 ++-- src/net_socket.c | 15 +++++++-------- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index fc40f301..04db92fc 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -44,7 +44,7 @@ struct meshlink_handle { struct splay_tree_t *nodes; struct list_t *connections; - struct list_t *outgoing_connections; + struct list_t *outgoings; }; /// A handle for a MeshLink node. diff --git a/src/net.c b/src/net.c index 74fb04b6..98cc8bed 100644 --- a/src/net.c +++ b/src/net.c @@ -206,7 +206,7 @@ static void periodic_handler(void *data) { bool found = false; - for list_each(outgoing_t, outgoing, outgoing_list) { + for list_each(outgoing_t, outgoing, mesh->outgoings) { if(!strcmp(outgoing->name, n->name)) { found = true; break; @@ -217,7 +217,7 @@ static void periodic_handler(void *data) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); outgoing_t *outgoing = xzalloc(sizeof *outgoing); outgoing->name = xstrdup(n->name); - list_insert_tail(outgoing_list, outgoing); + list_insert_tail(mesh->outgoings, outgoing); setup_outgoing_connection(outgoing); } break; @@ -241,7 +241,7 @@ static void periodic_handler(void *data) { break; logger(DEBUG_CONNECTIONS, LOG_INFO, "Autodisconnecting from %s", c->name); - list_delete(outgoing_list, c->outgoing); + list_delete(mesh->outgoings, c->outgoing); c->outgoing = NULL; terminate_connection(c, c->status.active); break; @@ -252,7 +252,7 @@ static void periodic_handler(void *data) { /* If we have enough active connections, remove any pending outgoing connections. */ - for list_each(outgoing_t, o, outgoing_list) { + for list_each(outgoing_t, o, mesh->outgoings) { bool found = false; for list_each(connection_t, c, mesh->connections) { if(c->outgoing == o) { @@ -262,7 +262,7 @@ static void periodic_handler(void *data) { } if(!found) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->name); - list_delete_node(outgoing_list, node); + list_delete_node(mesh->outgoings, node); } } } @@ -322,7 +322,7 @@ int reload_configuration(void) { void retry(void) { /* Reset the reconnection timers for all outgoing connections */ - for list_each(outgoing_t, outgoing, outgoing_list) { + for list_each(outgoing_t, outgoing, mesh->outgoings) { outgoing->timeout = 0; if(outgoing->ev.cb) timeout_set(&outgoing->ev, &(struct timeval){0, 0}); diff --git a/src/net.h b/src/net.h index dab40cbb..706f5690 100644 --- a/src/net.h +++ b/src/net.h @@ -79,8 +79,6 @@ typedef struct outgoing_t { timeout_t ev; } outgoing_t; -extern list_t *outgoing_list; - extern int maxoutbufsize; extern int seconds_till_retry; extern int addressfamily; diff --git a/src/net_setup.c b/src/net_setup.c index 62b12b55..1d2d4721 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -416,8 +416,8 @@ void close_network_connections(void) { terminate_connection(c, false); } - if(outgoing_list) - list_delete_list(outgoing_list); + if(mesh->outgoings) + list_delete_list(mesh->outgoings); if(mesh->self && mesh->self->connection) { terminate_connection(mesh->self->connection, false); diff --git a/src/net_socket.c b/src/net_socket.c index 1521208f..ecf2c26b 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -43,7 +43,6 @@ int max_connection_burst = 100; listen_socket_t listen_socket[MAXSOCKETS]; int listen_sockets; -list_t *outgoing_list = NULL; /* Setup sockets */ @@ -645,10 +644,10 @@ static void free_outgoing(outgoing_t *outgoing) { void try_outgoing_connections(void) { /* If there is no outgoing list yet, create one. Otherwise, mark all outgoings as deleted. */ - if(!outgoing_list) { - outgoing_list = list_alloc((list_action_t)free_outgoing); + if(!mesh->outgoings) { + mesh->outgoings = list_alloc((list_action_t)free_outgoing); } else { - for list_each(outgoing_t, outgoing, outgoing_list) + for list_each(outgoing_t, outgoing, mesh->outgoings) outgoing->timeout = -1; } @@ -669,7 +668,7 @@ void try_outgoing_connections(void) { bool found = false; - for list_each(outgoing_t, outgoing, outgoing_list) { + for list_each(outgoing_t, outgoing, mesh->outgoings) { if(!strcmp(outgoing->name, name)) { found = true; outgoing->timeout = 0; @@ -680,7 +679,7 @@ void try_outgoing_connections(void) { if(!found) { outgoing_t *outgoing = xzalloc(sizeof *outgoing); outgoing->name = name; - list_insert_tail(outgoing_list, outgoing); + list_insert_tail(mesh->outgoings, outgoing); setup_outgoing_connection(outgoing); } } @@ -697,7 +696,7 @@ void try_outgoing_connections(void) { /* Delete outgoing_ts for which there is no ConnectTo. */ - for list_each(outgoing_t, outgoing, outgoing_list) + for list_each(outgoing_t, outgoing, mesh->outgoings) if(outgoing->timeout == -1) - list_delete_node(outgoing_list, node); + list_delete_node(mesh->outgoings, node); } -- 2.39.5