X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet.c;h=8259a3672ba8a71403045fc3b7b4e3ec6262d4be;hb=0f6f54ff8aa96d981f68b5b71c7126b8fdbead6c;hp=3a44ce66b61d151dd42329e1118a2d5c00c54f43;hpb=17c8033029d50ce4a30b6e3585c0ee28ef45bc97;p=tinc diff --git a/src/net.c b/src/net.c index 3a44ce66..8259a367 100644 --- a/src/net.c +++ b/src/net.c @@ -128,17 +128,9 @@ static int build_fdset(void) connection_del(c); if(!connection_tree->head) purge(); - } else { - short events = EV_READ; - if(c->outbuflen > 0) - events |= EV_WRITE; - event_del(&c->ev); - event_set(&c->ev, c->socket, events, - handle_meta_connection_data, c); - if (event_add(&c->ev, NULL) < 0) - return -1; } } + return 0; } @@ -168,6 +160,8 @@ 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); @@ -274,33 +268,25 @@ void handle_meta_connection_data(int fd, short events, void *data) if (c->status.remove) return; - if (events & EV_READ) { - if(c->status.connecting) { - c->status.connecting = false; - getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); - - if(!result) - finish_connecting(c); - else { - ifdebug(CONNECTIONS) logger(LOG_DEBUG, - _("Error while connecting to %s (%s): %s"), - c->name, c->hostname, strerror(result)); - closesocket(c->socket); - do_outgoing_connection(c); - return; - } - } - - if (!receive_meta(c)) { - terminate_connection(c, c->status.active); + if(c->status.connecting) { + c->status.connecting = false; + getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); + + if(!result) + finish_connecting(c); + else { + ifdebug(CONNECTIONS) logger(LOG_DEBUG, + _("Error while connecting to %s (%s): %s"), + c->name, c->hostname, strerror(result)); + closesocket(c->socket); + do_outgoing_connection(c); return; } } - if (events & EV_WRITE) { - if(!flush_meta(c)) { - terminate_connection(c, c->status.active); - } + if (!receive_meta(c)) { + terminate_connection(c, c->status.active); + return; } }