From dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 10 Aug 2017 18:14:27 -0700 Subject: Unify the msg API. This makes the operations that work on headers start with nni_msg_header or nng_msg_header. It also renames _trunc to _chop (same strlen as _trim), and renames prepend to insert. We add a shorthand for clearing message content, and make better use of the endian safe 32-bit accessors too. This also fixes a bug in inserting large headers into messages. A test suite for message handling is included. --- src/protocol/reqrep/req.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/protocol/reqrep/req.c') diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c index d0dd3887..20fb07f8 100644 --- a/src/protocol/reqrep/req.c +++ b/src/protocol/reqrep/req.c @@ -437,17 +437,14 @@ nni_req_recv_cb(void *arg) // Malformed message. goto malformed; } - if (nni_msg_append_header(msg, nni_msg_body(msg), 4) != 0) { + if (nni_msg_header_append(msg, nni_msg_body(msg), 4) != 0) { // Arguably we could just discard and carry on. But // dropping the connection is probably more helpful since // it lets the other side see that a problem occurred. // Plus it gives us a chance to reclaim some memory. goto malformed; } - if (nni_msg_trim(msg, 4) != 0) { - // This should never happen - could be an assert. - nni_panic("Failed to trim REQ header from body"); - } + (void) nni_msg_trim(msg, 4); // Cannot fail rp->aio_putq.a_msg = msg; nni_msgq_aio_put(rp->req->urq, &rp->aio_putq); @@ -548,7 +545,7 @@ nni_req_sock_sfilter(void *arg, nni_msg *msg) // Request ID is in big endian format. NNI_PUT32(req->reqid, id); - if (nni_msg_append_header(msg, req->reqid, 4) != 0) { + if (nni_msg_header_append(msg, req->reqid, 4) != 0) { // Should be ENOMEM. nni_msg_free(msg); return (NULL); -- cgit v1.2.3-70-g09d2