]> git.meshlink.io Git - meshlink/commitdiff
Close meta-connections in meshlink_stop().
authorGuus Sliepen <guus@meshlink.io>
Mon, 14 Aug 2017 19:22:43 +0000 (21:22 +0200)
committerGuus Sliepen <guus@meshlink.io>
Mon, 14 Aug 2017 19:22:43 +0000 (21:22 +0200)
If we stop MeshLink for an extended time, we don't want to have open
sockets lying around that we don't take care of. Terminate all of them.

src/meshlink.c

index 35b00482b08c6fedbf176aafb4ca77de305de8c4..6e03e63bbe7e1b3848ccb8678c2a8b9fd4207d22 100644 (file)
@@ -1044,6 +1044,20 @@ void meshlink_stop(meshlink_handle_t *mesh) {
 
        mesh->threadstarted = false;
 
+       // Close all metaconnections
+       if(mesh->connections) {
+               for(list_node_t *node = mesh->connections->head, *next; node; node = next) {
+                       next = node->next;
+                       connection_t *c = node->data;
+                       c->outgoing = NULL;
+                       terminate_connection(mesh, c, false);
+               }
+       }
+
+       if(mesh->outgoings)
+               list_delete_list(mesh->outgoings);
+       mesh->outgoings = NULL;
+
        pthread_mutex_unlock(&(mesh->mesh_mutex));
 }