X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=1b5bb16693f1e700da422451b1f47017afe2ad5a;hb=67d9a72ea2f10f1a2d2eb7c04a41183359d5e1cc;hp=d78770e12c7da38c38339eba8d88d92a714bed96;hpb=ce976717ea9756aa985699547fdbf132b694748d;p=tinc diff --git a/src/net.c b/src/net.c index d78770e1..1b5bb166 100644 --- a/src/net.c +++ b/src/net.c @@ -121,8 +121,6 @@ void terminate_connection(connection_t *c, bool report) { if(c->socket) closesocket(c->socket); - event_del(&c->ev); - if(c->edge) { if(report && !tunnelserver) send_del_edge(broadcast, c->edge); @@ -146,20 +144,12 @@ void terminate_connection(connection_t *c, bool report) { } } - free(c->outbuf); - c->outbuf = NULL; - c->outbuflen = 0; - c->outbufsize = 0; - c->outbufstart = 0; - /* Check if this was our outgoing connection */ - if(c->outgoing) { + if(c->outgoing) retry_outgoing(c->outgoing); - c->outgoing = NULL; - } else { - connection_del(c); - } + + connection_del(c); } /* @@ -186,20 +176,20 @@ static void timeout_handler(int fd, short events, void *event) { 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->status.timeout = true; terminate_connection(c, true); continue; } else if(c->last_ping_time + pinginterval < now) { send_ping(c); } } else { - ifdebug(CONNECTIONS) logger(LOG_WARNING, _("Timeout from %s (%s) during authentication"), - c->name, c->hostname); if(c->status.connecting) { + ifdebug(CONNECTIONS) + logger(LOG_WARNING, _("Timeout while connecting to %s (%s)"), c->name, c->hostname); c->status.connecting = false; closesocket(c->socket); do_outgoing_connection(c); } else { + ifdebug(CONNECTIONS) logger(LOG_WARNING, _("Timeout from %s (%s) during authentication"), c->name, c->hostname); terminate_connection(c, false); continue; } @@ -216,6 +206,8 @@ void handle_meta_connection_data(int fd, short events, void *data) { socklen_t len = sizeof(result); if(c->status.connecting) { + c->status.connecting = false; + getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); if(!result) @@ -224,7 +216,6 @@ void handle_meta_connection_data(int fd, short events, void *data) { ifdebug(CONNECTIONS) logger(LOG_DEBUG, _("Error while connecting to %s (%s): %s"), c->name, c->hostname, strerror(result)); - c->status.connecting = false; closesocket(c->socket); do_outgoing_connection(c); return;