From bb67a9767078bd98add53ead0e0e2f1390cfb539 Mon Sep 17 00:00:00 2001
From: gdamore malloc.
If memory cannot be allocated for any reason, then NULL will be returned.
Applications that experience this should treat this like NNG_ENOMEM.
Memory returned by nng_alloc can be used to hold message buffers, in which
-case it can be directly passed to nng_send using the flag NNG_FLAG_ALLOC.
-Alternatively, it can be freed when no longer needed using nng_free.
Memory returned by nng_alloc should be freed when no longer needed using nng_free.
diff --git a/ref/api/sock.html b/ref/api/sock.html index 5ac982b7..215726e0 100644 --- a/ref/api/sock.html +++ b/ref/api/sock.html @@ -381,19 +381,9 @@ while SUB sockets can only receive data and never It sends the content in data, as a message of size bytes. The flags is a bit mask made up of zero or more of the following values:
NNG_FLAG_NONBLOCK:
If the socket cannot accept more data at this time, it does not block, but returns immediately
-with a status of NNG_EAGAIN. If this flag is absent, the function will wait until data can be sent.
-NNG_FLAG_ALLOC:
-The data was allocated using nng_alloc or was obtained from a call to nng_recv also with
-the NNG_FLAG_ALLOC flag. If this function succeeds, then it will dispose of the data, deallocating it
-once the transmission is complete. If this function returns a non-zero status, the caller retains the responsibility
-of disposing the data. The benefit of this flag is that it can eliminate a data copy and allocation. Without the flag
-the socket will make a duplicate copy of data for use by the operation, before returning to the caller.
NNG_EAGAIN. If this flag is absent, the function will wait until data can be sent.
@@ -406,15 +396,6 @@ Furthermore, there is no guarantee that the message has actually been delivered.
Finally, with some protocols, the semantic is implicitly NNG_FLAG_NONBLOCK,
such as with PUB sockets, which are best-effort delivery only.
- - important -
-When using NNG_FLAG_ALLOC, it is important that the value of size match the actual allocated size of the data.
-Using an incorrect size results in unspecified behavior, which may include heap corruption, program crashes,
-or other undesirable effects.
The nng_sendmsg function sends the msg over the socket s.
If this function returns zero, then the socket will dispose of msg when the transmission is complete.
@@ -451,7 +432,7 @@ this function instead of These functions ( These functions (
@@ -466,33 +447,14 @@ while PUB sockets can only send data and never rec
The nng_send
int nng_recvmsg(nng_socket s, nng_msg **msgp, int flags);
void nng_recv_aio(nng_socket s, nng_aio *aio);
-nng_recv, nng_recvmsg, and nng_recv_aio) receive
+nng_recv, nng_recvmsg, and nng_recv_aio) receive
messages over the socket s. The differences in their behaviors are as follows.nng_recv
nng_recv function is the simplest to use, but is the least efficient.
-It receives the content in data, as a message size (in bytes) of up to the value stored in sizep,
-unless the NNG_FLAG_ALLOC flag is set in flags (see below.)
Upon success, the size of the message received will be stored in sizep.
The flags is a bit mask made up of zero or more of the following values:
NNG_FLAG_NONBLOCK:
If the socket has no messages pending for reception at this time, it does not block, but returns immediately
-with a status of NNG_EAGAIN. If this flag is absent, the function will wait until data can be received.
-NNG_FLAG_ALLOC:
-Instead of receiving the message into data, a new buffer will be allocated exactly large enough to hold
-the message. A pointer to that buffer will be stored at the location specified by data. This provides a form
-of zero-copy operation. The caller should dispose of the buffer using nng_free or by sending using
-nng_send with the NNG_FLAG_ALLOC flag.
NNG_EAGAIN. If this flag is absent, the function will wait until data can be received.
- - important -
-When using NNG_FLAG_ALLOC, it is important that the value of size match the actual allocated size of the data.
-Using an incorrect size results in unspecified behavior, which may include heap corruption, program crashes,
-or other undesirable effects.
The nng_recvmsg function receives a message and stores a pointer to the nng_msg for that message in msgp.
The flags can contain the value NNG_FLAG_NONBLOCK, indicating that the function should not wait if the socket
@@ -503,7 +465,7 @@ has no messages available to receive. In such a case, it will return nng_recv, as it gives access to the message structure and eliminates both
-a data copy and allocation, even when nng_recv is using NNG_FLAG_ALLOC.
The Sometimes it is necessary to integrate a socket into a nng_send_aio function receives a message asynchronously, using the nng_aio aio, over the socket s.
@@ -530,12 +492,12 @@ this function instead of nng_recv or
poll or select driven
-event loop. (Or, on Linux, epoll, or on BSD derived systems like macOS kqueue).epoll, or on BSD derived systems like macOS kqueue).
For these occasions, a suitable file descriptor for polling is provided by these two functions.
-The nng_socket_get_recv_poll_fd function obtains a file descriptor
+
The nng_socket_get_recv_poll_fd function obtains a file descriptor
that will poll as readable when a message is ready for receiving for the socket.
The nng_socket_get_send_poll_fd function obtains a file descriptor
+
The nng_socket_get_send_poll_fd function obtains a file descriptor
that will poll as readable when the socket can accept a message for sending.
These file descriptors should only be polled for readability, and no other operation performed on them. The socket will read from, or write to, -- cgit v1.2.3-70-g09d2