X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=f24d18ad81db06d713b329a95180741b2d33c0fa;hp=7f1f77b38b192ea2e14db8b1a5afe300a6333371;hb=b1945f70fe993ca447555a1e27f35638b0c1fd8b;hpb=4c85542894f7fca823b119b05e07179deb24229a diff --git a/src/net.c b/src/net.c index 7f1f77b3..f24d18ad 100644 --- a/src/net.c +++ b/src/net.c @@ -2,6 +2,7 @@ net.c -- most of the network code Copyright (C) 1998-2005 Ivo Timmermans, 2000-2009 Guus Sliepen + 2006 Scott Lamb This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -302,7 +303,7 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) { else { ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Error while connecting to %s (%s): %s", - c->name, c->hostname, strerror(result)); + c->name, c->hostname, sockstrerror(result)); closesocket(c->socket); do_outgoing_connection(c); continue; @@ -368,17 +369,15 @@ int main_loop(void) { #endif if(r < 0) { - if(errno != EINTR && errno != EAGAIN) { - logger(LOG_ERR, "Error while waiting for input: %s", - strerror(errno)); + if(!sockwouldblock(sockerrno)) { + logger(LOG_ERR, "Error while waiting for input: %s", sockstrerror(sockerrno)); dump_connections(); return 1; } - - continue; } - check_network_activity(&readset, &writeset); + if(r > 0) + check_network_activity(&readset, &writeset); if(do_purge) { purge(); @@ -418,8 +417,13 @@ int main_loop(void) { } if(sigalrm) { + avl_node_t *node; logger(LOG_INFO, "Flushing event queue"); expire_events(); + for(node = connection_tree->head; node; node = node->next) { + connection_t *c = node->data; + send_ping(c); + } sigalrm = false; } @@ -430,7 +434,7 @@ int main_loop(void) { if(sighup) { connection_t *c; - avl_node_t *node; + avl_node_t *node, *next; char *fname; struct stat s; @@ -446,6 +450,31 @@ int main_loop(void) { return 1; } + /* Cancel non-active outgoing connections */ + + for(node = connection_tree->head; node; node = next) { + next = node->next; + c = node->data; + + c->outgoing = NULL; + + if(c->status.connecting) { + terminate_connection(c, false); + connection_del(c); + } + } + + /* Wipe list of outgoing connections */ + + for(list_node_t *node = outgoing_list->head; node; node = node->next) { + outgoing_t *outgoing = node->data; + + if(outgoing->event) + event_del(outgoing->event); + } + + list_delete_list(outgoing_list); + /* Close connections to hosts that have a changed or deleted host config file */ for(node = connection_tree->head; node; node = node->next) {