From 13e380343c0eec96a723e7407d59fb7f5d20aba0 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 2 Jan 2017 17:35:49 -0800 Subject: Fixes to enable REQ/REP to operate. This uncovered a few problems - inproc was not moving the headers to the body on transmit, and the message chunk allocator had a serious bug leading to memory corruption. I've also added a message dumper, which turns out to be incredibly useful during debugging. --- tests/reqrep.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/reqrep.c b/tests/reqrep.c index 9c45d2d4..4322edda 100644 --- a/tests/reqrep.c +++ b/tests/reqrep.c @@ -32,6 +32,12 @@ Main({ So(nng_protocol(req) == NNG_PROTO_REQ); So(nng_peer(req) == NNG_PROTO_REP); }) + + Convey("Recv with no send fails", { + nng_msg *msg; + rv = nng_recvmsg(req, &msg, 0); + So(rv == NNG_ESTATE); + }) }) Convey("We can create a REP socket", { @@ -48,6 +54,15 @@ Main({ So(nng_protocol(rep) == NNG_PROTO_REP); So(nng_peer(rep) == NNG_PROTO_REQ); }) + + Convey("Send with no recv fails", { + nng_msg *msg; + rv = nng_msg_alloc(&msg, 0); + So(rv == 0); + rv = nng_sendmsg(rep, msg, 0); + So(rv == NNG_ESTATE); + nng_msg_free(msg); + }) }) Convey("We can create a linked REQ/REP pair", { @@ -72,6 +87,35 @@ Main({ rv = nng_dial(req, addr, NULL, NNG_FLAG_SYNCH); So(rv == 0); + + Convey("They can REQ/REP exchange", { + nng_msg *ping; + nng_msg *pong; + char *body; + size_t len; + + So(nng_msg_alloc(&ping, 0) == 0); + So(nng_msg_append(ping, "ping", 5) == 0); + body = nng_msg_body(ping, &len); + So(len == 5); + So(memcmp(body, "ping", 5) == 0); + So(nng_sendmsg(req, ping, 0) == 0); + pong = NULL; + So(nng_recvmsg(rep, &pong, 0) == 0); + So(pong != NULL); + body = nng_msg_body(pong, &len); + So(len == 5); + So(memcmp(body, "ping", 5) == 0); + nng_msg_trim(pong, 5); + So(nng_msg_append(pong, "pong", 5) == 0); + So(nng_sendmsg(rep, pong, 0) == 0); + ping = 0; + So(nng_recvmsg(req, &ping, 0) == 0); + So(ping != NULL); + body = nng_msg_body(ping, &len); + So(len == 5); + So(memcmp(body, "pong", 5) == 0); + }) }) }) }) -- cgit v1.2.3-70-g09d2