From a2801adffebb6a3679e41789b38ba925ed32832b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 6 Jan 2017 08:18:50 -0800 Subject: Message API was awkward. The use of a single function to get both size and length actually turned out to be awkward to use; better to have separate functions to get each. While here, disable some of the initialization/fork checks, because it turns out they aren't needed. --- src/core/message.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/core/message.c') diff --git a/src/core/message.c b/src/core/message.c index 351858a4..4c666955 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -185,8 +185,11 @@ nni_chunk_trim(nni_chunk *ch, size_t len) if (ch->ch_len < len) { return (NNG_EINVAL); } - ch->ch_ptr += len; ch->ch_len -= len; + // Don't advance the pointer if we are just removing the whole content + if (ch->ch_len != 0) { + ch->ch_ptr += len; + } return (0); } @@ -442,25 +445,33 @@ nni_msg_realloc(nni_msg *m, size_t sz) void * -nni_msg_header(nni_msg *m, size_t *szp) +nni_msg_header(nni_msg *m) { - if (szp != NULL) { - *szp = m->m_header.ch_len; - } return (m->m_header.ch_ptr); } +size_t +nni_msg_header_len(nni_msg *m) +{ + return (m->m_header.ch_len); +} + + void * -nni_msg_body(nni_msg *m, size_t *szp) +nni_msg_body(nni_msg *m) { - if (szp != NULL) { - *szp = m->m_body.ch_len; - } return (m->m_body.ch_ptr); } +size_t +nni_msg_len(nni_msg *m) +{ + return (m->m_body.ch_len); +} + + int nni_msg_append(nni_msg *m, const void *data, size_t len) { -- cgit v1.2.3-70-g09d2