]> git.meshlink.io Git - meshlink/commitdiff
Fix the C++ wrapper and the examples.
authorGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 13:09:50 +0000 (15:09 +0200)
committerGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 13:09:50 +0000 (15:09 +0200)
examples/chat.c
examples/chatpp.cc
src/meshlink++.h

index 1c07e422d07a2fa7efb20c015d94db81246be21f..3dbbb86019bb8713d47b7cdcd1068f3a90d638fd 100644 (file)
@@ -27,6 +27,9 @@ static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool rea
                printf("%s left.\n", node->name);
 }
 
+static meshlink_node_t **nodes;
+static size_t nnodes;
+
 static void parse_command(meshlink_handle_t *mesh, char *buf) {
        char *arg = strchr(buf, ' ');
        if(arg)
@@ -75,16 +78,13 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
                printf("Node '%s' blacklisted.\n", arg);
        } else if(!strcasecmp(buf, "who")) {
                if(!arg) {
-                       meshlink_node_t *nodes[100];
-                       size_t n = meshlink_get_all_nodes(mesh, nodes, 100);
-                       if(!n) {
+                       nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes);
+                       if(!nnodes) {
                                fprintf(stderr, "No nodes known!\n");
                        } else {
                                printf("Known nodes:");
-                               for(int i = 0; i < n && i < 100; i++)
+                               for(int i = 0; i < nnodes; i++)
                                        printf(" %s", nodes[i]->name);
-                               if(n > 100)
-                                       printf(" (and %zu more)", n - 100);
                                printf("\n");
                        }
                } else {
index 73ced3c6a2c0f67c7ffbc1a2ff0c054306b12541..00863d501815cee2c5064d945987a27e3359e79e 100644 (file)
@@ -27,6 +27,9 @@ static void node_status(meshlink::mesh *mesh, meshlink::node *node, bool reachab
                printf("%s left.\n", node->name);
 }
 
+static meshlink::node **nodes;
+static size_t nnodes;
+
 static void parse_command(meshlink::mesh *mesh, char *buf) {
        char *arg = strchr(buf, ' ');
        if(arg)
@@ -75,16 +78,13 @@ static void parse_command(meshlink::mesh *mesh, char *buf) {
                printf("Node '%s' blacklisted.\n", arg);
        } else if(!strcasecmp(buf, "who")) {
                if(!arg) {
-                       meshlink::node *nodes[100];
-                       size_t n = mesh->get_all_nodes(nodes, 100);
-                       if(!n) {
+                       nodes = mesh->get_all_nodes(nodes, &nnodes);
+                       if(!nnodes) {
                                fprintf(stderr, "No nodes known!\n");
                        } else {
                                printf("Known nodes:");
-                               for(size_t i = 0; i < n && i < 100; i++)
+                               for(size_t i = 0; i < nnodes; i++)
                                        printf(" %s", nodes[i]->name);
-                               if(n > 100)
-                                       printf(" (and %zu more)", n - 100);
                                printf("\n");
                        }
                } else {
index 2729130cc64872f686a1fe6a4ce9bda60a564c9f..1d6c986123c0dd119458c2a9778768cf622269ed 100644 (file)
@@ -185,8 +185,8 @@ namespace meshlink {
                 *  @return             The number of known nodes, or -1 in case of an error.
                 *                      This can be larger than nmemb, in which case not all nodes were stored in the nodes array.
                 */
-               ssize_t get_all_nodes(node **nodes, size_t nmemb) {
-                       return meshlink_get_all_nodes(this, (meshlink_node_t **)nodes, nmemb);
+               node **get_all_nodes(node **nodes, size_t *nmemb) {
+                       return (node **)meshlink_get_all_nodes(this, (meshlink_node_t **)nodes, nmemb);
                }
 
                /// Sign data using the local node's MeshLink key.