diff options
Diffstat (limited to 'ref/api')
| -rw-r--r-- | ref/api/memory.html | 4 | ||||
| -rw-r--r-- | ref/api/sock.html | 58 |
2 files changed, 11 insertions, 51 deletions
diff --git a/ref/api/memory.html b/ref/api/memory.html index 9fa8b5bd..32319564 100644 --- a/ref/api/memory.html +++ b/ref/api/memory.html @@ -234,9 +234,7 @@ The memory will be 64-bit aligned. Note that the memory may have random data in it, just like with <code>malloc</code>.</p> <p>If memory cannot be allocated for any reason, then <code>NULL</code> will be returned. Applications that experience this should treat this like <a href="/api/errors.html#NNG_ENOMEM"><code>NNG_ENOMEM</code></a>.</p> -<p>Memory returned by <code>nng_alloc</code> can be used to hold message buffers, in which -case it can be directly passed to <a href="/api/sock.html#nng_send"><code>nng_send</code></a> using the flag <code>NNG_FLAG_ALLOC</code>. -Alternatively, it can be freed when no longer needed using <a href="/api/memory.html#deallocate-memory"><code>nng_free</code></a>.</p> +<p>Memory returned by <code>nng_alloc</code> should be freed when no longer needed using <a href="/api/memory.html#deallocate-memory"><code>nng_free</code></a>.</p> <div class="mdbook-alerts mdbook-alerts-important"> <p class="mdbook-alerts-title"> <span class="mdbook-alerts-icon"></span> 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 <a href="/proto/sub.html">SUB</a> sockets can only receive data and never It sends the content in <em>data</em>, as a message of <em>size</em> bytes. The <em>flags</em> is a bit mask made up of zero or more of the following values:</p> <ul> -<li> -<p><a name="a037"></a><code>NNG_FLAG_NONBLOCK</code>: <a name="NNG_FLAG_NONBLOCK"></a> +<li><a name="a037"></a><code>NNG_FLAG_NONBLOCK</code>: <a name="NNG_FLAG_NONBLOCK"></a> If the socket cannot accept more data at this time, it does not block, but returns immediately -with a status of <a href="/api/errors.html#NNG_EAGAIN"><code>NNG_EAGAIN</code></a>. If this flag is absent, the function will wait until data can be sent.</p> -</li> -<li> -<p><a name="a038"></a><code>NNG_FLAG_ALLOC</code>: <a name="NNG_FLAG_ALLOC"></a> -The <em>data</em> was allocated using <a href="/api/memory.html#allocate-memory"><code>nng_alloc</code></a> or was obtained from a call to <a href="/TODO.html"><code>nng_recv</code></a> also with -the <code>NNG_FLAG_ALLOC</code> flag. If this function succeeds, then it will dispose of the <em>data</em>, 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 <em>data</em> for use by the operation, before returning to the caller.</p> -</li> +with a status of <a href="/api/errors.html#NNG_EAGAIN"><code>NNG_EAGAIN</code></a>. If this flag is absent, the function will wait until data can be sent.</li> </ul> <div class="mdbook-alerts mdbook-alerts-note"> <p class="mdbook-alerts-title"> @@ -406,15 +396,6 @@ Furthermore, there is no guarantee that the message has actually been delivered. Finally, with some protocols, the semantic is implicitly <code>NNG_FLAG_NONBLOCK</code>, such as with <a href="/proto/pub.html">PUB</a> sockets, which are best-effort delivery only.</p> </div> -<div class="mdbook-alerts mdbook-alerts-important"> -<p class="mdbook-alerts-title"> - <span class="mdbook-alerts-icon"></span> - important -</p> -<p>When using <code>NNG_FLAG_ALLOC</code>, it is important that the value of <em>size</em> 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.</p> -</div> <h3 id="nng_sendmsg"><a class="header" href="#nng_sendmsg">nng_sendmsg</a></h3> <p>The <code>nng_sendmsg</code> function sends the <em>msg</em> over the socket <em>s</em>.</p> <p>If this function returns zero, then the socket will dispose of <em>msg</em> when the transmission is complete. @@ -451,7 +432,7 @@ this function instead of <a href="/api/sock.html#nng_send"><code>nng_send</code> int nng_recvmsg(nng_socket s, nng_msg **msgp, int flags); void nng_recv_aio(nng_socket s, nng_aio *aio); </code></pre> -<p>These functions (<a name="a039"></a><code>nng_recv</code>, <a name="a040"></a><code>nng_recvmsg</code>, and <a name="a041"></a><code>nng_recv_aio</code>) receive +<p>These functions (<a name="a038"></a><code>nng_recv</code>, <a name="a039"></a><code>nng_recvmsg</code>, and <a name="a040"></a><code>nng_recv_aio</code>) receive messages over the socket <em>s</em>. The differences in their behaviors are as follows.</p> <div class="mdbook-alerts mdbook-alerts-note"> <p class="mdbook-alerts-title"> @@ -466,33 +447,14 @@ while <a href="/proto/pub.html">PUB</a> sockets can only send data and never rec </div> <h3 id="nng_recv"><a class="header" href="#nng_recv">nng_recv</a></h3> <p>The <code>nng_recv</code> function is the simplest to use, but is the least efficient. -It receives the content in <em>data</em>, as a message size (in bytes) of up to the value stored in <em>sizep</em>, -unless the <code>NNG_FLAG_ALLOC</code> flag is set in <em>flags</em> (see below.)</p> +It receives the content in <em>data</em>, as a message size (in bytes) of up to the value stored in <em>sizep</em>.</p> <p>Upon success, the size of the message received will be stored in <em>sizep</em>.</p> <p>The <em>flags</em> is a bit mask made up of zero or more of the following values:</p> <ul> -<li> -<p><a name="a042"></a><code>NNG_FLAG_NONBLOCK</code>: +<li><a name="a041"></a><code>NNG_FLAG_NONBLOCK</code>: If the socket has no messages pending for reception at this time, it does not block, but returns immediately -with a status of <a href="/api/errors.html#NNG_EAGAIN"><code>NNG_EAGAIN</code></a>. If this flag is absent, the function will wait until data can be received.</p> -</li> -<li> -<p><a name="a043"></a><code>NNG_FLAG_ALLOC</code>: -Instead of receiving the message into <em>data</em>, 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 <em>data</em>. This provides a form -of zero-copy operation. The caller should dispose of the buffer using <a href="/api/memory.html#deallocate-memory"><code>nng_free</code></a> or by sending using -<a href="/api/sock.html#nng_send"><code>nng_send</code></a> with the <a href="/TODO.html"><code>NNG_FLAG_ALLOC</code></a> flag.</p> -</li> +with a status of <a href="/api/errors.html#NNG_EAGAIN"><code>NNG_EAGAIN</code></a>. If this flag is absent, the function will wait until data can be received.</li> </ul> -<div class="mdbook-alerts mdbook-alerts-important"> -<p class="mdbook-alerts-title"> - <span class="mdbook-alerts-icon"></span> - important -</p> -<p>When using <code>NNG_FLAG_ALLOC</code>, it is important that the value of <em>size</em> 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.</p> -</div> <h3 id="nng_recvmsg"><a class="header" href="#nng_recvmsg">nng_recvmsg</a></h3> <p>The <code>nng_recvmsg</code> function receives a message and stores a pointer to the <a href="/api/msg.html#message-structure"><code>nng_msg</code></a> for that message in <em>msgp</em>.</p> <p>The <em>flags</em> can contain the value <a href="/TODO.html"><code>NNG_FLAG_NONBLOCK</code></a>, 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 <a href="/a tip </p> <p>This function is preferred over <a href="/TODO.html"><code>nng_recv</code></a>, as it gives access to the message structure and eliminates both -a data copy and allocation, even when <code>nng_recv</code> is using <code>NNG_FLAG_ALLOC</code>.</p> +a data copy and allocation.</p> </div> <h3 id="nng_recv_aio"><a class="header" href="#nng_recv_aio">nng_recv_aio</a></h3> <p>The <code>nng_send_aio</code> function receives a message asynchronously, using the <a href="/api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>, over the socket <em>s</em>. @@ -530,12 +492,12 @@ this function instead of <a href="/TODO.html"><code>nng_recv</code></a> or <a hr int nng_socket_get_send_poll_fd(nng_socket s, int *fdp); </code></pre> <p>Sometimes it is necessary to integrate a socket into a <code>poll</code> or <code>select</code> driven -<a name="a044"></a>event loop. (Or, on Linux, <code>epoll</code>, or on BSD derived systems like macOS <code>kqueue</code>).</p> +<a name="a042"></a>event loop. (Or, on Linux, <code>epoll</code>, or on BSD derived systems like macOS <code>kqueue</code>).</p> <p>For these occasions, a suitable file descriptor for polling is provided by these two functions.</p> -<p>The <a name="a045"></a><code>nng_socket_get_recv_poll_fd</code> function obtains a file descriptor +<p>The <a name="a043"></a><code>nng_socket_get_recv_poll_fd</code> function obtains a file descriptor that will poll as readable when a message is ready for receiving for the socket.</p> -<p>The <a name="a046"></a><code>nng_socket_get_send_poll_fd</code> function obtains a file descriptor +<p>The <a name="a044"></a><code>nng_socket_get_send_poll_fd</code> function obtains a file descriptor that will poll as readable when the socket can accept a message for sending.</p> <p>These file descriptors should only be polled for readability, and no other operation performed on them. The socket will read from, or write to, |
