From 45f455064b5704f3d5ed8ecf9f197a18fe72ee59 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 4 Apr 2018 12:37:34 -0700 Subject: 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. --- tests/pubsub.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'tests/pubsub.c') 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); }); + }) -- cgit v1.2.3-70-g09d2