summaryrefslogtreecommitdiff
path: root/ref/api/stream.html
diff options
context:
space:
mode:
authorgdamore <gdamore@users.noreply.github.com>2025-10-26 16:14:53 +0000
committergdamore <gdamore@users.noreply.github.com>2025-10-26 16:14:53 +0000
commitfd320bbff94ed12a9db8e2ccb250dfa0d333f04c (patch)
treef3e68e01e8699c601e22c239f1552d3f2715ea49 /ref/api/stream.html
parent294a01aa69296a7402b0dbafc38b88040f9c5450 (diff)
downloadnng-fd320bbff94ed12a9db8e2ccb250dfa0d333f04c.tar.gz
nng-fd320bbff94ed12a9db8e2ccb250dfa0d333f04c.tar.bz2
nng-fd320bbff94ed12a9db8e2ccb250dfa0d333f04c.zip
deploy: e0cb4377cc4d6fe50514e0b297e174fdde001bb6
Diffstat (limited to 'ref/api/stream.html')
-rw-r--r--ref/api/stream.html61
1 files changed, 37 insertions, 24 deletions
diff --git a/ref/api/stream.html b/ref/api/stream.html
index 4b4362da..d7ce936f 100644
--- a/ref/api/stream.html
+++ b/ref/api/stream.html
@@ -312,6 +312,14 @@ stream itself.</p>
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>
</div>
+<h2 id="stream-addresses"><a class="header" href="#stream-addresses">Stream Addresses</a></h2>
+<pre><code class="language-c">const nng_sockaddr *nng_stream_peer_addr(nng_stream *s);
+const nng_sockaddr *nng_stream_self_addr(nng_stream *s);
+</code></pre>
+<p><a name="a008"></a>
+<a name="a009"></a>
+These functions are used to obtain value of the local (self) or remote (peer) addresses
+for the given stream <em>s</em>.</p>
<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);
nng_err nng_stream_get_int(nng_stream *s, const char *opt, int *valp);
@@ -320,41 +328,46 @@ nng_err nng_stream_get_size(nng_stream *s, const char *opt, size_t *valp);
nng_err nng_stream_get_addr(nng_stream *s, const char *opt, nng_sockaddr *valp);
nng_err nng_stream_get_string(nng_stream *s, const char *opt, const char **valp);
</code></pre>
-<p><a name="a008"></a>
-<a name="a009"></a>
-<a name="a010"></a>
+<p><a name="a010"></a>
<a name="a011"></a>
<a name="a012"></a>
<a name="a013"></a>
+<a name="a014"></a>
+<a name="a015"></a>
These functions are used to obtain value of an option named <em>opt</em> from the stream <em>s</em>, and store it in the location
referenced by <em>valp</em>.</p>
<p>These functions access an option as a specific type. The transport layer will have details about which options
are available, and which type they may be accessed using.</p>
<p>In the case of <code>nng_stream_get_string</code>, the string pointer is only guaranteed to be valid while the
stream exists. Callers should make a copy of the data if required before closing the stream.</p>
+<blockquote>
+<p>[!NOTE]:
+The <code>nng_stream_get_addr</code> function is deprecated and will be removed. Use the
+<a href="../api/stream.html#stream-addresses"><code>nng_stream_peer_addr</code></a> or <a href="../api/stream.html#stream-addresses"><code>nng_stream_self_addr</code></a> functions instead.</p>
+</blockquote>
<h2 id="stream-factories"><a class="header" href="#stream-factories">Stream Factories</a></h2>
<pre><code class="language-c">typedef struct nng_stream_dialer nng_stream_dialer;
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
+<p><a name="a016"></a>
+The <a name="a017"></a><code>nng_stream_listener</code> object and <a name="a018"></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>
<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>.
+In a BSD socket implementation, this is the entity responsible for doing <a name="a019"></a><code>bind</code>, <a name="a020"></a><code>listen</code> and <a name="a021"></a><code>accept</code>.
Normally a listener may be used to accept multiple, possibly many, concurrent connections.</p>
<p>The <code>nng_stream_dialer</code> object is a handle to a dialer, which creates streams by making outgoing
connection requests. While there isn’t a specific BSD socket analogue, this can be thought of as a factory for TCP sockets
-created by opening them with <a name="a020"></a><code>socket</code> and then calling <a name="a021"></a><code>connect</code> on them.</p>
+created by opening them with <a name="a022"></a><code>socket</code> and then calling <a name="a023"></a><code>connect</code> on them.</p>
<h2 id="creating-a-stream-factory"><a class="header" href="#creating-a-stream-factory">Creating a Stream Factory</a></h2>
<pre><code class="language-c">nng_err nng_stream_dialer_alloc(nng_stream_dialer **dialerp, const char *url);
nng_err nng_stream_dialer_alloc_url(nng_stream_dialer **dialerp, const nng_url *url);
nng_err nng_stream_listener_alloc(nng_stream_listener **lstenerp, const char *url);
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
+<p>The <a name="a024"></a><code>nng_stream_dialer_alloc</code> and <a name="a025"></a><code>nng_stream_dialer_alloc_url</code> functions create a stream dialer, associated the
+<a name="a026"></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
+<p>The <a name="a027"></a><code>nng_stream_listener_alloc</code> and <a name="a028"></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
<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>
@@ -370,14 +383,14 @@ void nng_stream_listener_close(nng_stream_listener *listener);
void nng_stream_listener_stop(nng_stream_listener *listener);
void nng_stream_listener_free(nng_stream_listener *listener);
</code></pre>
-<p>The <a name="a027"></a><code>nng_stream_dialer_close</code> and <a name="a028"></a><code>nng_stream_listener_close</code> functions close the stream <em>dialer</em> or <em>listener</em>,
+<p>The <a name="a029"></a><code>nng_stream_dialer_close</code> and <a name="a030"></a><code>nng_stream_listener_close</code> functions close the stream <em>dialer</em> or <em>listener</em>,
preventing it from creating new connections.
This will generally include closing any underlying file used for creating such connections.
However, some requests may still be pending when this function returns, as it does not wait for the shutdown to complete.</p>
-<p>The <a name="a029"></a><code>nng_stream_dialer_stop</code> and <a name="a030"></a><code>nng_stream_listener_stop</code> functions performs the same action,
+<p>The <a name="a031"></a><code>nng_stream_dialer_stop</code> and <a name="a032"></a><code>nng_stream_listener_stop</code> functions performs the same action,
but also wait until all outstanding requests are serviced, and the <em>dialer</em> or <em>listener</em> is completely stopped.
Because they blocks, these functions must not be called in contexts where blocking is not allowed.</p>
-<p>The <a name="a031"></a><code>nng_stream_dialer_free</code> and <a name="a032"></a><code>nng_stream_listener_free</code> function performs the same action as
+<p>The <a name="a033"></a><code>nng_stream_dialer_free</code> and <a name="a034"></a><code>nng_stream_listener_free</code> function performs the same action as
<code>nng_stream_dialer_stop</code> or <code>nng_stream_listener_stop</code>, but also deallocates the <em>dialer</em> or <em>listener</em>, and any associated resources.</p>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
@@ -390,7 +403,7 @@ 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>.
+<p>The <a name="a035"></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">
@@ -424,10 +437,10 @@ stream = nng_aio_get_output(aio, 0);
<pre><code class="language-c">nng_err nng_stream_listener_listen(nng_stream_listener *listener);
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
+<p>Accepting incoming connections is performed in two steps. The first step, <a name="a036"></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>.
+<p>In the second step, <a name="a037"></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>
@@ -482,9 +495,7 @@ nng_err nng_stream_listener_set_ms(nng_stream_listener *listener, const char *op
nng_err nng_stream_listener_set_size(nng_stream_listener *listener, const char *opt, size_t val);
nng_err nng_stream_listener_set_string(nng_stream_listener *listener, const char *opt, const char *val);
</code></pre>
-<p><a name="a036"></a>
-<a name="a037"></a>
-<a name="a038"></a>
+<p><a name="a038"></a>
<a name="a039"></a>
<a name="a040"></a>
<a name="a041"></a>
@@ -506,6 +517,8 @@ nng_err nng_stream_listener_set_string(nng_stream_listener *listener, const char
<a name="a057"></a>
<a name="a058"></a>
<a name="a059"></a>
+<a name="a060"></a>
+<a name="a061"></a>
These functions are used to retrieve or change the value of an option named <em>opt</em> from the stream <em>dialer</em> or <em>listener</em>.
The <code>nng_stream_dialer_get_</code> and <code>nng_stream_listener_get_</code> function families retrieve the value, and store it in the location <em>valp</em> references.
The <code>nng_stream_dialer_set_</code> and <code>nng_stream_listener_set_</code> function families change the value for the <em>dialer</em> or <em>listener</em>, taking it from <em>val</em>.</p>
@@ -518,9 +531,9 @@ 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="a062"></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,
+In this case, the application supplies the file descriptor or <code>SOCKET</code> object using the <a name="a063"></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>
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
@@ -548,13 +561,13 @@ 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.
-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
+<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="a064"></a>TLS parameters.
+The <a name="a065"></a><code>nng_stream_dialer_set_tls</code> and <a name="a066"></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>
<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>.
+configured) can be obtained with the <a name="a067"></a><code>nng_stream_dialer_get_tls</code> and <a name="a068"></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>
<div class="mdbook-alerts mdbook-alerts-note">
<p class="mdbook-alerts-title">