diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index c1971702e..000993ab9 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -38,26 +38,30 @@ void reply_handler(z_owned_reply_t *reply, void *ctx) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - const char *locator = NULL; + const char *clocator = NULL; + const char *llocator = NULL; const char *value = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case 'v': value = optarg; break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -70,8 +74,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_info.c b/examples/unix/c11/z_info.c index 68091cde8..2740d5110 100644 --- a/examples/unix/c11/z_info.c +++ b/examples/unix/c11/z_info.c @@ -29,19 +29,23 @@ void print_zid(const z_id_t *id, void *ctx) { int main(int argc, char **argv) { const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "e:m:")) != -1) { + while ((opt = getopt(argc, argv, "e:m:l:")) != -1) { switch (opt) { case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'e' || optopt == 'm') { + if (optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index e7b7e64bc..e4f96b7ea 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -27,7 +27,8 @@ int main(int argc, char **argv) { char *const default_value = "Pub from Pico!"; char *value = default_value; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int n = 10; int opt; @@ -40,25 +41,19 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; case 'l': - opt = atoi(optarg); - value = z_malloc(opt + 1); - memset(value, 'A', opt); - value[opt] = 0; - for (int i = opt - 1; opt > 0; i--, opt /= 10) { - value[i] = '0' + (opt % 10); - } + llocator = optarg; break; case 'n': n = atoi(optarg); break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -71,8 +66,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_pub_st.c b/examples/unix/c11/z_pub_st.c index 1e27ade12..f2b0fef79 100644 --- a/examples/unix/c11/z_pub_st.c +++ b/examples/unix/c11/z_pub_st.c @@ -23,10 +23,11 @@ int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -35,13 +36,16 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index 2a403af44..0445d48f9 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -23,10 +23,11 @@ int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-put"; const char *value = "Pub from Pico!"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -35,13 +36,16 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index e6f9d8e48..31a7d10ba 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -38,25 +38,29 @@ void query_handler(const z_query_t *query, void *ctx) { int main(int argc, char **argv) { const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case 'v': value = optarg; break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -69,8 +73,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 7cc329416..7b097fe72 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *ctx) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -58,8 +62,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 7a8b96143..567290484 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *ctx) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -58,8 +62,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index f20104028..65e22f91b 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -38,26 +38,30 @@ void reply_handler(z_owned_reply_t *reply, void *ctx) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - const char *locator = NULL; + const char *clocator = NULL; + const char *llocator = NULL; const char *value = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case 'v': value = optarg; break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -70,8 +74,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_info.c b/examples/unix/c99/z_info.c index a06f13ee3..901587bd8 100644 --- a/examples/unix/c99/z_info.c +++ b/examples/unix/c99/z_info.c @@ -29,19 +29,23 @@ void print_zid(const z_id_t *id, void *ctx) { int main(int argc, char **argv) { const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "e:m:")) != -1) { + while ((opt = getopt(argc, argv, "e:m:l:")) != -1) { switch (opt) { case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'e' || optopt == 'm') { + if (optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index a5839f36f..8ee66dfdb 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -23,10 +23,11 @@ int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -35,13 +36,16 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index 1261fcd50..96eeba2a4 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -23,10 +23,11 @@ int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -35,13 +36,16 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 45ebe29b4..be22b6eea 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -23,10 +23,11 @@ int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-put"; const char *value = "Pub from Pico!"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:v:e:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -35,13 +36,16 @@ int main(int argc, char **argv) { value = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -54,8 +58,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index e920b1035..8ddcf74e6 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -34,10 +34,11 @@ void query_handler(const z_query_t *query, void *ctx) { int main(int argc, char **argv) { const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + const char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:v:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:v:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -49,10 +50,13 @@ int main(int argc, char **argv) { mode = optarg; break; case 'e': - locator = optarg; + clocator = optarg; + break; + case 'l': + llocator = optarg; break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -65,8 +69,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index db294ee00..0f616525f 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *arg) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -58,8 +62,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index 4a87cce3b..fac31bd46 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -30,22 +30,26 @@ void data_handler(const z_sample_t *sample, void *arg) { int main(int argc, char **argv) { const char *keyexpr = "demo/example/**"; const char *mode = "client"; - char *locator = NULL; + char *clocator = NULL; + char *llocator = NULL; int opt; - while ((opt = getopt(argc, argv, "k:e:m:")) != -1) { + while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; break; case 'e': - locator = optarg; + clocator = optarg; break; case 'm': mode = optarg; break; + case 'l': + llocator = optarg; + break; case '?': - if (optopt == 'k' || optopt == 'e' || optopt == 'm') { + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -58,8 +62,11 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); - if (locator != NULL) { - zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); } printf("Opening session...\n"); diff --git a/src/net/session.c b/src/net/session.c index 28ceb6725..2f2b0c93e 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -16,7 +16,10 @@ #include #include +#include "zenoh-pico/api/primitives.h" #include "zenoh-pico/collections/bytes.h" +#include "zenoh-pico/collections/string.h" +#include "zenoh-pico/config.h" #include "zenoh-pico/net/memory.h" #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/session/utils.h" @@ -61,7 +64,9 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { if (config != NULL) { _z_str_array_t locators = _z_str_array_empty(); - if (_z_config_get(config, Z_CONFIG_CONNECT_KEY) == NULL) { // Scout if peer is not configured + char *connect = _z_config_get(config, Z_CONFIG_CONNECT_KEY); + char *listen = _z_config_get(config, Z_CONFIG_LISTEN_KEY); + if (connect == NULL && listen == NULL) { // Scout if peer is not configured opt_as_str = _z_config_get(config, Z_CONFIG_SCOUTING_WHAT_KEY); if (opt_as_str == NULL) { opt_as_str = Z_CONFIG_SCOUTING_WHAT_DEFAULT; @@ -88,8 +93,17 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { } _z_hello_list_free(&hellos); } else { + int key = Z_CONFIG_CONNECT_KEY; + if (listen != NULL) { + if (connect == NULL) { + key = Z_CONFIG_LISTEN_KEY; + _zp_config_insert(config, Z_CONFIG_MODE_KEY, _z_string_make(Z_CONFIG_MODE_PEER)); + } else { + return _Z_ERR_GENERIC; + } + } locators = _z_str_array_make(1); - locators.val[0] = _z_str_clone(_z_config_get(config, Z_CONFIG_CONNECT_KEY)); + locators.val[0] = _z_str_clone(_z_config_get(config, key)); } ret = _Z_ERR_SCOUT_NO_RESULTS; diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 125c90039..29b05223a 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -65,7 +65,7 @@ int main(int argc, char **argv) { z_owned_config_t config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make("peer")); - zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(argv[1])); + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(argv[1])); for (unsigned int i = 0; i < SET; i++) idx[i] = i; diff --git a/zenohpico.pc b/zenohpico.pc index 743095b12..3254c5f2a 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.10.20230913dev +Version: 0.10.20230915dev Cflags: -I${prefix}/ Libs: -L${prefix}/ -lzenohpico