From 15f5a7d8cee6416bf4748d15f97ac59c13c2ac75 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 19 Jan 2020 09:41:12 -0800 Subject: fixes #1145 nng_msg options should be removed --- src/core/message.c | 91 +----------------------------------------------------- src/core/message.h | 4 +-- 2 files changed, 2 insertions(+), 93 deletions(-) (limited to 'src/core') diff --git a/src/core/message.c b/src/core/message.c index fd14c171..af5b0160 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -8,7 +8,6 @@ // found online at https://opensource.org/licenses/MIT. // -#include #include #include "core/nng_impl.h" @@ -27,18 +26,9 @@ typedef struct { struct nng_msg { nni_chunk m_header; nni_chunk m_body; - nni_time m_expire; // usec - nni_list m_options; uint32_t m_pipe; // set on receive }; -typedef struct { - int mo_num; - size_t mo_sz; - void * mo_val; - nni_list_node mo_node; -} nni_msgopt; - #if 0 static void nni_chunk_dump(const nni_chunk *chunk, char *prefix) @@ -433,7 +423,6 @@ nni_msg_alloc(nni_msg **mp, size_t sz) nni_panic("chunk_append failed"); } - NNI_LIST_INIT(&m->m_options, nni_msgopt, mo_node); *mp = m; return (0); } @@ -442,14 +431,11 @@ int nni_msg_dup(nni_msg **dup, const nni_msg *src) { nni_msg * m; - nni_msgopt *mo; - nni_msgopt *newmo; int rv; if ((m = NNI_ALLOC_STRUCT(m)) == NULL) { return (NNG_ENOMEM); } - NNI_LIST_INIT(&m->m_options, nni_msgopt, mo_node); if ((rv = nni_chunk_dup(&m->m_header, &src->m_header)) != 0) { NNI_FREE_STRUCT(m); @@ -461,20 +447,6 @@ nni_msg_dup(nni_msg **dup, const nni_msg *src) return (rv); } - NNI_LIST_FOREACH (&src->m_options, mo) { - newmo = nni_zalloc(sizeof(*newmo) + mo->mo_sz); - if (newmo == NULL) { - nni_msg_free(m); - return (NNG_ENOMEM); - } - newmo->mo_val = ((char *) newmo + sizeof(*newmo)); - newmo->mo_sz = mo->mo_sz; - newmo->mo_num = mo->mo_num; - if (mo->mo_sz > 0) { - memcpy(newmo->mo_val, mo->mo_val, mo->mo_sz); - } - nni_list_append(&m->m_options, newmo); - } m->m_pipe = src->m_pipe; *dup = m; @@ -484,74 +456,13 @@ nni_msg_dup(nni_msg **dup, const nni_msg *src) void nni_msg_free(nni_msg *m) { - nni_msgopt *mo; - if (m != NULL) { nni_chunk_free(&m->m_header); nni_chunk_free(&m->m_body); - while ((mo = nni_list_first(&m->m_options)) != NULL) { - nni_list_remove(&m->m_options, mo); - nni_free(mo, sizeof(*mo) + mo->mo_sz); - } NNI_FREE_STRUCT(m); } } -int -nni_msg_setopt(nni_msg *m, int opt, const void *val, size_t sz) -{ - // Find the existing option if present. Note that if we alter - // a value, we can wind up trashing old data due to ENOMEM. - nni_msgopt *oldmo, *newmo; - - NNI_LIST_FOREACH (&m->m_options, oldmo) { - if (oldmo->mo_num == opt) { - if (sz == oldmo->mo_sz && sz > 0) { - // nice! we can just overwrite old value - memcpy(oldmo->mo_val, val, sz); - return (0); - } - break; - } - } - if ((newmo = nni_zalloc(sizeof(*newmo) + sz)) == NULL) { - return (NNG_ENOMEM); - } - newmo->mo_val = ((char *) newmo + sizeof(*newmo)); - newmo->mo_sz = sz; - newmo->mo_num = opt; - if (sz > 0) { - memcpy(newmo->mo_val, val, sz); - } - if (oldmo != NULL) { - nni_list_remove(&m->m_options, oldmo); - nni_free(oldmo, sizeof(*oldmo) + oldmo->mo_sz); - } - nni_list_append(&m->m_options, newmo); - return (0); -} - -int -nni_msg_getopt(nni_msg *m, int opt, void *val, size_t *szp) -{ - nni_msgopt *mo; - - NNI_LIST_FOREACH (&m->m_options, mo) { - if (mo->mo_num == opt) { - size_t sz = *szp; - if (sz > mo->mo_sz) { - sz = mo->mo_sz; - if (sz > 0) { - memcpy(val, mo->mo_val, sz); - } - *szp = mo->mo_sz; - return (0); - } - } - } - return (NNG_ENOENT); -} - int nni_msg_realloc(nni_msg *m, size_t sz) { diff --git a/src/core/message.h b/src/core/message.h index c96bae99..d09a18dc 100644 --- a/src/core/message.h +++ b/src/core/message.h @@ -1,5 +1,5 @@ // -// Copyright 2017 Garrett D'Amore +// Copyright 2020 Staysail Systems, Inc. // Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -32,8 +32,6 @@ extern void nni_msg_clear(nni_msg *); extern void nni_msg_header_clear(nni_msg *); extern int nni_msg_header_trim(nni_msg *, size_t); extern int nni_msg_header_chop(nni_msg *, size_t); -extern int nni_msg_setopt(nni_msg *, int, const void *, size_t); -extern int nni_msg_getopt(nni_msg *, int, void *, size_t *); extern void nni_msg_dump(const char *, const nni_msg *); extern int nni_msg_append_u16(nni_msg *, uint16_t); extern int nni_msg_append_u32(nni_msg *, uint32_t); -- cgit v1.2.3-70-g09d2