From 97058f23b30e703df8f8d1a11512000ca6d199fc Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:06:09 -0800 Subject: [PATCH 1/7] docs: minor cleanups --- docs/man/libnng.3.adoc | 7 ------- docs/man/man3http.desc | 13 ------------- docs/man/man3http.sect | 1 - docs/man/nng.7.adoc | 1 - 4 files changed, 22 deletions(-) delete mode 100644 docs/man/man3http.desc delete mode 100644 docs/man/man3http.sect diff --git a/docs/man/libnng.3.adoc b/docs/man/libnng.3.adoc index eddc434fc..8a4610790 100644 --- a/docs/man/libnng.3.adoc +++ b/docs/man/libnng.3.adoc @@ -35,13 +35,6 @@ Listeners accept incoming connection requests, and dialers make them. |xref:nng_listener_id.3.adoc[nng_listener_id()]|get numeric listener identifier |xref:nng_listener_set.3.adoc[nng_listener_set()]|set listener option |xref:nng_listener_start.3.adoc[nng_listener_start()]|start listener -|xref:nng_pipe_close.3.adoc[nng_pipe_close()]|close pipe -|xref:nng_pipe_dialer.3.adoc[nng_pipe_dialer()]|return dialer that created pipe -|xref:nng_pipe_get.3.adoc[nng_pipe_get()]|get pipe option -|xref:nng_pipe_id.3.adoc[nng_pipe_id()]|get numeric pipe identifier -|xref:nng_pipe_listener.3.adoc[nng_pipe_listener()]|return listener that created pipe -|xref:nng_pipe_notify.3.adoc[nng_pipe_notify()]|register pipe notification callback -|xref:nng_pipe_socket.3.adoc[nng_pipe_socket()]|return owning socket for pipe |=== === Asynchronous Operations diff --git a/docs/man/man3http.desc b/docs/man/man3http.desc deleted file mode 100644 index b6659eb87..000000000 --- a/docs/man/man3http.desc +++ /dev/null @@ -1,13 +0,0 @@ -This section documents supplemental HTTP (HyperText Transport Protocol) -support functions that are available. - -These functions can be used in conjunction with the -xref:nng_ws.7.adoc[WebSocket] transport for Scalability Protocols, or they -may be used to construct other types of applications that communicate -using HTTP. - -It is also possible to combine the two, such that an HTTP server providing -static or dynamic content can also be used to host one or more Scalability -Protocols sockets. - -NOTE: At present NNG only supports HTTP/1.0 and HTTP/1.1. diff --git a/docs/man/man3http.sect b/docs/man/man3http.sect deleted file mode 100644 index 3ae1b8134..000000000 --- a/docs/man/man3http.sect +++ /dev/null @@ -1 +0,0 @@ -Supplemental HTTP Functions diff --git a/docs/man/nng.7.adoc b/docs/man/nng.7.adoc index e1680e1a5..936d2dc6a 100644 --- a/docs/man/nng.7.adoc +++ b/docs/man/nng.7.adoc @@ -67,7 +67,6 @@ other languages please check the http://nanomsg.org/[website]. === Transports [horizontal] -xref:nng_inproc.7.adoc[nng_inproc(7)]:: Intra-process transport xref:nng_ipc.7.adoc[nng_ipc(7)]:: Inter-process transport xref:nng_socket.7.adoc[nng_socket(7)]:: BSD socket transport xref:nng_tls.7.adoc[nng_tls(7)]:: TLSv1.2 over TCP transport From 8ff8fa5077164f2ec9dd2f02b7f9f5b66f225db6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:12:16 -0800 Subject: [PATCH 2/7] aio: more nng_err updates --- docs/man/nng_aio_finish.3.adoc | 1 - docs/man/nng_aio_get_input.3.adoc | 1 - docs/man/nng_aio_reset.3.adoc | 1 - docs/man/nng_aio_set_output.3.adoc | 1 - docs/man/nng_aio_start.3.adoc | 1 - docs/ref/api/aio.md | 2 +- include/nng/nng.h | 2 +- src/core/aio.c | 14 +++++++------- src/core/aio.h | 12 ++++++------ src/nng.c | 4 ++-- 10 files changed, 17 insertions(+), 22 deletions(-) diff --git a/docs/man/nng_aio_finish.3.adoc b/docs/man/nng_aio_finish.3.adoc index bb0791b88..a4855ec8e 100644 --- a/docs/man/nng_aio_finish.3.adoc +++ b/docs/man/nng_aio_finish.3.adoc @@ -51,7 +51,6 @@ None. == SEE ALSO [.text-left] -xref:nng_aio_alloc.3.adoc[nng_aio_alloc(3)], xref:nng_aio_reset.3.adoc[nng_aio_reset(3)], xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], xref:nng_aio_start.3.adoc[nng_aio_start(3)], diff --git a/docs/man/nng_aio_get_input.3.adoc b/docs/man/nng_aio_get_input.3.adoc index 204ec4354..ef3313128 100644 --- a/docs/man/nng_aio_get_input.3.adoc +++ b/docs/man/nng_aio_get_input.3.adoc @@ -45,7 +45,6 @@ None. == SEE ALSO [.text-left] -xref:nng_aio_alloc.3.adoc[nng_aio_alloc(3)], xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], xref:nng_aio_set_input.3.adoc[nng_aio_set_input(3)], xref:nng_aio_result.3.adoc[nng_aio_result(3)], diff --git a/docs/man/nng_aio_reset.3.adoc b/docs/man/nng_aio_reset.3.adoc index cb0feec03..8f4ba514c 100644 --- a/docs/man/nng_aio_reset.3.adoc +++ b/docs/man/nng_aio_reset.3.adoc @@ -33,7 +33,6 @@ users of the _aio_ should not call this function. == SEE ALSO [.text-left] -xref:nng_aio_alloc.3.adoc[nng_aio_alloc(3)], xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], xref:nng_aio_start.3.adoc[nng_aio_start(3)], xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], diff --git a/docs/man/nng_aio_set_output.3.adoc b/docs/man/nng_aio_set_output.3.adoc index 67f8ac662..883598ceb 100644 --- a/docs/man/nng_aio_set_output.3.adoc +++ b/docs/man/nng_aio_set_output.3.adoc @@ -52,7 +52,6 @@ None. == SEE ALSO [.text-left] -xref:nng_aio_alloc.3.adoc[nng_aio_alloc(3)], xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], xref:nng_aio_result.3.adoc[nng_aio_result(3)], diff --git a/docs/man/nng_aio_start.3.adoc b/docs/man/nng_aio_start.3.adoc index 82dbde238..4c5d090a8 100644 --- a/docs/man/nng_aio_start.3.adoc +++ b/docs/man/nng_aio_start.3.adoc @@ -62,7 +62,6 @@ although it is harmless if it does. == SEE ALSO [.text-left] -xref:nng_aio_alloc.3.adoc[nng_aio_alloc(3)], xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], xref:nng_aio_result.3.adoc[nng_aio_result(3)], diff --git a/docs/ref/api/aio.md b/docs/ref/api/aio.md index dcf9aa858..2f7b9a731 100644 --- a/docs/ref/api/aio.md +++ b/docs/ref/api/aio.md @@ -43,7 +43,7 @@ complete, creating a synchronous flow from an asynchronous one. ## Create Handle ```c -int nng_aio_alloc(nng_aio **aiop, void (*callb)(void *), void *arg); +nng_err nng_aio_alloc(nng_aio **aiop, void (*callb)(void *), void *arg); ``` The {{i:`nng_aio_alloc`}} function creates an [`nng_aio`] object, with the diff --git a/include/nng/nng.h b/include/nng/nng.h index 908fbb23e..7ad814c4d 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -563,7 +563,7 @@ NNG_DECL void nng_strfree(char *); // when a submitted operation completes (or is canceled or fails) the // callback will be executed, generally in a different thread, with no // locks held. -NNG_DECL int nng_aio_alloc(nng_aio **, void (*)(void *), void *); +NNG_DECL nng_err nng_aio_alloc(nng_aio **, void (*)(void *), void *); // nng_aio_free frees the AIO and any associated resources. // It *must not* be in use at the time it is freed. diff --git a/src/core/aio.c b/src/core/aio.c index 81020bbb8..128178c8e 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -124,7 +124,7 @@ nni_aio_fini(nni_aio *aio) } } -int +nng_err nni_aio_alloc(nni_aio **aio_p, nni_cb cb, void *arg) { nni_aio *aio; @@ -134,7 +134,7 @@ nni_aio_alloc(nni_aio **aio_p, nni_cb cb, void *arg) } nni_aio_init(aio, cb, arg); *aio_p = aio; - return (0); + return (NNG_OK); } void @@ -154,7 +154,7 @@ nni_aio_reap(nni_aio *aio) } } -int +nng_err nni_aio_set_iov(nni_aio *aio, unsigned nio, const nni_iov *iov) { @@ -170,7 +170,7 @@ nni_aio_set_iov(nni_aio *aio, unsigned nio, const nni_iov *iov) } } aio->a_nio = nio; - return (0); + return (NNG_OK); } // nni_aio_stop cancels any outstanding operation, and waits for the @@ -602,7 +602,7 @@ nni_aio_expire_loop(void *arg) for (;;) { nni_aio *aio; - int rv; + nng_err rv; nni_time next; next = q->eq_next; @@ -884,7 +884,7 @@ nni_aio_sys_fini(void) nni_aio_expire_q_list = NULL; } -int +nng_err nni_aio_sys_init(nng_init_params *params) { int16_t num_thr; @@ -912,5 +912,5 @@ nni_aio_sys_init(nng_init_params *params) nni_aio_expire_q_list[i] = eq; } - return (0); + return (NNG_OK); } diff --git a/src/core/aio.h b/src/core/aio.h index 254753236..e0b5a388d 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -37,7 +37,7 @@ extern void nni_aio_reap(nni_aio *); // is called with the supplied argument when the operation is complete. // If NULL is supplied for the callback, then nni_aio_wake is used in its // place, and the aio is used for the argument. -extern int nni_aio_alloc(nni_aio **, nni_cb, void *arg); +extern nng_err nni_aio_alloc(nni_aio **, nni_cb, void *arg); // nni_aio_free frees the aio, releasing resources (locks) // associated with it. This is safe to call on zeroed memory. @@ -138,7 +138,7 @@ extern size_t nni_aio_iov_advance(nni_aio *, size_t); // nni_aio_iov_count returns the number of bytes referenced by the aio iov. extern size_t nni_aio_iov_count(nni_aio *); -extern int nni_aio_set_iov(nni_aio *, unsigned, const nni_iov *); +extern nng_err nni_aio_set_iov(nni_aio *, unsigned, const nni_iov *); extern void nni_aio_set_timeout(nni_aio *, nng_duration); extern void nni_aio_set_expire(nni_aio *, nni_time); @@ -188,9 +188,9 @@ extern void nni_aio_completions_run(nni_aio_completions *); extern void nni_aio_completions_add( nni_aio_completions *, nni_aio *, nng_err, size_t); -extern int nni_aio_sys_init(nng_init_params *); -extern bool nni_aio_sys_drain(void); -extern void nni_aio_sys_fini(void); +extern nng_err nni_aio_sys_init(nng_init_params *); +extern bool nni_aio_sys_drain(void); +extern void nni_aio_sys_fini(void); typedef struct nni_aio_expire_q nni_aio_expire_q; diff --git a/src/nng.c b/src/nng.c index 26f45f769..ad9ae0f6e 100644 --- a/src/nng.c +++ b/src/nng.c @@ -1828,11 +1828,11 @@ nng_msg_set_pipe(nng_msg *msg, nng_pipe p) nni_msg_set_pipe(msg, p.id); } -int +nng_err nng_aio_alloc(nng_aio **app, void (*cb)(void *), void *arg) { nng_aio *aio; - int rv; + nng_err rv; if ((rv = nni_aio_alloc(&aio, (nni_cb) cb, arg)) == 0) { nng_aio_set_timeout(aio, NNG_DURATION_DEFAULT); From 6f56e693e9c9165d514bb5aeef96d0597d33d8ad Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:15:29 -0800 Subject: [PATCH 3/7] docs: markup fix --- docs/ref/api/ctx.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ref/api/ctx.md b/docs/ref/api/ctx.md index b64ed3a1b..7f18b988e 100644 --- a/docs/ref/api/ctx.md +++ b/docs/ref/api/ctx.md @@ -81,7 +81,7 @@ Threads waiting for operations on the context when this call is executed may also return with an `NNG_ECLOSED` result. > [!NOTE] -> Closing the socket associated with _ctx_ using `nng_socket_close`] also closes this context. +> Closing the socket associated with _ctx_ using [`nng_socket_close`] also closes this context. ## Sending Messages From a7a2cdb0201a6e85caae621e748cfab03998b6a6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:15:48 -0800 Subject: [PATCH 4/7] init: use nng_err --- docs/ref/api/init.md | 2 +- include/nng/nng.h | 2 +- src/core/init.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ref/api/init.md b/docs/ref/api/init.md index 6e737cf3a..09708d280 100644 --- a/docs/ref/api/init.md +++ b/docs/ref/api/init.md @@ -17,7 +17,7 @@ typedef struct { int16_t num_resolver_threads; } nng_init_params; -extern int nng_init(nng_init_parms *params); +extern nng_err nng_init(nng_init_parms *params); ``` Before using other interfaces in this library, it is necessary to initialize diff --git a/include/nng/nng.h b/include/nng/nng.h index 7ad814c4d..bec1dd82f 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -1292,7 +1292,7 @@ typedef struct { // only the first call can contain a non-NULL params. If already // initialized with non-NULL params, will return NNG_EALREADY. // Applications should *not* call a matching nng_fini() in that case. -NNG_DECL int nng_init(nng_init_params *parms); +NNG_DECL nng_err nng_init(nng_init_params *parms); // nng_fini is used to terminate the library, freeing certain global resources. // Each call to nng_fini is paired to a call to nng_init. The last such diff --git a/src/core/init.c b/src/core/init.c index 9d9cdf48f..974f4f2e0 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -49,11 +49,11 @@ static nng_init_params init_params; unsigned int init_count; nni_atomic_flag init_busy; -int +nng_err nng_init(nng_init_params *params) { nng_init_params zero = { 0 }; - int rv; + nng_err rv; // cheap spin lock while (nni_atomic_flag_test_and_set(&init_busy)) { From b4fdf7a04fc1018f1114fb8ee6f16009752cd16f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:18:33 -0800 Subject: [PATCH 5/7] socketpair: use nng_err --- docs/ref/api/misc.md | 4 ++-- include/nng/nng.h | 2 +- src/core/platform.h | 2 +- src/nng.c | 2 +- src/platform/posix/posix_socketpair.c | 12 +++++++----- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/ref/api/misc.md b/docs/ref/api/misc.md index 4e7aec948..7c6b70051 100644 --- a/docs/ref/api/misc.md +++ b/docs/ref/api/misc.md @@ -17,10 +17,10 @@ number facilities when available. ## Create Socket Pair ```c -int nng_socket_pair(int fds[2]); +nng_err nng_socket_pair(int fds[2]); ``` -The `nng_socket_pair` function creates a pair of connected file descriptors. +The {{i:`nng_socket_pair`}} function creates a pair of connected file descriptors. These file descriptors, which are returned in the _fds_ array, are suitable for use with the [Socket transport][socktran]. diff --git a/include/nng/nng.h b/include/nng/nng.h index bec1dd82f..e2200f17e 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -1407,7 +1407,7 @@ NNG_DECL uint32_t nng_random(void); // by reliable, bidirectional, byte streams. This will return NNG_ENOTSUP // if the platform lacks support for this. The argument is a pointer // to an array of file descriptors (or HANDLES or similar). -NNG_DECL int nng_socket_pair(int[2]); +NNG_DECL nng_err nng_socket_pair(int[2]); // Multithreading and synchronization functions. diff --git a/src/core/platform.h b/src/core/platform.h index ca39ac980..bdb8beb45 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -417,7 +417,7 @@ extern int nni_plat_udp_sockname(nni_plat_udp *, nni_sockaddr *); // in APIs to transport file descriptors, or across a fork/exec boundary (so // that child processes may use these with socket to inherit a socket that is // connected to the parent.) -extern int nni_socket_pair(int[2]); +extern nng_err nni_socket_pair(int[2]); // // File/Store Support diff --git a/src/nng.c b/src/nng.c index ad9ae0f6e..a98ddda9b 100644 --- a/src/nng.c +++ b/src/nng.c @@ -2135,7 +2135,7 @@ nng_random(void) return (nni_random()); } -int +nng_err nng_socket_pair(int fds[2]) { return (nni_socket_pair(fds)); diff --git a/src/platform/posix/posix_socketpair.c b/src/platform/posix/posix_socketpair.c index bb2698b79..b2d3ef4d4 100644 --- a/src/platform/posix/posix_socketpair.c +++ b/src/platform/posix/posix_socketpair.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -17,7 +17,7 @@ #include #include -int +nng_err nni_socket_pair(int fds[2]) { int rv; @@ -28,14 +28,16 @@ nni_socket_pair(int fds[2]) #ifdef SO_NOSIGPIPE int set = 1; - setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); - setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); + setsockopt( + fds[0], SOL_SOCKET, SO_NOSIGPIPE, (void *) &set, sizeof(int)); + setsockopt( + fds[1], SOL_SOCKET, SO_NOSIGPIPE, (void *) &set, sizeof(int)); #endif return (0); } #else -int +nng_err nni_socket_pair(int fds[2]) { return (NNG_ENOTSUP); From 5b7313273ad99d8da69425beb3b1b3f09025caed Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:22:40 -0800 Subject: [PATCH 6/7] pipe: nng_pipe_notify should use nng_err --- include/nng/nng.h | 2 +- src/nng.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nng/nng.h b/include/nng/nng.h index e2200f17e..b3c5ae14c 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -337,7 +337,7 @@ typedef void (*nng_pipe_cb)(nng_pipe, nng_pipe_ev, void *); // nng_pipe_notify registers a callback to be executed when the // given event is triggered. To watch for different events, register // multiple times. Each event can have at most one callback registered. -NNG_DECL int nng_pipe_notify(nng_socket, nng_pipe_ev, nng_pipe_cb, void *); +NNG_DECL nng_err nng_pipe_notify(nng_socket, nng_pipe_ev, nng_pipe_cb, void *); // nng_listen creates a listening endpoint with no special options, // and starts it listening. It is functionally equivalent to the legacy diff --git a/src/nng.c b/src/nng.c index a98ddda9b..688206758 100644 --- a/src/nng.c +++ b/src/nng.c @@ -1174,10 +1174,10 @@ nng_socket_raw(nng_socket id, bool *rawp) return (0); } -int +nng_err nng_pipe_notify(nng_socket s, nng_pipe_ev ev, nng_pipe_cb cb, void *arg) { - int rv; + nng_err rv; nni_sock *sock; if ((rv = nni_sock_find(&sock, s.id)) != 0) { @@ -1186,7 +1186,7 @@ nng_pipe_notify(nng_socket s, nng_pipe_ev ev, nng_pipe_cb cb, void *arg) nni_sock_set_pipe_cb(sock, ev, cb, arg); nni_sock_rele(sock); - return (0); + return (NNG_OK); } void From cd9901549239bbe424bc70a48b09f33064d906b6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 14 Jan 2025 23:38:54 -0800 Subject: [PATCH 7/7] tests: add some tcp dialer local address tests --- src/platform/tcp_stream_test.c | 46 +++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/platform/tcp_stream_test.c b/src/platform/tcp_stream_test.c index e2ca694b2..1ed415c7b 100644 --- a/src/platform/tcp_stream_test.c +++ b/src/platform/tcp_stream_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include #include #include @@ -428,6 +429,48 @@ test_tcp_listen_activation_bad_arg(void) nng_stream_listener_free(l1); } +void +test_tcp_dialer_loc_addr(void) +{ + nng_stream_dialer *d; + nng_sockaddr sa; + NUTS_PASS(nng_stream_dialer_alloc(&d, "tcp://127.0.0.1:80")); + NUTS_PASS(nng_stream_dialer_get_addr(d, NNG_OPT_LOCADDR, &sa)); + NUTS_TRUE(sa.s_family == NNG_AF_UNSPEC); + + // cannot set a local port + sa.s_in.sa_family = NNG_AF_INET; + sa.s_in.sa_port = 8080; + NUTS_FAIL(nng_stream_dialer_set_addr(d, NNG_OPT_LOCADDR, &sa), + NNG_EADDRINVAL); + +#ifdef NNG_HAVE_INET6 + // cannot set a local port + sa.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_port = 8080; + NUTS_FAIL(nng_stream_dialer_set_addr(d, NNG_OPT_LOCADDR, &sa), + NNG_EADDRINVAL); +#endif + + // cannot set it to a bogus family + sa.s_inproc.sa_family = NNG_AF_INPROC; + snprintf(sa.s_inproc.sa_name, sizeof(sa.s_inproc.sa_name), "junk"); + NUTS_FAIL(nng_stream_dialer_set_addr(d, NNG_OPT_LOCADDR, &sa), + NNG_EADDRINVAL); + + // bad type test + NUTS_FAIL( + nng_stream_dialer_set_int(d, NNG_OPT_LOCADDR, 42), NNG_EBADTYPE); + + // but we can set it to a legal value + sa.s_in.sa_family = NNG_AF_INET; + sa.s_in.sa_port = 0; + sa.s_in.sa_addr = nuts_be32(0x7F000001); + NUTS_PASS(nng_stream_dialer_set_addr(d, NNG_OPT_LOCADDR, &sa)); + + nng_stream_dialer_free(d); +} + NUTS_TESTS = { { "tcp stream", test_tcp_stream }, { "tcp listen accept cancel", test_tcp_listen_accept_cancel }, @@ -443,5 +486,6 @@ NUTS_TESTS = { test_tcp_listen_activation_bogus_fd }, { "tcp socket activation bad arg", test_tcp_listen_activation_bad_arg }, + { "tcp dialer local address", test_tcp_dialer_loc_addr }, { NULL, NULL }, };