From ef2f0d4510168a77a6da16822b9401d1f14b69e0 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Tue, 3 Jun 2014 16:42:58 +0200 Subject: [PATCH] only allow meshlink_join() when the library thread is not running --- src/meshlink.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/meshlink.c b/src/meshlink.c index 511a6d15..9a53d67a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1171,6 +1171,12 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { char *b64key = ecdsa_get_base64_public_key(key); + //Before doing meshlink_join make sure we are not connected to another mesh + if ( pthread_kill(mesh->thread,0) == 0){ + printf("HELLO\n"); + goto invalid; + } + // Connect to the meshlink daemon mentioned in the URL. struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM); if(!ai) @@ -1261,7 +1267,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { return true; invalid: - fprintf(stderr, "Invalid invitation URL.\n"); + fprintf(stderr, "Invalid invitation URL or you are already connected to a Mesh ?\n"); return false; } -- 2.39.2