aboutsummaryrefslogtreecommitdiff
path: root/tests/pipeline.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/pipeline.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/pipeline.c')
-rw-r--r--tests/pipeline.c100
1 files changed, 54 insertions, 46 deletions
diff --git a/tests/pipeline.c b/tests/pipeline.c
index aa01c2d1..510b7f77 100644
--- a/tests/pipeline.c
+++ b/tests/pipeline.c
@@ -8,13 +8,14 @@
//
#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";
@@ -25,58 +26,54 @@ Main({
Convey("We can create a PUSH socket", {
nng_socket push;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
+ So(nng_push_open(&push) == 0);
- Reset({
- nng_close(push);
- })
+ Reset({ nng_close(push); });
Convey("Protocols match", {
So(nng_protocol(push) == NNG_PROTO_PUSH);
So(nng_peer(push) == NNG_PROTO_PULL);
- })
+ });
Convey("Recv fails", {
nng_msg *msg;
So(nng_recvmsg(push, &msg, 0) == NNG_ENOTSUP);
- })
- })
+ });
+ });
Convey("We can create a PULL socket", {
nng_socket pull;
- So(nng_open(&pull, NNG_PROTO_PULL) == 0);
+ So(nng_pull_open(&pull) == 0);
- Reset({
- nng_close(pull);
- })
+ Reset({ nng_close(pull); });
Convey("Protocols match", {
So(nng_protocol(pull) == NNG_PROTO_PULL);
So(nng_peer(pull) == NNG_PROTO_PUSH);
- })
+ });
Convey("Send fails", {
nng_msg *msg;
So(nng_msg_alloc(&msg, 0) == 0);
So(nng_sendmsg(pull, msg, 0) == NNG_ENOTSUP);
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("We can create a linked PUSH/PULL pair", {
nng_socket push;
nng_socket pull;
nng_socket what;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
- So(nng_open(&pull, NNG_PROTO_PULL) == 0);
- So(nng_open(&what, NNG_PROTO_PUSH) == 0);
+ So(nng_push_open(&push) == 0);
+ So(nng_pull_open(&pull) == 0);
+ So(nng_push_open(&what) == 0);
Reset({
nng_close(push);
nng_close(pull);
nng_close(what);
- })
+ });
// Its important to avoid a startup race that the
// sender be the dialer. Otherwise you need a delay
@@ -97,30 +94,30 @@ Main({
So(msg != NULL);
CHECKSTR(msg, "hello");
nng_msg_free(msg);
- })
- })
+ });
+ });
Convey("Load balancing", {
- nng_msg *abc;
- nng_msg *def;
- uint64_t usecs;
- int len;
+ nng_msg * abc;
+ nng_msg * def;
+ uint64_t usecs;
+ int len;
nng_socket push;
nng_socket pull1;
nng_socket pull2;
nng_socket pull3;
- So(nng_open(&push, NNG_PROTO_PUSH) == 0);
- So(nng_open(&pull1, NNG_PROTO_PULL) == 0);
- So(nng_open(&pull2, NNG_PROTO_PULL) == 0);
- So(nng_open(&pull3, NNG_PROTO_PULL) == 0);
+ So(nng_push_open(&push) == 0);
+ So(nng_pull_open(&pull1) == 0);
+ So(nng_pull_open(&pull2) == 0);
+ So(nng_pull_open(&pull3) == 0);
Reset({
nng_close(push);
nng_close(pull1);
nng_close(pull2);
nng_close(pull3);
- })
+ });
// We need to increase the buffer from zero, because
// there is no guarantee that the various listeners
@@ -129,14 +126,22 @@ Main({
// ensures that we can write to each stream, even if
// the listeners are not running yet.
len = 4;
- So(nng_setopt(push, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(push, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull1, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull1, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull2, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull2, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull3, NNG_OPT_RCVBUF, &len, sizeof (len)) == 0);
- So(nng_setopt(pull3, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
+ So(nng_setopt(
+ push, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ push, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull1, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull1, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull2, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull2, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull3, NNG_OPT_RCVBUF, &len, sizeof(len)) == 0);
+ So(nng_setopt(
+ pull3, NNG_OPT_SNDBUF, &len, sizeof(len)) == 0);
So(nng_msg_alloc(&abc, 0) == 0);
APPENDSTR(abc, "abc");
@@ -144,9 +149,12 @@ Main({
APPENDSTR(def, "def");
usecs = 100000;
- So(nng_setopt(pull1, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
- So(nng_setopt(pull2, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
- So(nng_setopt(pull3, NNG_OPT_RCVTIMEO, &usecs, sizeof (usecs)) == 0);
+ So(nng_setopt(pull1, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
+ So(nng_setopt(pull2, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
+ So(nng_setopt(pull3, NNG_OPT_RCVTIMEO, &usecs,
+ sizeof(usecs)) == 0);
So(nng_listen(push, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(pull1, addr, NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(pull2, addr, NULL, NNG_FLAG_SYNCH) == 0);
@@ -175,8 +183,8 @@ Main({
So(nng_recvmsg(pull1, &abc, 0) == NNG_ETIMEDOUT);
So(nng_recvmsg(pull2, &abc, 0) == NNG_ETIMEDOUT);
- })
- })
+ });
+ });
nni_fini();
})