NN_MSG specifies pointer to pointer to buffer in nn_send and nn_sendmsg
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
diff --git a/doc/nn_allocmsg.3.txt b/doc/nn_allocmsg.3.txt
index 124b380..55d0e41 100644
--- a/doc/nn_allocmsg.3.txt
+++ b/doc/nn_allocmsg.3.txt
@@ -50,7 +50,7 @@
----
void *buf = nn_allocmsg (12, 0);
memcpy (buf, "Hello world!", 12);
-nn_send (s, buf, NN_MSG, 0);
+nn_send (s, &buf, NN_MSG, 0);
----
diff --git a/doc/nn_send.3.txt b/doc/nn_send.3.txt
index bfa1e62..03bfa2d 100644
--- a/doc/nn_send.3.txt
+++ b/doc/nn_send.3.txt
@@ -18,9 +18,9 @@
by 'buf' parameter to the socket 's'. The message will be 'len' bytes long.
Alternatively, to send a buffer allocated by linknanomsg:nn_allocmsg[3] function
-specify the buffer in 'buf' parameter and set 'len' parameter to _NN_MSG_. In
-this case the buffer will be deallocated by _nn_send_ function. Trying to
-deallocate it afterwards will result in undefined behaviour.
+set the buf paramter to point to the pointer to the buffer and 'len' parameter
+to _NN_MSG_ constant. In this case the buffer will be deallocated by _nn_send_
+function. Trying to deallocate it afterwards will result in undefined behaviour.
To which of the peers will the message be sent to is determined by
the particular socket type.
diff --git a/doc/nn_sendmsg.3.txt b/doc/nn_sendmsg.3.txt
index 8d1d448..88ad311 100644
--- a/doc/nn_sendmsg.3.txt
+++ b/doc/nn_sendmsg.3.txt
@@ -42,10 +42,10 @@
size_t iov_len;
Alternatively, to send a buffer allocated by linknanomsg:nn_allocmsg[3] function
-set 'iov_base' to the buffer pointer and 'iov_len' to _NN_MSG_. The buffer will
-be deallocated by _nn_send_ function. Trying to deallocate it
-afterwards will result in undefined behaviour. Also, scatter array in
-_nn_msghdr_ structure can contain only one element in this case.
+set 'iov_base' to point to the pointer to the buffer and 'iov_len' to _NN_MSG_
+constant. The buffer will be deallocated by _nn_send_ function. Trying to
+deallocate it afterwards will result in undefined behaviour. Also, scatter array
+in _nn_msghdr_ structure can contain only one element in this case.
To which of the peers will the message be sent to is determined by
the particular socket type.
diff --git a/src/core/ctx.c b/src/core/ctx.c
index 0ef6647..dfd2995 100644
--- a/src/core/ctx.c
+++ b/src/core/ctx.c
@@ -486,7 +486,7 @@
/* Create a message object. */
if (len == NN_MSG) {
- ch = ((struct nn_chunk*) buf) - 1;
+ ch = (*(struct nn_chunk**) buf) - 1;
rc = nn_chunk_check (ch);
if (nn_slow (rc < 0)) {
errno = -rc;
@@ -567,7 +567,7 @@
}
if (msghdr->msg_iovlen == 1 && msghdr->msg_iov [0].iov_len == NN_MSG) {
- ch = ((struct nn_chunk*) msghdr->msg_iov [0].iov_base) - 1;
+ ch = (*(struct nn_chunk**) msghdr->msg_iov [0].iov_base) - 1;
sz = nn_chunk_size (ch);
nn_msg_init_chunk (&msg, ch);
}
diff --git a/tests/msg.c b/tests/msg.c
index 925103b..5888a67 100644
--- a/tests/msg.c
+++ b/tests/msg.c
@@ -52,7 +52,7 @@
alloc_assert (buf1);
for (i = 0; i != 256; ++i)
buf1 [i] = (unsigned char) i;
- rc = nn_send (sc, buf1, NN_MSG, 0);
+ rc = nn_send (sc, &buf1, NN_MSG, 0);
errno_assert (rc >= 0);
nn_assert (rc == 256);
@@ -70,7 +70,7 @@
alloc_assert (buf1);
for (i = 0; i != 256; ++i)
buf1 [i] = (unsigned char) i;
- iov.iov_base = buf1;
+ iov.iov_base = &buf1;
iov.iov_len = NN_MSG;
memset (&hdr, 0, sizeof (hdr));
hdr.msg_iov = &iov;