diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-04-04 12:37:34 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-04-04 13:13:24 -0700 |
| commit | 45f455064b5704f3d5ed8ecf9f197a18fe72ee59 (patch) | |
| tree | 76a626029f3a5a818b113b7e4342efaf6220a03f /tests/pubsub.c | |
| parent | 505a9bce029e51540739c853a6c9eef0ecfb2e90 (diff) | |
| download | nng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.tar.gz nng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.tar.bz2 nng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.zip | |
fixes #331 replace NNG_OPT_RAW option with constructor
This makes the raw mode something that is immutable, determined
at socket construction. This is an enabling change for the
separate context support coming soon.
As a result, this is an API breaking change for users of the raw
mode option (NNG_OPT_RAW). There aren't many of them out there.
Cooked mode is entirely unaffected.
There are changes to tests and documentation included.
Diffstat (limited to 'tests/pubsub.c')
| -rw-r--r-- | tests/pubsub.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/pubsub.c b/tests/pubsub.c index bd0d7f56..2151611d 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -146,19 +146,44 @@ TestMain("PUB/SUB pattern", { So(nng_recvmsg(sub, &msg, 0) == NNG_ETIMEDOUT); }); - Convey("Subs in raw receive", { + }); - nng_msg *msg; + Convey("Subs in raw receive", { - So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0); - So(nng_setopt_bool(sub, NNG_OPT_RAW, true) == 0); + nng_msg * msg; + nng_socket pub; + nng_socket sub; + bool raw; - So(nng_msg_alloc(&msg, 0) == 0); - APPENDSTR(msg, "/some/like/it/raw"); - So(nng_sendmsg(pub, msg, 0) == 0); - So(nng_recvmsg(sub, &msg, 0) == 0); - CHECKSTR(msg, "/some/like/it/raw"); - nng_msg_free(msg); + So(nng_pub_open(&pub) == 0); + + So(nng_sub_open_raw(&sub) == 0); + + Reset({ + nng_close(pub); + nng_close(sub); }); + + // Most applications will usually have the pub listen, + // and the sub dial. However, this creates a problem + // for our tests, since we can wind up trying to push + // data before the pipe is fully registered (the accept + // runs asynchronously.) + So(nng_listen(sub, addr, NULL, 0) == 0); + So(nng_dial(pub, addr, NULL, 0) == 0); + + nng_msleep(20); // give time for connecting threads + + So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0); + So(nng_getopt_bool(sub, NNG_OPT_RAW, &raw) == 0); + So(raw == true); + + So(nng_msg_alloc(&msg, 0) == 0); + APPENDSTR(msg, "/some/like/it/raw"); + So(nng_sendmsg(pub, msg, 0) == 0); + So(nng_recvmsg(sub, &msg, 0) == 0); + CHECKSTR(msg, "/some/like/it/raw"); + nng_msg_free(msg); }); + }) |
