aboutsummaryrefslogtreecommitdiff
path: root/src/core/message.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-01-19 11:06:55 -0800
committerGarrett D'Amore <garrett@damore.org>2020-01-20 12:59:45 -0800
commit8abf75857e8993a25e50d07bdd6d9628f028d7cc (patch)
tree15f89948cfa97a44130db224e9e27e51a00e5f76 /src/core/message.h
parentb2ba35251986d2754de5f0f274ee7cbf577223e1 (diff)
downloadnng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.tar.gz
nng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.tar.bz2
nng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.zip
fixes #1156 Message cloning could help reduce copies a lot
This introduces reference counting on messages to reduce the data copies. This should have a marked improvement when moving large messages through the system, or when publishing to many subscribers. For some transports, when using large messages, the copy time can be the dominant factor. Note that when a message is actually shared, inproc will still perform an extra copy in order to ensure that it can modify the headers. This will unfortunately always be the case with REQ, as the REQ protocol keeps a copy of the original message so it can retry.
Diffstat (limited to 'src/core/message.h')
-rw-r--r--src/core/message.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/core/message.h b/src/core/message.h
index d09a18dc..53b644c4 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -60,6 +60,20 @@ extern uint64_t nni_msg_header_chop_u64(nni_msg *);
extern void nni_msg_set_pipe(nni_msg *, uint32_t);
extern uint32_t nni_msg_get_pipe(const nni_msg *);
+// Reference counting messages. This allows the same message to be
+// cheaply reused instead of copied over and over again. Callers of
+// this functionality MUST be certain to use nni_msg_unique() before
+// passing a message out of their control (e.g. to user programs.)
+// Failure to do so will likely result in corruption.
+extern void nni_msg_clone(nni_msg *);
+extern nni_msg *nni_msg_unique(nni_msg *);
+// nni_msg_pull_up ensures that the message is unique, and that any
+// header present is "pulled up" into the message body. If the function
+// cannot do this for any reason (out of space in the body), then NULL
+// is returned. It is the responsibility of the caller to free the
+// original message in that case (same semantics as realloc).
+extern nni_msg *nni_msg_pull_up(nni_msg *);
+
// These should only be used when the transport or protocol is absolutely
// certain that there is adequate room. There is about 32 bytes of
// header and trailer space for a newly allocated message, and transports