]> git.meshlink.io Git - meshlink/blobdiff - src/net_socket.c
Ensure the maxtimeout value is taken from the destination node's device class.
[meshlink] / src / net_socket.c
index 8b293d5d548904002fe7e15749bf938fcb478f3f..a692313958850a0f1b87db3bb313930684cb59b9 100644 (file)
@@ -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) {
@@ -88,8 +93,10 @@ void retry_outgoing(meshlink_handle_t *mesh, outgoing_t *outgoing) {
                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) {
@@ -283,12 +290,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;
                }