X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=392aa7acbe79084e32210c4e37485906b00854f2;hp=327bdd307a7c551f50151cd10da41517e52352ea;hb=f6543e4da4a4f313ded43b84d572f21acacfcee7;hpb=c373de2e9812700c0568640727ad917b6fc7d758 diff --git a/src/net.c b/src/net.c index 327bdd30..392aa7ac 100644 --- a/src/net.c +++ b/src/net.c @@ -40,6 +40,7 @@ #include "route.h" #include "subnet.h" #include "xalloc.h" +#include "resolv.h" bool do_purge = false; volatile bool running = false; @@ -134,7 +135,7 @@ static int build_fdset(fd_set *readset, fd_set *writeset) { purge(); } else { FD_SET(c->socket, readset); - if(c->outbuflen > 0) + if(c->outbuflen > 0 || c->status.connecting) FD_SET(c->socket, writeset); if(c->socket > max) max = c->socket; @@ -212,6 +213,12 @@ void terminate_connection(connection_t *c, bool report) { c->status.remove = false; do_outgoing_connection(c); } + +#ifndef HAVE_MINGW + /* Clean up dead proxy processes */ + + while(waitpid(-1, NULL, WNOHANG) > 0); +#endif } /* @@ -234,7 +241,7 @@ static void check_dead_connections(void) { if(c->status.active) { if(c->status.pinged) { ifdebug(CONNECTIONS) logger(LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", - c->name, c->hostname, now - c->last_ping_time); + c->name, c->hostname, (long)now - c->last_ping_time); c->status.timeout = true; terminate_connection(c, true); } else if(c->last_ping_time + pinginterval <= now) { @@ -263,7 +270,7 @@ static void check_dead_connections(void) { if(c->status.active) { ifdebug(CONNECTIONS) logger(LOG_INFO, "%s (%s) could not flush for %ld seconds (%d bytes remaining)", - c->name, c->hostname, now - c->last_flushed_time, c->outbuflen); + c->name, c->hostname, (long)now - c->last_flushed_time, c->outbuflen); c->status.timeout = true; terminate_connection(c, true); } @@ -308,7 +315,7 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) { if(c->status.remove) continue; - if(FD_ISSET(c->socket, readset)) { + if(FD_ISSET(c->socket, writeset)) { if(c->status.connecting) { c->status.connecting = false; getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&result, &len); @@ -325,14 +332,14 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) { } } - if(!receive_meta(c)) { + if(!flush_meta(c)) { terminate_connection(c, c->status.active); continue; } } - if(FD_ISSET(c->socket, writeset)) { - if(!flush_meta(c)) { + if(FD_ISSET(c->socket, readset)) { + if(!receive_meta(c)) { terminate_connection(c, c->status.active); continue; } @@ -488,9 +495,11 @@ int main_loop(void) { avl_node_t *node; logger(LOG_INFO, "Flushing event queue"); expire_events(); + res_init(); for(node = connection_tree->head; node; node = node->next) { connection_t *c = node->data; - send_ping(c); + if(c->status.active) + send_ping(c); } sigalrm = false; }