aboutsummaryrefslogtreecommitdiff
path: root/tests/bus.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-08 21:19:09 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-09 02:38:55 -0700
commitd64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba (patch)
treef6bdac79578176f0d00528d191f862009e761eac /tests/bus.c
parent5f0398de8edd1ed4ddbf6455c66273a6608aad9a (diff)
downloadnng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.gz
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.bz2
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.zip
fixes #44 open protocol by "name" (symbol) instead number
fixes #38 Make protocols "pluggable", or at least optional This is a breaking change, as we've done away with the central registered list of protocols, and instead demand the user call nng_xxx_open() where xxx is a protocol name. (We did keep a table around in the compat framework though.) There is a nice way for protocols to plug in via an nni_proto_open(), where they can use a generic constructor that they use to build a protocol specific constructor (passing their ops vector in.)
Diffstat (limited to 'tests/bus.c')
-rw-r--r--tests/bus.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/tests/bus.c b/tests/bus.c
index 78740a37..e96a0a53 100644
--- a/tests/bus.c
+++ b/tests/bus.c
@@ -8,14 +8,15 @@
//
#include "convey.h"
-#include "nng.h"
#include "core/nng_impl.h"
+#include "nng.h"
#include <string.h>
-#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
-#define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\
- So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
+#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
+#define CHECKSTR(m, s) \
+ So(nng_msg_len(m) == strlen(s)); \
+ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
Main({
const char *addr = "inproc://test";
@@ -27,54 +28,57 @@ Main({
Convey("We can create a BUS socket", {
nng_socket bus;
- So(nng_open(&bus, NNG_PROTO_BUS) == 0);
+ So(nng_bus_open(&bus) == 0);
- Reset({
- nng_close(bus);
- })
+ Reset({ nng_close(bus); });
Convey("Protocols match", {
So(nng_protocol(bus) == NNG_PROTO_BUS);
So(nng_peer(bus) == NNG_PROTO_BUS);
- })
- })
+ });
+ });
Convey("We can create a linked BUS topology", {
nng_socket bus1;
nng_socket bus2;
nng_socket bus3;
- uint64_t rtimeo;
+ uint64_t rtimeo;
+
+ So(nng_bus_open(&bus1) == 0);
+ So(nng_bus_open(&bus2) == 0);
+ So(nng_bus_open(&bus3) == 0);
- So(nng_open(&bus1, NNG_PROTO_BUS) == 0);
- So(nng_open(&bus2, NNG_PROTO_BUS) == 0);
- So(nng_open(&bus3, NNG_PROTO_BUS) == 0);
-
Reset({
nng_close(bus1);
nng_close(bus2);
nng_close(bus3);
- })
+ });
So(nng_listen(bus1, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(bus2, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(bus3, addr, NULL, NNG_FLAG_SYNCH) == 0);
rtimeo = 50000;
- So(nng_setopt(bus1, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus1, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
rtimeo = 50000;
- So(nng_setopt(bus2, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus2, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
rtimeo = 50000;
- So(nng_setopt(bus3, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0);
+ So(nng_setopt(bus3, NNG_OPT_RCVTIMEO, &rtimeo,
+ sizeof(rtimeo)) == 0);
Convey("Messages delivered", {
nng_msg *msg;
-
// This is just a poor man's sleep.
- So(nng_recvmsg(bus1, &msg, 0) == NNG_ETIMEDOUT);
- So(nng_recvmsg(bus2, &msg, 0) == NNG_ETIMEDOUT);
- So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
-
+ So(nng_recvmsg(bus1, &msg, 0) ==
+ NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus2, &msg, 0) ==
+ NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus3, &msg, 0) ==
+ NNG_ETIMEDOUT);
+
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "99bits");
So(nng_sendmsg(bus2, msg, 0) == 0);
@@ -82,7 +86,8 @@ Main({
So(nng_recvmsg(bus1, &msg, 0) == 0);
CHECKSTR(msg, "99bits");
nng_msg_free(msg);
- So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus3, &msg, 0) ==
+ NNG_ETIMEDOUT);
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "onthe");
@@ -95,7 +100,7 @@ Main({
So(nng_recvmsg(bus3, &msg, 0) == 0);
CHECKSTR(msg, "onthe");
nng_msg_free(msg);
- })
- })
- })
+ });
+ });
+ });
})