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/bus/bus.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/protocol/bus/bus.c') diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c index c5a6ce06..79d7187e 100644 --- a/src/protocol/bus/bus.c +++ b/src/protocol/bus/bus.c @@ -240,16 +240,14 @@ nni_bus_pipe_recv_cb(void *arg) nni_bus_pipe *ppipe = arg; nni_bus_sock *psock = ppipe->psock; nni_msg * msg; - uint32_t id; if (nni_aio_result(&ppipe->aio_recv) != 0) { nni_pipe_stop(ppipe->npipe); return; } msg = ppipe->aio_recv.a_msg; - id = nni_pipe_id(ppipe->npipe); - if (nni_msg_prepend_header(msg, &id, 4) != 0) { + if (nni_msg_header_insert_u32(msg, nni_pipe_id(ppipe->npipe)) != 0) { // XXX: bump a nomemory stat nni_msg_free(msg); nni_pipe_stop(ppipe->npipe); @@ -298,8 +296,7 @@ nni_bus_sock_getq_cb(void *arg) // is doing this probably.) In this case grab the pipe // ID from the header, so we can exclude it. if (nni_msg_header_len(msg) >= 4) { - memcpy(&sender, nni_msg_header(msg), 4); - nni_msg_trim_header(msg, 4); + sender = nni_msg_header_trim_u32(msg); } else { sender = 0; } -- cgit v1.2.3-70-g09d2