]> git.meshlink.io Git - meshlink/commitdiff
Send a UDP packet to ourself instead of doing a dummy connect().
authorGuus Sliepen <guus@meshlink.io>
Sat, 7 Nov 2015 22:48:37 +0000 (22:48 +0000)
committerGuus Sliepen <guus@meshlink.io>
Sun, 25 Jun 2017 08:45:35 +0000 (10:45 +0200)
This is simpler, hopefully with less chance of failing.

src/meshlink.c

index 412976644cdb5d702647b406ab083d920ce3162b..1c763d6a668e632a70650d648e259c9aedb66d88 100644 (file)
@@ -999,11 +999,10 @@ void meshlink_stop(meshlink_handle_t *mesh) {
        // Shut down the main thread
        event_loop_stop(&mesh->loop);
 
-       // Fake a connection to kick the event loop
+       // Send ourselves a UDP packet to kick the event loop
        listen_socket_t *s = &mesh->listen_socket[0];
-       int fd = socket(s->sa.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
-       connect(fd, &s->sa.sa, SALEN(s->sa.sa));
-       close(fd);
+       if(sendto(s->udp.fd, "", 1, MSG_NOSIGNAL, &s->sa.sa, SALEN(s->sa.sa)) == -1)
+               logger(mesh, MESHLINK_ERROR, "Could not send a UDP packet to ourself");
 
        // Wait for the main thread to finish
        pthread_mutex_unlock(&(mesh->mesh_mutex));