From 34ceda3c2dd4990d15e0341e86861dd291003f63 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 10 Aug 2017 16:33:09 -0700 Subject: Add new PAIR_V1 protocol. The PAIR_V1 protocol supports both raw and cooked modes, and has loop prevention included. It also has a polyamorous mode, wherein it allows multiple connections to be established. In polyamorous mode (set by an option), the sender requests a paritcular pipe by setting it on the message. We default to PAIR_V1 now. --- src/core/message.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) (limited to 'src/core/message.c') diff --git a/src/core/message.c b/src/core/message.c index 4b563ce2..316bc035 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -1,5 +1,6 @@ // // Copyright 2016 Garrett D'Amore +// Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -29,6 +30,7 @@ struct nng_msg { nni_chunk m_body; nni_time m_expire; // usec nni_list m_options; + uint32_t m_pipe; // set on receive }; typedef struct { @@ -264,6 +266,42 @@ nni_chunk_prepend(nni_chunk *ch, const void *data, size_t len) return (0); } +static int +nni_chunk_prepend_u32(nni_chunk *ch, uint32_t val) +{ + unsigned char buf[sizeof(uint32_t)]; + NNI_PUT32(buf, val); + return (nni_chunk_prepend(ch, buf, sizeof(buf))); +} + +static int +nni_chunk_append_u32(nni_chunk *ch, uint32_t val) +{ + unsigned char buf[sizeof(uint32_t)]; + NNI_PUT32(buf, val); + return (nni_chunk_append(ch, buf, sizeof(buf))); +} + +static uint32_t +nni_chunk_trim_u32(nni_chunk *ch) +{ + uint32_t v; + NNI_ASSERT(ch->ch_len >= sizeof(v)); + NNI_GET32(ch->ch_ptr, v); + nni_chunk_trim(ch, sizeof(v)); + return (v); +} + +static uint32_t +nni_chunk_trunc_u32(nni_chunk *ch) +{ + uint32_t v; + NNI_ASSERT(ch->ch_len >= sizeof(v)); + NNI_GET32(ch->ch_ptr + ch->ch_len - sizeof(v), v); + nni_chunk_trunc(ch, sizeof(v)); + return (v); +} + int nni_msg_alloc(nni_msg **mp, size_t sz) { @@ -483,7 +521,6 @@ nni_msg_append_header(nni_msg *m, const void *data, size_t len) { return (nni_chunk_append(&m->m_header, data, len)); } - int nni_msg_prepend_header(nni_msg *m, const void *data, size_t len) { @@ -501,3 +538,61 @@ nni_msg_trunc_header(nni_msg *m, size_t len) { return (nni_chunk_trunc(&m->m_header, len)); } +int +nni_msg_append_u32(nni_msg *m, uint32_t val) +{ + return (nni_chunk_append_u32(&m->m_body, val)); +} + +int +nni_msg_prepend_u32(nni_msg *m, uint32_t val) +{ + return (nni_chunk_prepend_u32(&m->m_body, val)); +} + +int +nni_msg_header_append_u32(nni_msg *m, uint32_t val) +{ + return (nni_chunk_append_u32(&m->m_header, val)); +} + +int +nni_msg_header_prepend_u32(nni_msg *m, uint32_t val) +{ + return (nni_chunk_prepend_u32(&m->m_header, val)); +} + +uint32_t +nni_msg_trunc_u32(nni_msg *m) +{ + return (nni_chunk_trunc_u32(&m->m_body)); +} + +uint32_t +nni_msg_trim_u32(nni_msg *m) +{ + return (nni_chunk_trim_u32(&m->m_body)); +} + +uint32_t +nni_msg_header_trunc_u32(nni_msg *m) +{ + return (nni_chunk_trunc_u32(&m->m_header)); +} +uint32_t +nni_msg_header_trim_u32(nni_msg *m) +{ + return (nni_chunk_trim_u32(&m->m_header)); +} + +void +nni_msg_set_pipe(nni_msg *m, uint32_t pid) +{ + m->m_pipe = pid; +} + +uint32_t +nni_msg_get_pipe(nni_msg *m) +{ + return (m->m_pipe); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2