From: Guus Sliepen Date: Sat, 15 Jan 2011 21:21:31 +0000 (+0100) Subject: Call connect() from the metadata handler thread. X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=2d4203fefa52a41f7987b1ace254da77df6e2dbf;p=tinc Call connect() from the metadata handler thread. --- diff --git a/src/net.c b/src/net.c index e52363e4..d80a7129 100644 --- a/src/net.c +++ b/src/net.c @@ -216,13 +216,12 @@ void handle_meta_connection_data(void *data) { int result; socklen_t len = sizeof result; - if(c->status.connecting) { - c->status.connecting = false; - - getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); + while(c->status.connecting) { + result = connect(c->socket, &c->address.sa, SALEN(c->address.sa)); if(!result) { mutex_lock(&mutex); + c->status.connecting = false; finish_connecting(c); mutex_unlock(&mutex); } else { @@ -230,10 +229,10 @@ void handle_meta_connection_data(void *data) { "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(result)); closesocket(c->socket); + c->status.connecting = false; mutex_lock(&mutex); do_outgoing_connection(c); mutex_unlock(&mutex); - return; } } diff --git a/src/net_socket.c b/src/net_socket.c index 3c79ceea..d12810fc 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -392,25 +392,7 @@ begin: configure_tcp(c); - /* Connect */ - - result = connect(c->socket, &c->address.sa, SALEN(c->address.sa)); - - if(result == -1) { - if(sockinprogress(sockerrno)) { - c->status.connecting = true; - return; - } - - closesocket(c->socket); - - ifdebug(CONNECTIONS) logger(LOG_ERR, "%s: %s", c->hostname, sockstrerror(sockerrno)); - - goto begin; - } - - finish_connecting(c); - + c->status.connecting = true; return; }