diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-02 17:35:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-02 17:35:49 -0800 |
| commit | 13e380343c0eec96a723e7407d59fb7f5d20aba0 (patch) | |
| tree | f50fdea3117c64d460fc82ce7978b6b4253250cf /tests/reqrep.c | |
| parent | ec2b1275153487fda661942d9b98aab2567b612e (diff) | |
| download | nng-13e380343c0eec96a723e7407d59fb7f5d20aba0.tar.gz nng-13e380343c0eec96a723e7407d59fb7f5d20aba0.tar.bz2 nng-13e380343c0eec96a723e7407d59fb7f5d20aba0.zip | |
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.
Diffstat (limited to 'tests/reqrep.c')
| -rw-r--r-- | tests/reqrep.c | 44 |
1 files changed, 44 insertions, 0 deletions
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); + }) }) }) }) |
