From 3d422139648b99fa100f3ff0628b97c0c629a665 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 7 Nov 2015 22:48:37 +0000 Subject: [PATCH] Send a UDP packet to ourself instead of doing a dummy connect(). This is simpler, hopefully with less chance of failing. --- src/meshlink.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 41297664..1c763d6a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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)); -- 2.39.5