summaryrefslogtreecommitdiff
path: root/tests/pair1.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/pair1.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/pair1.c')
-rw-r--r--tests/pair1.c89
1 files changed, 37 insertions, 52 deletions
diff --git a/tests/pair1.c b/tests/pair1.c
index ba13d494..c82dd5cb 100644
--- a/tests/pair1.c
+++ b/tests/pair1.c
@@ -14,7 +14,6 @@
#include <string.h>
-extern int nng_optid_pair1_poly;
extern const char *nng_opt_pair1_poly;
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
@@ -47,25 +46,13 @@ TestMain("PAIRv1 protocol", {
});
tmo = 300000;
- So(nng_setopt_usec(s1, nng_optid_recvtimeo, tmo) == 0);
- So(nng_setopt_usec(c1, nng_optid_recvtimeo, tmo) == 0);
- So(nng_setopt_usec(c2, nng_optid_recvtimeo, tmo) == 0);
+ So(nng_setopt_usec(s1, NNG_OPT_RECVTIMEO, tmo) == 0);
+ So(nng_setopt_usec(c1, NNG_OPT_RECVTIMEO, tmo) == 0);
+ So(nng_setopt_usec(c2, NNG_OPT_RECVTIMEO, tmo) == 0);
tmo = 0;
- So(nng_getopt_usec(s1, nng_optid_recvtimeo, &tmo) == 0);
+ So(nng_getopt_usec(s1, NNG_OPT_RECVTIMEO, &tmo) == 0);
So(tmo == 300000);
- Convey("Polyamorous option id works", {
- // This test has to be done after polyamorous mode
- // is registered!
- int poly;
- poly = nng_option_lookup(nng_opt_pair1_poly);
- So(poly >= 0);
- So(poly == nng_optid_pair1_poly);
- So(nng_option_name(poly) != 0);
- So(strcmp(nng_option_name(poly), nng_opt_pair1_poly) ==
- 0);
- });
-
Convey("Monogamous cooked mode works", {
nng_msg *msg;
@@ -114,8 +101,8 @@ TestMain("PAIRv1 protocol", {
So(nng_dial(c1, addr, NULL, 0) == 0);
nng_usleep(100000);
- So(nng_setopt_int(s1, nng_optid_raw, 1) == NNG_ESTATE);
- So(nng_setopt_int(c1, nng_optid_raw, 1) == NNG_ESTATE);
+ So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == NNG_ESTATE);
+ So(nng_setopt_int(c1, NNG_OPT_RAW, 1) == NNG_ESTATE);
});
Convey("Polyamorous mode is best effort", {
@@ -123,12 +110,12 @@ TestMain("PAIRv1 protocol", {
int i;
nng_msg *msg;
- So(nng_setopt_int(s1, nng_optid_pair1_poly, 1) == 0);
+ So(nng_setopt_int(s1, nng_opt_pair1_poly, 1) == 0);
- So(nng_setopt_int(s1, nng_optid_recvbuf, 1) == 0);
- So(nng_setopt_int(s1, nng_optid_sendbuf, 1) == 0);
- So(nng_setopt_int(c1, nng_optid_recvbuf, 1) == 0);
- So(nng_setopt_usec(s1, nng_optid_sendtimeo, 100000) ==
+ So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0);
+ So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0);
+ So(nng_setopt_int(c1, NNG_OPT_RECVBUF, 1) == 0);
+ So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, 100000) ==
0);
So(nng_listen(s1, addr, NULL, 0) == 0);
@@ -151,11 +138,10 @@ TestMain("PAIRv1 protocol", {
int rv;
nng_msg *msg;
- So(nng_setopt_int(s1, nng_optid_recvbuf, 1) == 0);
- So(nng_setopt_int(s1, nng_optid_sendbuf, 1) == 0);
- So(nng_setopt_int(c1, nng_optid_recvbuf, 1) == 0);
- So(nng_setopt_usec(s1, nng_optid_sendtimeo, 30000) ==
- 0);
+ So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0);
+ So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0);
+ So(nng_setopt_int(c1, NNG_OPT_RECVBUF, 1) == 0);
+ So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, 30000) == 0);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -179,7 +165,7 @@ TestMain("PAIRv1 protocol", {
So(nng_dial(c1, addr, NULL, 0) == 0);
nng_usleep(100000);
- So(nng_setopt_int(s1, nng_optid_pair1_poly, 1) ==
+ So(nng_setopt_int(s1, nng_opt_pair1_poly, 1) ==
NNG_ESTATE);
});
@@ -187,9 +173,9 @@ TestMain("PAIRv1 protocol", {
nng_msg *msg;
uint32_t hops;
- So(nng_setopt_int(s1, nng_optid_raw, 1) == 0);
- So(nng_setopt_int(c1, nng_optid_raw, 1) == 0);
- So(nng_setopt_int(c2, nng_optid_raw, 1) == 0);
+ So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
+ So(nng_setopt_int(c1, NNG_OPT_RAW, 1) == 0);
+ So(nng_setopt_int(c2, NNG_OPT_RAW, 1) == 0);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -267,10 +253,9 @@ TestMain("PAIRv1 protocol", {
Convey("TTL is honored", {
int ttl;
- So(nng_setopt_int(s1, nng_optid_maxttl, 4) ==
+ So(nng_setopt_int(s1, NNG_OPT_MAXTTL, 4) == 0);
+ So(nng_getopt_int(s1, NNG_OPT_MAXTTL, &ttl) ==
0);
- So(nng_getopt_int(
- s1, nng_optid_maxttl, &ttl) == 0);
So(ttl == 4);
Convey("Bad TTL bounces", {
So(nng_msg_alloc(&msg, 0) == 0);
@@ -298,8 +283,8 @@ TestMain("PAIRv1 protocol", {
Convey("Large TTL passes", {
ttl = 0xff;
- So(nng_setopt_int(s1, nng_optid_maxttl,
- 0xff) == 0);
+ So(nng_setopt_int(
+ s1, NNG_OPT_MAXTTL, 0xff) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
So(nng_msg_append_u32(msg, 1234) == 0);
So(nng_msg_header_append_u32(
@@ -316,8 +301,8 @@ TestMain("PAIRv1 protocol", {
Convey("Max TTL fails", {
ttl = 0xff;
- So(nng_setopt_int(s1, nng_optid_maxttl,
- 0xff) == 0);
+ So(nng_setopt_int(
+ s1, NNG_OPT_MAXTTL, 0xff) == 0);
So(nng_msg_alloc(&msg, 0) == 0);
So(nng_msg_header_append_u32(
msg, 0xff) == 0);
@@ -332,15 +317,15 @@ TestMain("PAIRv1 protocol", {
int ttl;
ttl = 0;
- So(nng_setopt_int(s1, nng_optid_maxttl, 0) ==
+ So(nng_setopt_int(s1, NNG_OPT_MAXTTL, 0) ==
NNG_EINVAL);
- So(nng_setopt_int(s1, nng_optid_maxttl, 1000) ==
+ So(nng_setopt_int(s1, NNG_OPT_MAXTTL, 1000) ==
NNG_EINVAL);
sz = 1;
ttl = 8;
- So(nng_setopt(s1, nng_optid_maxttl, &ttl, sz) ==
+ So(nng_setopt(s1, NNG_OPT_MAXTTL, &ttl, sz) ==
NNG_EINVAL);
});
@@ -350,11 +335,11 @@ TestMain("PAIRv1 protocol", {
nng_pipe p1;
nng_pipe p2;
- So(nng_getopt_int(s1, nng_optid_pair1_poly, &v) == 0);
+ So(nng_getopt_int(s1, nng_opt_pair1_poly, &v) == 0);
So(v == 0);
- So(nng_setopt_int(s1, nng_optid_pair1_poly, 1) == 0);
- So(nng_getopt_int(s1, nng_optid_pair1_poly, &v) == 0);
+ So(nng_setopt_int(s1, nng_opt_pair1_poly, 1) == 0);
+ So(nng_getopt_int(s1, nng_opt_pair1_poly, &v) == 0);
So(v == 1);
So(nng_listen(s1, addr, NULL, 0) == 0);
@@ -411,7 +396,7 @@ TestMain("PAIRv1 protocol", {
Convey("Polyamorous default works", {
nng_msg *msg;
- So(nng_setopt_int(s1, nng_optid_pair1_poly, 1) == 0);
+ So(nng_setopt_int(s1, nng_opt_pair1_poly, 1) == 0);
So(nng_listen(s1, addr, NULL, 0) == 0);
So(nng_dial(c1, addr, NULL, 0) == 0);
@@ -444,16 +429,16 @@ TestMain("PAIRv1 protocol", {
nng_pipe p1;
nng_pipe p2;
- So(nng_getopt_int(s1, nng_optid_pair1_poly, &v) == 0);
+ So(nng_getopt_int(s1, nng_opt_pair1_poly, &v) == 0);
So(v == 0);
- So(nng_setopt_int(s1, nng_optid_pair1_poly, 1) == 0);
- So(nng_getopt_int(s1, nng_optid_pair1_poly, &v) == 0);
+ So(nng_setopt_int(s1, nng_opt_pair1_poly, 1) == 0);
+ So(nng_getopt_int(s1, nng_opt_pair1_poly, &v) == 0);
So(v == 1);
v = 0;
- So(nng_setopt_int(s1, nng_optid_raw, 1) == 0);
- So(nng_getopt_int(s1, nng_optid_raw, &v) == 0);
+ So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
+ So(nng_getopt_int(s1, NNG_OPT_RAW, &v) == 0);
So(v == 1);
So(nng_listen(s1, addr, NULL, 0) == 0);