X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fmeshlink.c;h=66d87ee986cde60a8b3689fb0820b1bbbb7f0f51;hp=0bc947a6acae95e4eebf07a2ae6cfdfab288e35a;hb=56e0dd5ad3936663d398500f80c9a502553659df;hpb=7afe8daaf5ba221968a3e2beff61fa653f497cb1 diff --git a/src/meshlink.c b/src/meshlink.c index 0bc947a6..66d87ee9 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1211,10 +1211,18 @@ void meshlink_stop(meshlink_handle_t *mesh) { event_loop_stop(&mesh->loop); // Send ourselves a UDP packet to kick the event loop - listen_socket_t *s = &mesh->listen_socket[0]; + for(int i = 0; i < mesh->listen_sockets; i++) { + sockaddr_t sa; + socklen_t salen = sizeof(sa.sa); - 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"); + if(getsockname(mesh->listen_socket[i].udp.fd, &sa.sa, &salen) == -1) { + logger(mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "getsockname", sockstrerror(sockerrno)); + continue; + } + + if(sendto(mesh->listen_socket[i].udp.fd, "", 1, MSG_NOSIGNAL, &sa.sa, salen) == -1) { + logger(mesh, MESHLINK_ERROR, "Could not send a UDP packet to ourself: %s", sockstrerror(sockerrno)); + } } // Wait for the main thread to finish