X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnet_socket.c;h=31bc608f1d43fd56f346d9d2736de43c3b79e951;hb=HEAD;hp=8b293d5d548904002fe7e15749bf938fcb478f3f;hpb=53818faa72ac501f593edfc454b35d1fd4bfb318;p=meshlink diff --git a/src/net_socket.c b/src/net_socket.c index 8b293d5d..8b1263b0 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -71,6 +71,11 @@ static void configure_tcp(connection_t *c) { int lowdelay = IPTOS_LOWDELAY; setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&lowdelay, sizeof(lowdelay)); #endif + +#if defined(SO_NOSIGPIPE) + int nosigpipe = 1; + setsockopt(c->socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&nosigpipe, sizeof(nosigpipe)); +#endif } static void retry_outgoing_handler(event_loop_t *loop, void *data) { @@ -82,14 +87,16 @@ static void retry_outgoing_handler(event_loop_t *loop, void *data) { } void retry_outgoing(meshlink_handle_t *mesh, outgoing_t *outgoing) { - if(!mesh->reachable && mesh->loop.now.tv_sec < mesh->last_unreachable + mesh->dev_class_traits[mesh->devclass].fast_retry_period) { + if(!mesh->reachable && mesh->loop.now.tv_sec < mesh->last_unreachable + mesh->dev_class_traits[outgoing->node->devclass].fast_retry_period) { outgoing->timeout = 1; } else { outgoing->timeout += 5; } - if(outgoing->timeout > mesh->maxtimeout) { - outgoing->timeout = mesh->maxtimeout; + int maxtimeout = mesh->dev_class_traits[outgoing->node->devclass].maxtimeout; + + if(outgoing->timeout > maxtimeout) { + outgoing->timeout = maxtimeout; } timeout_add(&mesh->loop, &outgoing->ev, retry_outgoing_handler, outgoing, &(struct timespec) { @@ -129,6 +136,10 @@ static void handle_meta_write(meshlink_handle_t *mesh, connection_t *c) { return; } + if(c->node) { + c->node->out_meta += outlen; + } + buffer_read(&c->outbuf, outlen); if(!c->outbuf.len) { @@ -136,6 +147,10 @@ static void handle_meta_write(meshlink_handle_t *mesh, connection_t *c) { } } +void flush_meta(meshlink_handle_t *mesh, connection_t *c) { + handle_meta_write(mesh, c); +} + static void handle_meta_io(event_loop_t *loop, void *data, int flags) { meshlink_handle_t *mesh = loop->data; connection_t *c = data; @@ -150,7 +165,7 @@ static void handle_meta_io(event_loop_t *loop, void *data, int flags) { if(!result) { finish_connecting(mesh, c); } else { - logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s: %s", c->name, sockstrerror(result)); + logger(mesh, MESHLINK_ERROR, "Error while connecting to %s: %s", c->name, sockstrerror(result)); terminate_connection(mesh, c, false); return; } @@ -283,12 +298,14 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo if(port) { *port++ = 0; port = xstrdup(port); + adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2); + return false; } else { - port = xstrdup(mesh->myport); + logger(mesh, MESHLINK_ERROR, "Canonical address for %s is missing port number", n->name); + free(address); + outgoing->state = OUTGOING_RECENT; } - adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2); - return false; } else { outgoing->state = OUTGOING_RECENT; } @@ -311,7 +328,7 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo outgoing->ai = NULL; outgoing->aip = NULL; - outgoing->state = OUTGOING_RECENT; + outgoing->state = OUTGOING_END; } if(outgoing->state == OUTGOING_RECENT) { @@ -365,6 +382,7 @@ begin: /* We are waiting for a callback from the ADNS thread */ } else if(outgoing->state == OUTGOING_NO_KNOWN_ADDRESSES) { logger(mesh, MESHLINK_ERROR, "No known addresses for %s", outgoing->node->name); + list_delete(mesh->outgoings, outgoing); } else { logger(mesh, MESHLINK_ERROR, "Could not set up a meta connection to %s", outgoing->node->name); retry_outgoing(mesh, outgoing); @@ -511,6 +529,10 @@ void handle_new_meta_connection(event_loop_t *loop, void *data, int flags) { fd = accept(l->tcp.fd, &sa.sa, &len); if(fd < 0) { + if(sockwouldblock(errno)) { + return; + } + if(errno == EINVAL) { // TODO: check if Windows agrees event_loop_stop(loop); return;