aboutsummaryrefslogtreecommitdiff
path: root/tests/sock.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-14 15:27:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-14 15:27:38 -0700
commit63479c2938cbc80c1aac9367cb95564f6e7540e1 (patch)
tree495584b637f73b593d25f01577eeaa944477f159 /tests/sock.c
parent343417234aa3fd86e8ae0b56ae500a1ed3411cfc (diff)
downloadnng-63479c2938cbc80c1aac9367cb95564f6e7540e1.tar.gz
nng-63479c2938cbc80c1aac9367cb95564f6e7540e1.tar.bz2
nng-63479c2938cbc80c1aac9367cb95564f6e7540e1.zip
fixes #63 NNG_FLAG_SYNCH should be the default
Also enables creating endpoints that are idle (first part of endpoint options API) and shutting down endpoints.
Diffstat (limited to 'tests/sock.c')
-rw-r--r--tests/sock.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/tests/sock.c b/tests/sock.c
index 56159aae..31d48333 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -25,8 +25,27 @@ TestMain("Socket Operations", {
Reset({ nng_close(s1); });
Convey("And we can shut it down", {
+ char * buf;
+ size_t sz;
So(nng_shutdown(s1) == 0);
So(nng_shutdown(s1) == NNG_ECLOSED);
+ Convey("It can't receive", {
+ So(nng_recv(s1, &buf, &sz, NNG_FLAG_ALLOC) ==
+ NNG_ECLOSED);
+ });
+ Convey("It can't send",
+ { So(nng_send(s1, "", 0, 0) == NNG_ECLOSED); });
+ Convey("Cannot create endpoints", {
+ nng_dialer d;
+ nng_listener l;
+ char * a = "inproc://closed";
+ So(nng_dialer_create(&d, s1, a) ==
+ NNG_ECLOSED);
+ So(nng_listener_create(&l, s1, a) ==
+ NNG_ECLOSED);
+ So(nng_dial(s1, a, &d, 0) == NNG_ECLOSED);
+ So(nng_listen(s1, a, &l, 0) == NNG_ECLOSED);
+ });
});
Convey("It's type & peer are still PAIR", {
@@ -176,17 +195,37 @@ TestMain("Socket Operations", {
});
Convey("Dialing synch can get refused", {
- rv = nng_dial(s1, "inproc://no", NULL, NNG_FLAG_SYNCH);
+ rv = nng_dial(s1, "inproc://no", NULL, 0);
So(rv == NNG_ECONNREFUSED);
});
+ Convey("Dialing asynch does not get refused", {
+ char * buf;
+ size_t sz;
+ nng_socket s2;
+ char * a = "inproc://asy";
+ So(nng_dial(s1, a, NULL, NNG_FLAG_NONBLOCK) == 0);
+ Convey("And connects late", {
+ So(nng_pair_open(&s2) == 0);
+ Reset({ nng_close(s2); });
+ So(nng_listen(s2, a, NULL, 0) == 0);
+ nng_usleep(100000);
+ So(nng_send(s1, "abc", 4, 0) == 0);
+ So(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC) ==
+ 0);
+ So(sz == 4);
+ So(memcmp(buf, "abc", 4) == 0);
+ nng_free(buf, sz);
+ });
+ });
+
Convey("Listening works", {
char *a = "inproc://here";
- rv = nng_listen(s1, a, NULL, NNG_FLAG_SYNCH);
+ rv = nng_listen(s1, a, NULL, 0);
So(rv == 0);
Convey("Second listen fails ADDRINUSE", {
- rv = nng_listen(s1, a, NULL, NNG_FLAG_SYNCH);
+ rv = nng_listen(s1, a, NULL, 0);
So(rv == NNG_EADDRINUSE);
});
@@ -194,7 +233,7 @@ TestMain("Socket Operations", {
nng_socket s2;
So(nng_pair_open(&s2) == 0);
Reset({ nng_close(s2); });
- So(nng_dial(s2, a, NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_dial(s2, a, NULL, 0) == 0);
nng_close(s2);
});
});
@@ -222,8 +261,8 @@ TestMain("Socket Operations", {
So(nng_setopt_duration(s2, NNG_OPT_SNDTIMEO, to) == 0);
So(nng_setopt_duration(s2, NNG_OPT_RCVTIMEO, to) == 0);
- So(nng_listen(s1, a, NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(s2, a, NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_listen(s1, a, NULL, 0) == 0);
+ So(nng_dial(s2, a, NULL, 0) == 0);
So(nng_send(s1, "abc", 4, 0) == 0);
So(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC) == 0);