diff options
| author | gdamore <gdamore@users.noreply.github.com> | 2025-10-09 01:22:20 +0000 |
|---|---|---|
| committer | gdamore <gdamore@users.noreply.github.com> | 2025-10-09 01:22:20 +0000 |
| commit | edd3b6bc34f211bd3d58642d0c69ce1b5bb9dc3b (patch) | |
| tree | f3396cdaec643fb87365b5f92df4f92e6644b075 /ref/api/stream.html | |
| parent | ecdd21b5f4bd29bc1a88d276a9c8015dd100063b (diff) | |
| download | nng-edd3b6bc34f211bd3d58642d0c69ce1b5bb9dc3b.tar.gz nng-edd3b6bc34f211bd3d58642d0c69ce1b5bb9dc3b.tar.bz2 nng-edd3b6bc34f211bd3d58642d0c69ce1b5bb9dc3b.zip | |
deploy: 9c834956456924df7c885ab8b79573721acaff5c
Diffstat (limited to 'ref/api/stream.html')
| -rw-r--r-- | ref/api/stream.html | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/ref/api/stream.html b/ref/api/stream.html index 25ca66bc..fd8de778 100644 --- a/ref/api/stream.html +++ b/ref/api/stream.html @@ -267,26 +267,26 @@ using these Streams APIs.</p> note </p> <p>The <code>nng_stream</code> object is used for raw byte stream connections, and -should not be confused with a <a href="../../api/pipe.html">pipe</a> object created on a <a href="../../TODO.html">socket</a> using -the <a href="../../TODO.html"><code>nng_listen</code></a>, <a href="../../TODO.html"><code>nng_dial</code></a> or related functions.</p> +should not be confused with a <a href="../api/pipe.html">pipe</a> object created on a <a href="../TODO.html">socket</a> using +the <a href="../TODO.html"><code>nng_listen</code></a>, <a href="../TODO.html"><code>nng_dial</code></a> or related functions.</p> </div> <h2 id="sending-and-receiving-data"><a class="header" href="#sending-and-receiving-data">Sending and Receiving Data</a></h2> <pre><code class="language-c">void nng_stream_send(nng_stream *s, nng_aio *aio); void nng_stream_recv(nng_stream *s, nng_aio *aio); </code></pre> <p>The <a name="a003"></a><code>nng_stream_send</code> function starts sending data asynchronously over the stream <em>s</em>. -The data is sent from the scatter/gather vector located in the <a href="../../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>, -which must have been previously set using <a href="../../api/aio.html#scatter-gather-vectors"><code>nng_aio_set_iov</code></a>.</p> +The data is sent from the scatter/gather vector located in the <a href="../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>, +which must have been previously set using <a href="../api/aio.html#scatter-gather-vectors"><code>nng_aio_set_iov</code></a>.</p> <p>The <a name="a004"></a><code>nng_stream_recv</code> function starts receiving data [asynchronously over the stream <em>s</em> -into the scatter/gather vector located in the <a href="../../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>, -which must have been previously set using <a href="../../api/aio.html#scatter-gather-vectors"><code>nng_aio_set_iov</code></a>.</p> +into the scatter/gather vector located in the <a href="../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>, +which must have been previously set using <a href="../api/aio.html#scatter-gather-vectors"><code>nng_aio_set_iov</code></a>.</p> <p>These functions return immediately, with no return value. Completion of the operation is signaled via the <em>aio</em>, and the final -result may be obtained via <a href="../../api/aio.html#result-of-operation"><code>nng_aio_result</code></a>.</p> +result may be obtained via <a href="../api/aio.html#result-of-operation"><code>nng_aio_result</code></a>.</p> <p>The I/O operation may complete as soon as at least one byte has been transferred, or an error has occurred. Therefore, the number of bytes transferred may be less than requested. -The actual number of bytes transferred can be determined with <a href="../../api/aio.html#result-of-operation"><code>nng_aio_count</code></a>.</p> +The actual number of bytes transferred can be determined with <a href="../api/aio.html#result-of-operation"><code>nng_aio_count</code></a>.</p> <h2 id="closing-a-stream"><a class="header" href="#closing-a-stream">Closing a Stream</a></h2> <pre><code class="language-c">void nng_stream_close(nng_stream *s); void nng_stream_stop(nng_stream *s); @@ -294,8 +294,8 @@ void nng_stream_free(nng_stream *s); </code></pre> <p>The <a name="a005"></a><code>nng_stream_close</code> function closes a stream, but does not destroy it. This function returns immediately. Operations that are pending against the stream, such -as <a href="../../api/stream.html#sending-and-receiving-data"><code>nng_stream_send</code></a> or <a href="../../api/stream.html#sending-and-receiving-data"><code>nng_stream_recv</code></a> operations will be canceled asynchronously, if possible. -Those operations will result in <a href="../../api/errors.html#NNG_ECLOSED"><code>NNG_ECLOSED</code></a>.</p> +as <a href="../api/stream.html#sending-and-receiving-data"><code>nng_stream_send</code></a> or <a href="../api/stream.html#sending-and-receiving-data"><code>nng_stream_recv</code></a> operations will be canceled asynchronously, if possible. +Those operations will result in <a href="../api/errors.html#NNG_ECLOSED"><code>NNG_ECLOSED</code></a>.</p> <p>The <a name="a006"></a><code>nng_stream_stop</code> function not only closes the stream, but waits for any operations pending against it to complete, and for any underlying asynchronous registered I/O to be fully deregistered. As some systems use separate threads for asynchronous I/O, stopping the stream is necessary before those @@ -310,7 +310,7 @@ stream itself.</p> </p> <p>Because <code>nng_stream_stop</code> and <code>nng_stream_free</code> both may block waiting for outstanding I/O to complete or be aborted, these functions are unsafe to call from functions that may not block, such as the -completion function registered with an <a href="../../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> when it is created.</p> +completion function registered with an <a href="../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> when it is created.</p> </div> <h2 id="getting-stream-options"><a class="header" href="#getting-stream-options">Getting Stream Options</a></h2> <pre><code class="language-c">nng_err nng_stream_get_bool(nng_stream *s, const char *opt, bool *valp); @@ -338,7 +338,7 @@ typedef struct nng_stream_listener nng_stream_listener; </code></pre> <p><a name="a014"></a> The <a name="a015"></a><code>nng_stream_listener</code> object and <a name="a016"></a><code>nng_stream_listener</code> objects can be thought of as factories that -create <a href="../../api/stream.html#stream-type"><code>nng_stream</code></a> streams.</p> +create <a href="../api/stream.html#stream-type"><code>nng_stream</code></a> streams.</p> <p>The <code>nng_stream_listener</code> object a handle to a listener, which creates streams by accepting incoming connection requests. In a BSD socket implementation, this is the entity responsible for doing <a name="a017"></a><code>bind</code>, <a name="a018"></a><code>listen</code> and <a name="a019"></a><code>accept</code>. Normally a listener may be used to accept multiple, possibly many, concurrent connections.</p> @@ -352,10 +352,10 @@ nng_err nng_stream_listener_alloc(nng_stream_listener **lstenerp, const char *ur nng_err nng_stream_listener_alloc_url(nng_stream_listener **listenerp, const nng_url *url); </code></pre> <p>The <a name="a022"></a><code>nng_stream_dialer_alloc</code> and <a name="a023"></a><code>nng_stream_dialer_alloc_url</code> functions create a stream dialer, associated the -<a name="a024"></a>URL specified by <em>url</em> represented as a string, or as an <a href="../../api/url.html#url-structure"><code>nng_url</code></a> object, respectively. The dialer is returned in the location +<a name="a024"></a>URL specified by <em>url</em> represented as a string, or as an <a href="../api/url.html#url-structure"><code>nng_url</code></a> object, respectively. The dialer is returned in the location <em>dialerp</em> references.</p> <p>The <a name="a025"></a><code>nng_stream_listener_alloc</code> and <a name="a026"></a><code>nng_stream_listener_alloc_url</code> functions create a stream listener, associated the -URL specified by <em>url</em> represented as a string, or as an <a href="../../api/url.html#url-structure"><code>nng_url</code></a> object, respectively. The listener is returned in the location +URL specified by <em>url</em> represented as a string, or as an <a href="../api/url.html#url-structure"><code>nng_url</code></a> object, respectively. The listener is returned in the location <em>listenerp</em> references.</p> <h3 id="example-1-creating-a-tcp-listener"><a class="header" href="#example-1-creating-a-tcp-listener">Example 1: Creating a TCP Listener</a></h3> <p>This shows creating a TCP listener that listens on <code>INADDR_ANY</code>, port 444.</p> @@ -390,15 +390,15 @@ callbacks are running that could reference an object after it is deallocated.</p <h2 id="making-outgoing-connections"><a class="header" href="#making-outgoing-connections">Making Outgoing Connections</a></h2> <pre><code class="language-c">void nng_stream_dialer_dial(nng_stream_dialer *dialer, nng_aio *aio); </code></pre> -<p>The <a name="a033"></a><code>nng_stream_dialer_dial</code> initiates an outgoing connection asynchronously, using the <a href="../../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>. -If it successfully establishes a connection, it creates an <a href="../../api/stream.html#stream-type"><code>nng_stream</code></a>, which can be obtained as the first -output result on <em>aio</em> using the <a href="../../api/aio.html#inputs-and-outputs"><code>nng_aio_get_output</code></a> function with index zero.</p> +<p>The <a name="a033"></a><code>nng_stream_dialer_dial</code> initiates an outgoing connection asynchronously, using the <a href="../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>. +If it successfully establishes a connection, it creates an <a href="../api/stream.html#stream-type"><code>nng_stream</code></a>, which can be obtained as the first +output result on <em>aio</em> using the <a href="../api/aio.html#inputs-and-outputs"><code>nng_aio_get_output</code></a> function with index zero.</p> <div class="mdbook-alerts mdbook-alerts-tip"> <p class="mdbook-alerts-title"> <span class="mdbook-alerts-icon"></span> tip </p> -<p>An <a href="../../api/stream.html#stream-factories"><code>nng_stream_dialer</code></a> can be used multiple times to make multiple concurrent connection requests, but +<p>An <a href="../api/stream.html#stream-factories"><code>nng_stream_dialer</code></a> can be used multiple times to make multiple concurrent connection requests, but they all must reference the same URL.</p> </div> <h3 id="example-3-connecting-to-google"><a class="header" href="#example-3-connecting-to-google">Example 3: Connecting to Google</a></h3> @@ -426,12 +426,12 @@ void nng_stream_listener_accept(nng_stream_listener *listener, nng_aio *aio); </code></pre> <p>Accepting incoming connections is performed in two steps. The first step, <a name="a034"></a><code>nng_stream_listener_listen</code> is to setup for listening. For a TCP implementation of this, for example, this would perform the <code>bind</code> and the <code>listen</code> steps. This will bind -to the address represented by the URL that was specific when the listener was created with <a href="../../api/stream.html#creating-a-stream-factory"><code>nng_stream_listener_alloc</code></a>.</p> -<p>In the second step, <a name="a035"></a><code>nng_stream_listener_accept</code> accepts an incoming connection on <em>listener</em> asynchronously, using the <a href="../../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>. -If an incoming connection is accepted, it will be represented as an <a href="../../api/stream.html#stream-type"><code>nng_stream</code></a>, which can be obtained from the <em>aio</em> as the first -output result using the <a href="../../api/aio.html#inputs-and-outputs"><code>nng_aio_get_output</code></a> function with index zero.</p> +to the address represented by the URL that was specific when the listener was created with <a href="../api/stream.html#creating-a-stream-factory"><code>nng_stream_listener_alloc</code></a>.</p> +<p>In the second step, <a name="a035"></a><code>nng_stream_listener_accept</code> accepts an incoming connection on <em>listener</em> asynchronously, using the <a href="../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>. +If an incoming connection is accepted, it will be represented as an <a href="../api/stream.html#stream-type"><code>nng_stream</code></a>, which can be obtained from the <em>aio</em> as the first +output result using the <a href="../api/aio.html#inputs-and-outputs"><code>nng_aio_get_output</code></a> function with index zero.</p> <h3 id="example-3-accepting-an-inbound-stream"><a class="header" href="#example-3-accepting-an-inbound-stream">Example 3: Accepting an Inbound Stream</a></h3> -<p>For clarity this example uses a synchronous approach using <a href="../../api/aio.html#wait-for-completion"><code>nng_aio_wait</code></a>, but a typical server application +<p>For clarity this example uses a synchronous approach using <a href="../api/aio.html#wait-for-completion"><code>nng_aio_wait</code></a>, but a typical server application would most likely use a callback to accept the incoming stream, and start another instance of <code>nng_stream_listener_accept</code>.</p> <pre><code class="language-c">nng_aio *aio; nng_listener *listener; @@ -518,10 +518,10 @@ need not retain the value referenced once the function returns.</p> <p>In the case of <code>nng_stream_dialer_set_addr</code> and <code>nng_stream_listener_set_addr</code>, the contents of <em>addr</em> are copied if necessary, so that the caller need not retain the value referenced once the function returns.</p> <h3 id="example-4-socket-activation"><a class="header" href="#example-4-socket-activation">Example 4: Socket Activation<a name="socket-activation"></a></a></h3> -<p>Some <a href="../../api/stream.html#stream-factories"><code>nng_stream_listener</code></a> objects, depending on the underlying transport and platform, can support a technique known as “<a name="a060"></a>socket activation”, +<p>Some <a href="../api/stream.html#stream-factories"><code>nng_stream_listener</code></a> objects, depending on the underlying transport and platform, can support a technique known as “<a name="a060"></a>socket activation”, where the file descriptor used for listening and accepting is supplied externally, such as by a system service manager. In this case, the application supplies the file descriptor or <code>SOCKET</code> object using the <a name="a061"></a><code>NNG_OPT_LISTEN_FD</code> option, -instead of calling <a href="../../api/stream.html#accepting-incoming-connections"><code>nng_stream_listener_listen</code></a>.</p> +instead of calling <a href="../api/stream.html#accepting-incoming-connections"><code>nng_stream_listener_listen</code></a>.</p> <div class="mdbook-alerts mdbook-alerts-tip"> <p class="mdbook-alerts-title"> <span class="mdbook-alerts-icon"></span> @@ -548,21 +548,21 @@ nng_err nng_stream_dialer_set_tls(nng_stream_listener *dialer, nng_tls_config *t nng_err nng_stream_listener_get_tls(nng_stream_listener *listener, nng_tls_config **tlsp); nng_err nng_stream_listener_set_tls(nng_stream_listener *listener, nng_tls_config *tls); </code></pre> -<p>Both <a href="../../api/stream.html#stream-factories"><code>nng_stream_dialer</code></a> and <a href="../../api/stream.html#stream-factories"><code>nng_stream_listener</code></a> objects may support configuration of <a name="a062"></a>TLS parameters. +<p>Both <a href="../api/stream.html#stream-factories"><code>nng_stream_dialer</code></a> and <a href="../api/stream.html#stream-factories"><code>nng_stream_listener</code></a> objects may support configuration of <a name="a062"></a>TLS parameters. The <a name="a063"></a><code>nng_stream_dialer_set_tls</code> and <a name="a064"></a><code>nng_stream_listener_set_tls</code> functions support setting the -configuration of a <a href="../../TODO.html"><code>nng_tls_config</code></a> object supplied by <em>tls</em> on <em>dialer</em> or <em>listener</em>. -This must be performed before the <em>listener</em> starts listening with <a href="../../api/stream.html#accepting-incoming-connections"><code>nng_stream_listener_listen</code></a>, or the dialer starts an outgoing connection -as a result of <a href="../../api/stream.html#making-outgoing-connections"><code>nng_stream_dialer_dial</code></a>.</p> +configuration of a <a href="../TODO.html"><code>nng_tls_config</code></a> object supplied by <em>tls</em> on <em>dialer</em> or <em>listener</em>. +This must be performed before the <em>listener</em> starts listening with <a href="../api/stream.html#accepting-incoming-connections"><code>nng_stream_listener_listen</code></a>, or the dialer starts an outgoing connection +as a result of <a href="../api/stream.html#making-outgoing-connections"><code>nng_stream_dialer_dial</code></a>.</p> <p>The configuration object that was previously established (which may be a default if one was not explicitly configured) can be obtained with the <a name="a065"></a><code>nng_stream_dialer_get_tls</code> and <a name="a066"></a><code>nng_stream_listener_get_tls</code>. -They will return a pointer to the <a href="../../TODO.html"><code>nng_tls_config</code></a> object in question at the location referenced by <em>tlsp</em>.</p> +They will return a pointer to the <a href="../TODO.html"><code>nng_tls_config</code></a> object in question at the location referenced by <em>tlsp</em>.</p> <div class="mdbook-alerts mdbook-alerts-note"> <p class="mdbook-alerts-title"> <span class="mdbook-alerts-icon"></span> note </p> <p>TLS configuration cannot be changed once it has started being used by a listener or dialer. This applies to -both configuring a different TLS configuration object, as well as mutating the existing <a href="../../TODO.html"><code>nng_tls_config</code></a> object.</p> +both configuring a different TLS configuration object, as well as mutating the existing <a href="../TODO.html"><code>nng_tls_config</code></a> object.</p> </div> <!-- NOTE: This assumes that any page referencing this is located in a directory two levels down. Meaning ./api/somefile.md or |
