From 64db0f085be0c9efc6dca8d9e72d3e5a47cb792e Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 25 Sep 2017 12:49:10 -0700 Subject: 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.) --- tests/survey.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'tests/survey.c') diff --git a/tests/survey.c b/tests/survey.c index ae252cd5..346f2f30 100644 --- a/tests/survey.c +++ b/tests/survey.c @@ -14,7 +14,6 @@ #include extern const char *nng_opt_surveyor_surveytime; -extern int nng_optid_surveyor_surveytime; #define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s)) #define CHECKSTR(m, s) \ @@ -33,17 +32,6 @@ TestMain("SURVEY pattern", { Reset({ nng_close(surv); }); - Convey("Surveytime option id works", { - int opt; - const char *name; - opt = nng_option_lookup(nng_opt_surveyor_surveytime); - So(opt >= 0); - So(opt == nng_optid_surveyor_surveytime); - name = nng_option_name(opt); - So(name != NULL); - So(strcmp(name, nng_opt_surveyor_surveytime) == 0); - }); - Convey("Protocols match", { So(nng_protocol(surv) == NNG_PROTO_SURVEYOR); So(nng_peer(surv) == NNG_PROTO_RESPONDENT); @@ -57,8 +45,8 @@ TestMain("SURVEY pattern", { Convey("Survey without responder times out", { nng_msg *msg; - So(nng_setopt_usec(surv, nng_optid_surveyor_surveytime, - 50000) == 0); + So(nng_setopt_usec( + surv, nng_opt_surveyor_surveytime, 50000) == 0); So(nng_msg_alloc(&msg, 0) == 0); So(nng_sendmsg(surv, msg, 0) == 0); So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); @@ -97,8 +85,8 @@ TestMain("SURVEY pattern", { nng_close(resp); }); - So(nng_setopt_usec( - surv, nng_optid_surveyor_surveytime, 50000) == 0); + So(nng_setopt_usec(surv, nng_opt_surveyor_surveytime, 50000) == + 0); So(nng_listen(surv, addr, NULL, 0) == 0); So(nng_dial(resp, addr, NULL, 0) == 0); @@ -132,8 +120,8 @@ TestMain("SURVEY pattern", { Convey("And goes to non-survey state", { rtimeo = 200000; - So(nng_setopt_usec(surv, nng_optid_recvtimeo, - 200000) == 0); + So(nng_setopt_usec( + surv, NNG_OPT_RECVTIMEO, 200000) == 0); So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE); }); }); -- cgit v1.2.3-70-g09d2