aboutsummaryrefslogtreecommitdiff
path: root/tests/zt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-09-25 12:49:10 -0700
committerGarrett D'Amore <garrett@damore.org>2017-09-27 14:38:12 -0700
commit64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (patch)
tree475520498d8ebe9e47e9785d8f9d209c87582400 /tests/zt.c
parent86a96e5bf1b207a8b1aa925e1d9f73ce834505b8 (diff)
downloadnng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.gz
nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.bz2
nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.zip
Refactor option handling APIs.
This makes the APIs use string keys, and largely eliminates the use of integer option IDs altogether. The underlying registration for options is also now a bit richer, letting protcols and transports declare the actual options they use, rather than calling down into each entry point carte blanche and relying on ENOTSUP. This code may not be as fast as the integers was, but it is more intuitive, easier to extend, and is not on any hot code paths. (If you're diddling options on a hot code path you're doing something wrong.)
Diffstat (limited to 'tests/zt.c')
-rw-r--r--tests/zt.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/tests/zt.c b/tests/zt.c
index fe6023a1..4826b6bf 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -13,10 +13,9 @@
extern int nng_zt_register(void);
extern const char *nng_opt_zt_home;
-extern int nng_optid_zt_home;
-extern int nng_optid_zt_node;
-extern int nng_optid_zt_status;
-extern int nng_optid_zt_network_name;
+extern const char *nng_opt_zt_node;
+extern const char *nng_opt_zt_status;
+extern const char *nng_opt_zt_network_name;
extern int nng_zt_status_ok;
// zerotier tests.
@@ -61,17 +60,11 @@ TestMain("ZeroTier Transport", {
So(nng_listener_create(&l, s, addr) == 0);
- Convey("We can lookup zerotier home option id", {
- So(nng_optid_zt_home > 0);
- So(nng_option_lookup(nng_opt_zt_home) ==
- nng_optid_zt_home);
- });
-
Convey("And it can be started...", {
mkdir(path1, 0700);
- So(nng_listener_setopt(l, nng_optid_zt_home, path1,
+ So(nng_listener_setopt(l, nng_opt_zt_home, path1,
strlen(path1) + 1) == 0);
So(nng_listener_start(l, 0) == 0);
@@ -93,12 +86,6 @@ TestMain("ZeroTier Transport", {
Reset({ nng_close(s); });
So(nng_dialer_create(&d, s, addr) == 0);
-
- Convey("We can lookup zerotier home option id", {
- So(nng_optid_zt_home > 0);
- So(nng_option_lookup(nng_opt_zt_home) ==
- nng_optid_zt_home);
- });
});
Convey("We can create an ephemeral listener", {
@@ -117,8 +104,7 @@ TestMain("ZeroTier Transport", {
So(nng_listener_create(&l, s, addr) == 0);
- So(nng_listener_getopt_usec(l, nng_optid_zt_node, &node1) ==
- 0);
+ So(nng_listener_getopt_usec(l, nng_opt_zt_node, &node1) == 0);
So(node1 != 0);
Convey("Network name & status options work", {
@@ -128,11 +114,11 @@ TestMain("ZeroTier Transport", {
namesz = sizeof(name);
nng_usleep(10000000);
- So(nng_listener_getopt(l, nng_optid_zt_network_name,
+ So(nng_listener_getopt(l, nng_opt_zt_network_name,
name, &namesz) == 0);
So(strcmp(name, "nng_test_open") == 0);
So(nng_listener_getopt_int(
- l, nng_optid_zt_status, &status) == 0);
+ l, nng_opt_zt_status, &status) == 0);
So(status == nng_zt_status_ok);
});
Convey("Connection refused works", {
@@ -140,7 +126,7 @@ TestMain("ZeroTier Transport", {
(unsigned long long) node1, 42u);
So(nng_dialer_create(&d, s, addr) == 0);
So(nng_dialer_getopt_usec(
- d, nng_optid_zt_node, &node2) == 0);
+ d, nng_opt_zt_node, &node2) == 0);
So(node2 == node1);
So(nng_dialer_start(d, 0) == NNG_ECONNREFUSED);
});
@@ -173,18 +159,18 @@ TestMain("ZeroTier Transport", {
So(nng_listener_create(&l, s1, addr1) == 0);
So(nng_listener_setopt(
- l, nng_optid_zt_home, path1, strlen(path1) + 1) == 0);
+ l, nng_opt_zt_home, path1, strlen(path1) + 1) == 0);
So(nng_listener_start(l, 0) == 0);
node = 0;
- So(nng_listener_getopt_usec(l, nng_optid_zt_node, &node) == 0);
+ So(nng_listener_getopt_usec(l, nng_opt_zt_node, &node) == 0);
So(node != 0);
snprintf(addr2, sizeof(addr2), "zt://" NWID "/%llx:%u",
(unsigned long long) node, port);
So(nng_dialer_create(&d, s2, addr2) == 0);
So(nng_dialer_setopt(
- d, nng_optid_zt_home, path2, strlen(path2) + 1) == 0);
+ d, nng_opt_zt_home, path2, strlen(path2) + 1) == 0);
So(nng_dialer_start(d, 0) == 0);
});