]> git.meshlink.io Git - meshlink/commitdiff
manynodes chat example: use a prefix for nodes names so that is possible to run multi...
authorSaverio Proto <zioproto@gmail.com>
Fri, 8 Aug 2014 12:40:15 +0000 (12:40 +0000)
committerSaverio Proto <zioproto@gmail.com>
Fri, 8 Aug 2014 13:18:52 +0000 (15:18 +0200)
examples/manynodes.c

index 3fa88c3b26decc143450a2abccbfad8b47c7a6a5..64a2657bfe8c54560b3e1991ab16b25bbeea7a19 100644 (file)
@@ -176,19 +176,23 @@ static void parse_input(char *buf) {
 
 int main(int argc, char *argv[]) {
        const char *basebase = ".manynodes";
+       const char *namesprefix = "machine1";
        char buf[1024];
 
        if(argc > 1)
                n = atoi(argv[1]);
 
        if(n < 1) {
-               fprintf(stderr, "Usage: %s [number of local nodes] [confbase]\n", argv[0]);
+               fprintf(stderr, "Usage: %s [number of local nodes] [confbase] [prefixnodenames]\n", argv[0]);
                return 1;
        }
 
        if(argc > 2)
                basebase = argv[2];
 
+       if(argc > 3)
+               namesprefix = argv[3];
+
        mesh = calloc(n, sizeof *mesh);
 
        mkdir(basebase, 0750);
@@ -196,7 +200,7 @@ int main(int argc, char *argv[]) {
        char filename[PATH_MAX];
        char nodename[100];
        for(int i = 0; i < n; i++) {
-               snprintf(nodename, sizeof nodename, "node%d", i);
+               snprintf(nodename, sizeof nodename, "%snode%d", namesprefix,i);
                snprintf(filename, sizeof filename, "%s/%s", basebase, nodename);
                bool itsnew = access(filename, R_OK);
                mesh[i] = meshlink_open(filename, nodename, "manynodes");