]> git.meshlink.io Git - meshlink/blobdiff - test/utils.c
Never automatically try to bind to ports >= 32768.
[meshlink] / test / utils.c
index 21b33f5e301d7e50aa9a75b9bc238d14dfe57375..872060b1035a1076f5fb2205b76fdea12e4ebfa0 100644 (file)
@@ -1,4 +1,4 @@
-#define _GNU_SOURCE 1
+#define _GNU_SOURCE
 
 #ifdef NDEBUG
 #undef NDEBUG
@@ -16,6 +16,7 @@
 void init_sync_flag(struct sync_flag *s) {
        assert(pthread_mutex_init(&s->mutex, NULL) == 0);
        assert(pthread_cond_init(&s->cond, NULL) == 0);
+       s->flag = false;
 }
 
 void set_sync_flag(struct sync_flag *s, bool value) {
@@ -108,11 +109,31 @@ void open_meshlink_pair(meshlink_handle_t **pa, meshlink_handle_t **pb, const ch
        *pb = b;
 }
 
+void open_meshlink_pair_ephemeral(meshlink_handle_t **pa, meshlink_handle_t **pb, const char *prefix) {
+       // Create two new MeshLink instances
+
+       *pa = *pb = NULL;
+
+       meshlink_handle_t *a = meshlink_open_ephemeral("a", prefix, DEV_CLASS_BACKBONE);
+       meshlink_handle_t *b = meshlink_open_ephemeral("b", prefix, DEV_CLASS_BACKBONE);
+
+       assert(a);
+       assert(b);
+
+       meshlink_enable_discovery(a, false);
+       meshlink_enable_discovery(b, false);
+
+       link_meshlink_pair(a, b);
+
+       *pa = a;
+       *pb = b;
+}
+
 // Don't poll in the application thread, use a condition variable to signal when the peer is online.
 static void pair_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
        (void)node;
 
-       if(reachable) {
+       if(reachable && meshlink_get_self(mesh) != node) {
                set_sync_flag(mesh->priv, true);
        }
 }