From 123e1439a284716c651eca037b95ba997e6c30db Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 27 Dec 2016 20:46:32 -0800 Subject: Send and receive now work. This fixes a few core issues, and improves readability for the message queue code as well. inproc delivery of messages works now. --- tests/sock.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/sock.c b/tests/sock.c index 7ba4b3c4..929e73c8 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -10,6 +10,8 @@ #include "convey.h" #include "nng.h" +#include + TestMain("Socket Operations", { Convey("We are able to open a PAIR socket", { int rv; @@ -47,8 +49,8 @@ TestMain("Socket Operations", { rv = nng_recvmsg(sock, &msg, 0); So(rv == NNG_ETIMEDOUT); So(msg == NULL); - So(nni_clock() > (now + 500000)); - So(nni_clock() < (now + 1000000)); + So(nni_clock() >= (now + when)); + So(nni_clock() < (now + (when * 2))); }) Convey("Recv nonblock with no pipes gives EAGAIN", { @@ -143,6 +145,11 @@ TestMain("Socket Operations", { Convey("We can send and receive messages", { nng_socket *sock2 = NULL; int len = 1; + nng_msg *msg; + size_t sz; + char *ptr; + uint64_t second = 1000000; + rv = nng_open(&sock2, NNG_PROTO_PAIR); So(rv == 0); @@ -155,6 +162,42 @@ TestMain("Socket Operations", { So(rv == 0); rv = nng_setopt(sock2, NNG_OPT_SNDBUF, &len, sizeof (len)); So(rv == 0); + + rv = nng_setopt(sock, NNG_OPT_SNDTIMEO, &second, sizeof (second)); + So(rv == 0); + rv = nng_setopt(sock, NNG_OPT_RCVTIMEO, &second, sizeof (second)); + So(rv == 0); + rv = nng_setopt(sock2, NNG_OPT_SNDTIMEO, &second, sizeof (second)); + So(rv == 0); + rv = nng_setopt(sock2, NNG_OPT_RCVTIMEO, &second, sizeof (second)); + So(rv == 0); + + rv = nng_listen(sock, "inproc://test1", NULL, NNG_FLAG_SYNCH); + So(rv == 0); + rv = nng_dial(sock2, "inproc://test1", NULL, 0); + So(rv == 0); + + rv = nng_msg_alloc(&msg, 3); + So(rv == 0); + ptr = nng_msg_body(msg, &sz); + So(ptr != NULL); + So(sz == 3); + + memcpy(ptr, "abc", 3); + + rv = nng_sendmsg(sock, msg, 0); + So(rv == 0); + + msg = NULL; + rv = nng_recvmsg(sock2, &msg, 0); + So(rv == 0); + So(msg != NULL); + ptr = nng_msg_body(msg, &sz); + So(ptr != NULL); + So(sz == 3); + So(memcmp(ptr, "abc", 3) == 0); + nng_msg_free(msg); + nng_close(sock2); }) }) -}) \ No newline at end of file +}) -- cgit v1.2.3-70-g09d2