X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_socket.c;h=80f37a455d53abfcd9efa77b0e73adafeedba2ff;hb=af2e0c9a32642065aedd2e67ca1f5791ca7a407d;hp=40120962312de31420813f864ad5352e768e2fcf;hpb=d772289f6d6adfb8932658b533349d43f08ec326;p=tinc diff --git a/src/net_socket.c b/src/net_socket.c index 40120962..80f37a45 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -137,9 +137,9 @@ static bool bind_to_address(connection_t *c) { status = getaddrinfo(node, /* service = */ NULL, &ai_hints, &ai_list); if(status) { - free(node); logger(LOG_WARNING, "Error looking up %s port %s: %s", node, "any", gai_strerror(status)); + free(node); return false; } assert(ai_list != NULL); @@ -350,7 +350,7 @@ void finish_connecting(connection_t *c) { send_id(c); } -void do_outgoing_connection(connection_t *c) { +bool do_outgoing_connection(connection_t *c) { char *address, *port, *space; int result; @@ -367,7 +367,7 @@ begin: retry_outgoing(c->outgoing); c->outgoing = NULL; connection_del(c); - return; + return false; } get_config_string(c->outgoing->cfg, &address); @@ -434,7 +434,7 @@ begin: if(result == -1) { if(sockinprogress(sockerrno)) { c->status.connecting = true; - return; + return true; } closesocket(c->socket); @@ -446,7 +446,7 @@ begin: finish_connecting(c); - return; + return true; } static void handle_meta_write(int sock, short events, void *data) { @@ -466,12 +466,6 @@ static void handle_meta_write(int sock, short events, void *data) { event_del(&c->outevent); } -static void handle_meta_connection_error(struct bufferevent *event, short what, void *data) { - connection_t *c = data; - logger(LOG_ERR, "handle_meta_connection_error() called: %d: %s", what, strerror(errno)); - terminate_connection(c, c->status.active); -} - void setup_outgoing_connection(outgoing_t *outgoing) { connection_t *c; node_t *n; @@ -512,11 +506,11 @@ void setup_outgoing_connection(outgoing_t *outgoing) { connection_add(c); - do_outgoing_connection(c); - - event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c); - event_set(&c->outevent, c->socket, EV_WRITE | EV_PERSIST, handle_meta_write, c); - event_add(&c->inevent, NULL); + if (do_outgoing_connection(c)) { + event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c); + event_set(&c->outevent, c->socket, EV_WRITE | EV_PERSIST, handle_meta_write, c); + event_add(&c->inevent, NULL); + } } /*