aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/bus
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-10 18:14:27 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-10 22:47:43 -0700
commitdbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292 (patch)
treec5b94f14fd95725077d2b4e9cd0d3d4d166aa7e2 /src/protocol/bus
parent34ceda3c2dd4990d15e0341e86861dd291003f63 (diff)
downloadnng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.tar.gz
nng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.tar.bz2
nng-dbbee1a3ea7fbd26c528eb96ebe0dbfd7075e292.zip
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.
Diffstat (limited to 'src/protocol/bus')
-rw-r--r--src/protocol/bus/bus.c7
1 files changed, 2 insertions, 5 deletions
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;
}