aboutsummaryrefslogtreecommitdiff
path: root/src/core/message.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-01-11 13:15:40 -0800
committerGarrett D'Amore <garrett@damore.org>2020-01-11 14:15:37 -0800
commit6d92c73e5cdf93fe70b0646e78a250e01a8d2f65 (patch)
treecb14648b92b02e17bcb48f41a623009cdd65e0ab /src/core/message.c
parent516b99946aad5da15020de9d7175d44c12fd14c6 (diff)
downloadnng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.tar.gz
nng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.tar.bz2
nng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.zip
XREQ and others race on TTL.
The TTL in these cases should have been atomic. To facilitate things we actually introduce an atomic int for convenience. We also introduce a convenience nni_msg_must_append_u32() and nni_msg_header_must_append_u32(), so that we can eliminate some failure tests that cannot ever happen. Combined with a new test for xreq, we have 100% coverage for xreq and more coverage for the other REQ/REP protocols.
Diffstat (limited to 'src/core/message.c')
-rw-r--r--src/core/message.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core/message.c b/src/core/message.c
index 58baa4b7..fd14c171 100644
--- a/src/core/message.c
+++ b/src/core/message.c
@@ -650,6 +650,23 @@ nni_msg_header_chop(nni_msg *m, size_t len)
return (nni_chunk_##z##_u##x(&m->m_header, v)); \
}
+#define DEF_MSG_MUST_ADD_N(z, x) \
+ void nni_msg_must_##z##_u##x(nni_msg *m, uint##x##_t v) \
+ { \
+ int rv; \
+ if ((rv = nni_msg_##z##_u##x(m, v)) != 0) { \
+ nni_panic("nni_msg_%s_u%s failed: %d", #z, #x, rv); \
+ } \
+ } \
+ void nni_msg_header_must_##z##_u##x(nni_msg *m, uint##x##_t v) \
+ { \
+ int rv; \
+ if ((rv = nni_msg_header_##z##_u##x(m, v)) != 0) { \
+ nni_panic( \
+ "nni_msg_header_%s_u%s failed: %d", #z, #x, rv); \
+ } \
+ }
+
#define DEF_MSG_REM_N(z, x) \
uint##x##_t nni_msg_##z##_u##x(nni_msg *m) \
{ \
@@ -662,17 +679,23 @@ nni_msg_header_chop(nni_msg *m, size_t len)
#define DEF_MSG_ADD(op) \
DEF_MSG_ADD_N(op, 16) DEF_MSG_ADD_N(op, 32) DEF_MSG_ADD_N(op, 64)
+
+#define DEF_MSG_MUST_ADD(op) DEF_MSG_MUST_ADD_N(op, 32)
+
#define DEF_MSG_REM(op) \
DEF_MSG_REM_N(op, 16) DEF_MSG_REM_N(op, 32) DEF_MSG_REM_N(op, 64)
DEF_MSG_ADD(append)
+DEF_MSG_MUST_ADD(append)
DEF_MSG_ADD(insert)
DEF_MSG_REM(chop)
DEF_MSG_REM(trim)
#undef DEF_MSG_ADD_N
+#undef DEF_MUST_ADD_N
#undef DEF_MSG_REM_N
#undef DEF_MSG_ADD
+#undef DEF_MSG_MUST_ADD
#undef DEF_MSG_REM
void