From c9a68bfe6bea2acc708bf49045f6cb65017a3306 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 24 Aug 2017 14:15:48 -0700 Subject: Eliminate legacy option settings, provide easier option IDs. This eliminates all the old #define's or enum values, making all option IDs now totally dynamic, and providing well-known string values for well-behaved applications. We have added tests of some of these options, including lookups, and so forth. We have also fixed a few problems; including at least one crasher bug when the timeouts on reconnect were zero. Protocol specific options are now handled in the protocol. We will be moving the initialization for a few of those well known entities to the protocol startup code, following the PAIRv1 pattern, later. Applications must therefore not depend on the value of the integer IDs, at least until the application has opened a socket of the appropriate type. --- tests/pubsub.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'tests/pubsub.c') diff --git a/tests/pubsub.c b/tests/pubsub.c index 2712181d..de2fcfc5 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -83,35 +83,35 @@ TestMain("PUB/SUB pattern", { So(nng_dial(pub, addr, NULL, 0) == 0); Convey("Sub can subscribe", { - So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "ABC", 3) == 0); - So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "", 0) == 0); + So(nng_setopt( + sub, nng_optid_sub_subscribe, "ABC", 3) == 0); + So(nng_setopt(sub, nng_optid_sub_subscribe, "", 0) == + 0); Convey("Unsubscribe works", { - So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "ABC", - 3) == 0); - So(nng_setopt( - sub, NNG_OPT_UNSUBSCRIBE, "", 0) == 0); - - So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, "", - 0) == NNG_ENOENT); - So(nng_setopt(sub, NNG_OPT_UNSUBSCRIBE, + So(nng_setopt(sub, nng_optid_sub_unsubscribe, + "ABC", 3) == 0); + So(nng_setopt(sub, nng_optid_sub_unsubscribe, + "", 0) == 0); + + So(nng_setopt(sub, nng_optid_sub_unsubscribe, + "", 0) == NNG_ENOENT); + So(nng_setopt(sub, nng_optid_sub_unsubscribe, "HELLO", 0) == NNG_ENOENT); }); }); Convey("Pub cannot subscribe", { - So(nng_setopt(pub, NNG_OPT_SUBSCRIBE, "", 0) == + So(nng_setopt(pub, nng_optid_sub_subscribe, "", 0) == NNG_ENOTSUP); }); Convey("Subs can receive from pubs", { nng_msg *msg; - uint64_t rtimeo; - So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "/some/", + So(nng_setopt(sub, nng_optid_sub_subscribe, "/some/", strlen("/some/")) == 0); - rtimeo = 50000; // 50ms - So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, - sizeof(rtimeo)) == 0); + So(nng_setopt_usec(sub, nng_optid_recvtimeo, 90000) == + 0); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "/some/like/it/hot"); @@ -139,10 +139,9 @@ TestMain("PUB/SUB pattern", { Convey("Subs without subsciptions don't receive", { - uint64_t rtimeo = 50000; // 50ms nng_msg *msg; - So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, - sizeof(rtimeo)) == 0); + So(nng_setopt_usec(sub, nng_optid_recvtimeo, 90000) == + 0); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "/some/don't/like/it"); @@ -152,14 +151,11 @@ TestMain("PUB/SUB pattern", { Convey("Subs in raw receive", { - uint64_t rtimeo = 50000; // 500ms - int raw = 1; nng_msg *msg; - So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, - sizeof(rtimeo)) == 0); - So(nng_setopt(sub, NNG_OPT_RAW, &raw, sizeof(raw)) == + So(nng_setopt_usec(sub, nng_optid_recvtimeo, 90000) == 0); + So(nng_setopt_int(sub, nng_optid_raw, 1) == 0); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "/some/like/it/raw"); -- cgit v1.2.3-70-g09d2