From: Guus Sliepen Date: Thu, 6 Jul 2017 20:08:37 +0000 (+0200) Subject: Restart the mesh after a failed join() in the other examples as well. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=fc484c9dde648cad4c95af9763db674ab4be668f Restart the mesh after a failed join() in the other examples as well. --- diff --git a/examples/chat.c b/examples/chat.c index c6d67fb5..37e06734 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -65,12 +65,11 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { meshlink_stop(mesh); if(!meshlink_join(mesh, arg)) fprintf(stderr, "Could not join using invitation: %s\n", meshlink_strerror(meshlink_errno)); - else { + else fprintf(stderr, "Invitation accepted!\n"); - if(!meshlink_start(mesh)) { - fprintf(stderr, "Could not start MeshLink: %s\n", meshlink_strerror(meshlink_errno)); - return; - } + if(!meshlink_start(mesh)) { + fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink_strerror(meshlink_errno)); + exit(1); } } else if(!strcasecmp(buf, "kick")) { if(!arg) { diff --git a/examples/chatpp.cc b/examples/chatpp.cc index 33a1cac5..97f87406 100644 --- a/examples/chatpp.cc +++ b/examples/chatpp.cc @@ -61,10 +61,17 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { return; } + mesh->stop(); + if(!mesh->join(arg)) fprintf(stderr, "Could not join using invitation: %s\n", meshlink::strerror()); else fprintf(stderr, "Invitation accepted!\n"); + + if(!mesh->start()) { + fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink::strerror()); + exit(1); + } } else if(!strcasecmp(buf, "kick")) { if(!arg) { fprintf(stderr, "/kick requires an argument!\n"); diff --git a/examples/manynodes.c b/examples/manynodes.c index f0fc22da..0aafbcef 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -221,7 +221,10 @@ static void parse_command(char *buf) { fprintf(stderr, "Could not join using invitation: %s\n", meshlink_strerror(meshlink_errno)); else { fprintf(stderr, "Invitation accepted!\n"); - meshlink_start(mesh[nodeindex]); + } + if(!meshlink_start(mesh[nodeindex])) { + fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink_strerror(meshlink_errno)); + exit(1); } } else if(!strcasecmp(buf, "kick")) { if(!arg) {