Call connect() from the metadata handler thread.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 15 Jan 2011 21:21:31 +0000 (22:21 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 15 Jan 2011 21:21:31 +0000 (22:21 +0100)
src/net.c
src/net_socket.c

index e52363e..d80a712 100644 (file)
--- 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;
                }
        }
 
index 3c79cee..d12810f 100644 (file)
@@ -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;
 }