]> git.meshlink.io Git - meshlink/blobdiff - src/net_socket.c
Never automatically try to bind to ports >= 32768.
[meshlink] / src / net_socket.c
index 7ac6dbbdbe023b06033e5e76956b964ff2cdc9b6..8b1263b063fb8df8c5900e68a09361921ac5e636 100644 (file)
@@ -136,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) {
@@ -143,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;
@@ -157,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;
                }
@@ -320,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) {
@@ -374,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);
@@ -520,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;