]> git.meshlink.io Git - meshlink/blobdiff - src/net_socket.c
Merge branch 'discovery' into everbase
[meshlink] / src / net_socket.c
index 2ddf837b0a357589df87b280ccb9c512dfa6880b..a99849a76e8a5513629b9c5395454129b863411d 100644 (file)
@@ -58,13 +58,13 @@ static void configure_tcp(connection_t *c) {
 #endif
 
 #if defined(SOL_TCP) && defined(TCP_NODELAY)
-       option = 1;
-       setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&option, sizeof option);
+       int nodelay = 1;
+       setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&nodelay, sizeof nodelay);
 #endif
 
 #if defined(SOL_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
-       option = IPTOS_LOWDELAY;
-       setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&option, sizeof option);
+       int lowdelay = IPTOS_LOWDELAY;
+       setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&lowdelay, sizeof lowdelay);
 #endif
 }
 
@@ -305,7 +305,7 @@ static void handle_meta_write(meshlink_handle_t *mesh, connection_t *c) {
        if(c->outbuf.len <= c->outbuf.offset)
                return;
 
-       ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, 0);
+       ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, MSG_NOSIGNAL);
        if(outlen <= 0) {
                if(!errno || errno == EPIPE) {
                        logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection closed by %s (%s)", c->name, c->hostname);
@@ -372,8 +372,11 @@ begin:
                        *space = 0;
                } else {
                        // TODO: Only allow Address statements?
-                       if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port))
-                               port = xstrdup("655");
+                       if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port)) {
+                               logger(DEBUG_CONNECTIONS, LOG_ERR, "No Port known for %s", outgoing->name);
+                               retry_outgoing(mesh, outgoing);
+                               return false;
+                       }
                }
 
                outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
@@ -632,7 +635,9 @@ void handle_new_meta_connection(event_loop_t *loop, void *data, int flags) {
        send_id(mesh, c);
 }
 
-static void free_outgoing(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+static void free_outgoing(outgoing_t *outgoing) {
+       meshlink_handle_t *mesh = outgoing->mesh;
+
        timeout_del(&mesh->loop, &outgoing->ev);
 
        if(outgoing->ai)
@@ -684,6 +689,7 @@ void try_outgoing_connections(meshlink_handle_t *mesh) {
 
                if(!found) {
                        outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+                       outgoing->mesh = mesh;
                        outgoing->name = name;
                        list_insert_tail(mesh->outgoings, outgoing);
                        setup_outgoing_connection(mesh, outgoing);