diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-10-26 10:02:33 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-10-26 10:02:33 -0700 |
| commit | 72b96ad6925634e1b4efa775ffbed436b0a29abd (patch) | |
| tree | aca1508cbc9fa89597fae7e059263725983d6485 | |
| parent | e0cb4377cc4d6fe50514e0b297e174fdde001bb6 (diff) | |
| download | nng-72b96ad6925634e1b4efa775ffbed436b0a29abd.tar.gz nng-72b96ad6925634e1b4efa775ffbed436b0a29abd.tar.bz2 nng-72b96ad6925634e1b4efa775ffbed436b0a29abd.zip | |
NNG_OPT_BOUND_PORT replaces NNG_OPT_TCP/UDP_BOUND_PORT.
This is easier and agnostic about the underlying L3 protocol.
We plan to remove direct NNG_OPT_LOCADDR support from listeners
(and probably both NNG_OPT_LOCADDR and NNG_OPT_REMADDR have numbered
days left in their lifetime. They will be replaced with more direct
typed access functions as has been done for pipes already.)
While here fixed some include for IWYU in the POSIX platform.
30 files changed, 105 insertions, 81 deletions
diff --git a/docs/man/nng_tcp_options.5.adoc b/docs/man/nng_tcp_options.5.adoc index 37228b82..c6063d8a 100644 --- a/docs/man/nng_tcp_options.5.adoc +++ b/docs/man/nng_tcp_options.5.adoc @@ -22,7 +22,7 @@ nng_tcp_options - TCP-specific options #define NNG_OPT_TCP_NODELAY "tcp-nodelay" #define NNG_OPT_TCP_KEEPALIVE "tcp-keepalive" -#define NNG_OPT_TCP_BOUND_PORT "tcp-bound-port" +#define NNG_OPT_BOUND_PORT "bound-port" ---- == DESCRIPTION @@ -89,10 +89,10 @@ First, it can be used to detect dead peers on an otherwise quiescent network. Second, it can be used to keep connection table entries in NAT and other middleware from being expiring due to lack of activity. -[[NNG_OPT_TCP_BOUND_PORT]] -((`NNG_OPT_TCP_BOUND_PORT`)):: +[[NNG_OPT_BOUND_PORT]] +((`NNG_OPT_BOUND_PORT`)):: (`int`) -This option is available on listeners, after the listern has bound to +This option is available on listeners, after the listener has bound to a port, and provides the port bound to in native byte order. This is most useful when using a listener with an ephemeral port (configured by using port 0 at configuration time), as it allows diff --git a/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md index df062efd..52b786cc 100644 --- a/docs/ref/migrate/nng1.md +++ b/docs/ref/migrate/nng1.md @@ -274,6 +274,9 @@ The latter option is a hint for transports and intended to facilitate early detection (and possibly avoidance of extra allocations) of oversize messages, before bringing them into the socket itself. +The `NNG_OPT_TCP_BOUND_PORT` port is renamed to just [`NNG_OPT_BOUND_PORT`], +and is available for listeners using transports based on either TCP or UDP. + ## Socket Options The `NNG_OPT_PROTO`, `NNG_OPT_PROTONAME`, `NNG_OPT_PEER`, and `NNG_OPT_PEERNAME` options diff --git a/docs/ref/tran/udp.md b/docs/ref/tran/udp.md index 0b83b542..920d5bcd 100644 --- a/docs/ref/tran/udp.md +++ b/docs/ref/tran/udp.md @@ -66,13 +66,11 @@ the actual structure is either of type The following transport options are supported by this transport, where supported by the underlying platform. -| Option | Type | Description | -| ------------------------------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- | -| [`NNG_OPT_LOCADDR`] | [`nng_sockaddr`] | The locally bound address, will be either [`nng_sockaddr_in`] or [`nng_sockaddr_in6`]. | -| [`NNG_OPT_REMADDR`] | [`nng_sockaddr`] | The remote peer address, will be either [`nng_sockaddr_in`] or [`nng_sockaddr_in6`]. Only valid for [pipe] and [dialer] objects. | -| [`NNG_OPT_RECVMAXSZ`] | `size_t` | Maximum size of incoming messages, will be limited to at most 65000. | -| `NNG_OPT_UDP_COPY_MAX`<a name="NNG_OPT_UDP_COPY_MAX"></a> | `size_t` | Threshold above which received messages are "loaned" up, rather than a new message being allocated and copied into. | -| `NNG_OPT_UDP_BOUND_PORT`<a name="NNG_OPT_UDP_BOUND_PORT"></a> | `int` | The locally bound UDP port number (1-65535), read-only for [listener] objects only. | +| Option | Type | Description | +| --------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------- | +| [`NNG_OPT_RECVMAXSZ`] | `size_t` | Maximum size of incoming messages, will be limited to at most 65000. | +| `NNG_OPT_UDP_COPY_MAX`<a name="NNG_OPT_UDP_COPY_MAX"></a> | `size_t` | Threshold above which received messages are "loaned" up, rather than a new message being allocated and copied into. | +| `NNG_OPT_BOUND_PORT`<a name="NNG_OPT_BOUND_PORT"></a> | `int` | The locally bound UDP port number (1-65535), read-only for [listener] objects only. | ## Maximum Message Size diff --git a/include/nng/nng.h b/include/nng/nng.h index e5e0e02b..8e5dcd9f 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -833,19 +833,16 @@ NNG_DECL nng_listener nng_pipe_listener(nng_pipe); // state current). This is a boolean. #define NNG_OPT_TCP_KEEPALIVE "tcp-keepalive" -// Local TCP port number. This is used on a listener, and is intended +// Local TCP or UDP port number. This is used on a listener, and is intended // to be used after starting the listener in combination with a wildcard // (0) local port. This determines the actual ephemeral port that was -// selected and bound. The value is provided as an int, but only the -// low order 16 bits will be set. This is provided in native byte order, +// selected and bound. The value is provided as an int, but in practice +// port numbers are only 16-bits. This is provided in native byte order, // which makes it more convenient than using the NNG_OPT_LOCADDR option. -#define NNG_OPT_TCP_BOUND_PORT "tcp-bound-port" +#define NNG_OPT_BOUND_PORT "bound-port" // UDP options. -// UDP alias for convenience uses the same value -#define NNG_OPT_UDP_BOUND_PORT NNG_OPT_TCP_BOUND_PORT - // UDP short message size. Messages smaller than (or equal to) this // will be copied, instead of loan up. This can allow for a faster // pass up as we can allocate smaller message buffers instead of having diff --git a/src/platform/posix/posix_aio.h b/src/platform/posix/posix_aio.h index 3b1ce751..67b60a12 100644 --- a/src/platform/posix/posix_aio.h +++ b/src/platform/posix/posix_aio.h @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -17,7 +17,6 @@ // that is not very performant on many systems. So we emulate this using // one of several possible different backends. -#include "core/nng_impl.h" #include "posix_pollq.h" #include <sys/stat.h> // needed for musl build diff --git a/src/platform/posix/posix_pollq.h b/src/platform/posix/posix_pollq.h index a6306643..a1b5f605 100644 --- a/src/platform/posix/posix_pollq.h +++ b/src/platform/posix/posix_pollq.h @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -19,10 +19,8 @@ // that is not very performant on many systems. So we emulate this using // one of several possible different backends. -#include "core/nng_impl.h" - -typedef struct nni_posix_pfd nni_posix_pfd; -typedef void (*nni_posix_pfd_cb)(void *, unsigned); +// #include "core/nng_impl.h" +#include "../../core/defs.h" #if defined(NNG_POLLQ_KQUEUE) #include "posix_pollq_kqueue.h" diff --git a/src/platform/posix/posix_pollq_epoll.h b/src/platform/posix/posix_pollq_epoll.h index a6ef5ad8..05755c52 100644 --- a/src/platform/posix/posix_pollq_epoll.h +++ b/src/platform/posix/posix_pollq_epoll.h @@ -13,6 +13,12 @@ #include <poll.h> +#include "../../core/list.h" +#include "../../core/platform.h" + +typedef struct nni_posix_pfd nni_posix_pfd; +typedef void (*nni_posix_pfd_cb)(void *, unsigned); + // nni_posix_pfd is the handle used by the poller. It's internals are private // to the poller. struct nni_posix_pfd { diff --git a/src/platform/posix/posix_pollq_kqueue.h b/src/platform/posix/posix_pollq_kqueue.h index 69cf6dae..3959b5e6 100644 --- a/src/platform/posix/posix_pollq_kqueue.h +++ b/src/platform/posix/posix_pollq_kqueue.h @@ -11,6 +11,13 @@ #ifndef PLATFORM_POSIX_POLLQ_KQUEUE_H #define PLATFORM_POSIX_POLLQ_KQUEUE_H +#include "../../core/defs.h" +#include "../../core/list.h" +#include "../../core/platform.h" + +typedef struct nni_posix_pfd nni_posix_pfd; +typedef void (*nni_posix_pfd_cb)(void *, unsigned); + // nni_posix_pfd is the handle used by the poller. It's internals are private // to the poller. struct nni_posix_pfd { diff --git a/src/platform/posix/posix_pollq_port.h b/src/platform/posix/posix_pollq_port.h index d8771527..377e3620 100644 --- a/src/platform/posix/posix_pollq_port.h +++ b/src/platform/posix/posix_pollq_port.h @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -13,6 +13,11 @@ #include <poll.h> +#include "../../core/platform.h" + +typedef struct nni_posix_pfd nni_posix_pfd; +typedef void (*nni_posix_pfd_cb)(void *, unsigned); + typedef struct nni_posix_pollq nni_posix_pollq; // nni_posix_pfd is the handle used by the poller. It's internals are private diff --git a/src/platform/posix/posix_pollq_select.h b/src/platform/posix/posix_pollq_select.h index 012f10a0..4f59c007 100644 --- a/src/platform/posix/posix_pollq_select.h +++ b/src/platform/posix/posix_pollq_select.h @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,6 +11,11 @@ #ifndef PLATFORM_POSIX_POLLQ_SELECT_H #define PLATFORM_POSIX_POLLQ_SELECT_H +#include "../../core/platform.h" + +typedef struct nni_posix_pfd nni_posix_pfd; +typedef void (*nni_posix_pfd_cb)(void *, unsigned); + // nni_posix_pfd is the handle used by the poller. It's internals are private // to the poller. struct nni_posix_pfd { diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index fe6ee2d7..3696cef1 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -37,7 +37,7 @@ #endif #ifndef NNG_HAVE_INET6 -#ifdef HAVE_NNG_HAVE_INET6_BSD +#ifdef NNG_HAVE_INET6_BSD #define NNG_HAVE_INET6 #include <netinet6/in6.h> #else diff --git a/src/platform/posix/posix_sockaddr.c b/src/platform/posix/posix_sockaddr.c index c86b6fb5..29d8b8f4 100644 --- a/src/platform/posix/posix_sockaddr.c +++ b/src/platform/posix/posix_sockaddr.c @@ -23,7 +23,7 @@ #include <sys/un.h> #ifndef NNG_HAVE_INET6 -#ifdef HAVE_NNG_HAVE_INET6_BSD +#ifdef NNG_HAVE_INET6_BSD #define NNG_HAVE_INET6 #include <netinet6/in6.h> #else diff --git a/src/platform/posix/posix_tcp.h b/src/platform/posix/posix_tcp.h index 20325841..d8743063 100644 --- a/src/platform/posix/posix_tcp.h +++ b/src/platform/posix/posix_tcp.h @@ -12,9 +12,11 @@ #ifndef PLATFORM_POSIX_TCP_H #define PLATFORM_POSIX_TCP_H -#include "core/nng_impl.h" +#include "../../core/defs.h" +#include "../../core/reap.h" +#include "../../core/stream.h" -#include "platform/posix/posix_aio.h" +#include "posix_aio.h" struct nni_tcp_conn { nng_stream stream; diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c index c04c27c1..833cd560 100644 --- a/src/platform/posix/posix_tcpconn.c +++ b/src/platform/posix/posix_tcpconn.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -9,9 +9,6 @@ // found online at https://opensource.org/licenses/MIT. // -#include "core/nng_impl.h" -#include "platform/posix/posix_pollq.h" - #include <errno.h> #include <fcntl.h> #include <netinet/in.h> @@ -26,6 +23,12 @@ #define MSG_NOSIGNAL 0 #endif +#include "../../core/aio.h" +#include "../../core/defs.h" +#include "../../core/options.h" +#include "../../core/platform.h" + +#include "posix_pollq.h" #include "posix_tcp.h" static void diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c index 181a667f..12fa990f 100644 --- a/src/platform/posix/posix_tcpdial.c +++ b/src/platform/posix/posix_tcpdial.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // @@ -9,8 +9,6 @@ // found online at https://opensource.org/licenses/MIT. // -#include "core/nng_impl.h" - #include <errno.h> #include <netinet/in.h> #include <string.h> @@ -21,10 +19,8 @@ #define SOCK_CLOEXEC 0 #endif -#include "posix_tcp.h" - #ifndef NNG_HAVE_INET6 -#ifdef HAVE_NNG_HAVE_INET6_BSD +#ifdef NNG_HAVE_INET6_BSD #define NNG_HAVE_INET6 #include <netinet6/in6.h> #else @@ -32,6 +28,14 @@ #endif #endif +#include "../../core/aio.h" +#include "../../core/defs.h" +#include "../../core/options.h" +#include "../../core/platform.h" +#include "../../core/refcnt.h" + +#include "posix_tcp.h" + struct nni_tcp_dialer { nni_list connq; // pending connections bool closed; diff --git a/src/platform/posix/posix_tcplisten.c b/src/platform/posix/posix_tcplisten.c index 700af4c5..b158508c 100644 --- a/src/platform/posix/posix_tcplisten.c +++ b/src/platform/posix/posix_tcplisten.c @@ -9,9 +9,6 @@ // found online at https://opensource.org/licenses/MIT. // -#include "core/nng_impl.h" -#include "nng/nng.h" - #include <arpa/inet.h> #include <errno.h> #include <fcntl.h> @@ -29,7 +26,7 @@ #endif #ifndef NNG_HAVE_INET6 -#ifdef HAVE_NNG_HAVE_INET6_BSD +#ifdef NNG_HAVE_INET6_BSD #define NNG_HAVE_INET6 #include <netinet6/in6.h> #else @@ -37,6 +34,13 @@ #endif #endif +#include "../../core/aio.h" +#include "../../core/defs.h" +#include "../../core/list.h" +#include "../../core/options.h" +#include "../../core/platform.h" +#include "../../core/url.h" + #include "posix_tcp.h" typedef struct tcp_listener { @@ -480,7 +484,7 @@ static const nni_option tcp_listener_options[] = { .o_get = tcp_listener_get_keepalive, }, { - .o_name = NNG_OPT_TCP_BOUND_PORT, + .o_name = NNG_OPT_BOUND_PORT, .o_get = tcp_listener_get_port, }, { diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index 99460721..7188b427 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -32,7 +32,7 @@ #endif #ifndef NNG_HAVE_INET6 -#ifdef HAVE_NNG_HAVE_INET6_BSD +#ifdef NNG_HAVE_INET6_BSD #define NNG_HAVE_INET6 #include <netinet6/in6.h> #else diff --git a/src/platform/tcp_stream_test.c b/src/platform/tcp_stream_test.c index 1ed415c7..a0943e6c 100644 --- a/src/platform/tcp_stream_test.c +++ b/src/platform/tcp_stream_test.c @@ -164,7 +164,7 @@ test_tcp_listen_port_zero_not_bound(void) // start a listening stream listener but do not call accept NUTS_PASS(nng_stream_listener_alloc(&l, addr)); - NUTS_FAIL(nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &p), + NUTS_FAIL(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &p), NNG_ESTATE); nng_stream_listener_free(l); } @@ -204,8 +204,7 @@ test_tcp_listen_activation(void) NUTS_PASS(nng_stream_listener_alloc(&l1, addr)); NUTS_PASS(nng_stream_listener_listen(l1)); - NUTS_PASS( - nng_stream_listener_get_int(l1, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l1, NNG_OPT_BOUND_PORT, &port)); snprintf(url, sizeof(url), "tcp4://127.0.0.1:%u", port); NUTS_PASS(nng_stream_dialer_alloc(&d, url)); diff --git a/src/platform/windows/win_tcplisten.c b/src/platform/windows/win_tcplisten.c index 0b11104d..b32c1fbb 100644 --- a/src/platform/windows/win_tcplisten.c +++ b/src/platform/windows/win_tcplisten.c @@ -517,7 +517,7 @@ static const nni_option tcp_listener_options[] = { .o_get = tcp_listener_get_keepalive, }, { - .o_name = NNG_OPT_TCP_BOUND_PORT, + .o_name = NNG_OPT_BOUND_PORT, .o_get = tcp_listener_get_port, }, { diff --git a/src/sp/transport/dtls/dtls.c b/src/sp/transport/dtls/dtls.c index ff78709d..5a97af4f 100644 --- a/src/sp/transport/dtls/dtls.c +++ b/src/sp/transport/dtls/dtls.c @@ -1726,7 +1726,7 @@ static const nni_option dtls_ep_opts[] = { .o_get = dtls_ep_get_remaddr, }, { - .o_name = NNG_OPT_TCP_BOUND_PORT, + .o_name = NNG_OPT_BOUND_PORT, .o_get = dtls_ep_get_port, }, // terminate list diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index 1040e7a9..759bc320 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -938,7 +938,7 @@ tcptran_ep_bind(void *arg, nng_url *url) if (rv == NNG_OK) { int port; nng_stream_listener_get_int( - ep->listener, NNG_OPT_TCP_BOUND_PORT, &port); + ep->listener, NNG_OPT_BOUND_PORT, &port); url->u_port = (uint32_t) port; } nni_mtx_unlock(&ep->mtx); diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c index 4814b29f..5086a942 100644 --- a/src/sp/transport/tls/tls.c +++ b/src/sp/transport/tls/tls.c @@ -877,7 +877,7 @@ tlstran_ep_bind(void *arg, nng_url *url) if (rv == NNG_OK) { int port; nng_stream_listener_get_int( - ep->listener, NNG_OPT_TCP_BOUND_PORT, &port); + ep->listener, NNG_OPT_BOUND_PORT, &port); url->u_port = (uint32_t) port; } nni_mtx_unlock(&ep->mtx); diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c index 7f46a3c9..02eb088a 100644 --- a/src/sp/transport/udp/udp.c +++ b/src/sp/transport/udp/udp.c @@ -1740,7 +1740,7 @@ static const nni_option udp_ep_opts[] = { .o_get = udp_ep_get_remaddr, }, { - .o_name = NNG_OPT_TCP_BOUND_PORT, + .o_name = NNG_OPT_BOUND_PORT, .o_get = udp_ep_get_port, }, // terminate list diff --git a/src/sp/transport/udp/udp_tran_test.c b/src/sp/transport/udp/udp_tran_test.c index 56a25cce..33517246 100644 --- a/src/sp/transport/udp/udp_tran_test.c +++ b/src/sp/transport/udp/udp_tran_test.c @@ -86,7 +86,7 @@ test_udp_port_zero_bind(void) NUTS_MATCH(nng_url_hostname(u1), nng_url_hostname(u2)); NUTS_MATCH(nng_url_path(u1), nng_url_path(u2)); NUTS_TRUE(nng_url_port(u1) == nng_url_port(u2)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port == (int) nng_url_port(u1)); NUTS_CLOSE(s2); diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c index dec0ea8e..4033553b 100644 --- a/src/sp/transport/ws/websocket.c +++ b/src/sp/transport/ws/websocket.c @@ -234,7 +234,7 @@ wstran_listener_bind(void *arg, nng_url *url) if ((rv = nng_stream_listener_listen(l->listener)) == NNG_OK) { int port; nng_stream_listener_get_int( - l->listener, NNG_OPT_TCP_BOUND_PORT, &port); + l->listener, NNG_OPT_BOUND_PORT, &port); url->u_port = (uint32_t) port; } return (rv); diff --git a/src/sp/transport/ws/ws_test.c b/src/sp/transport/ws/ws_test.c index 4f41b150..6f41fe99 100644 --- a/src/sp/transport/ws/ws_test.c +++ b/src/sp/transport/ws/ws_test.c @@ -24,7 +24,7 @@ test_ws_url_path_filters(void) snprintf(addr, sizeof(addr), "ws://127.0.0.1:0/ws-url-path-filters"); NUTS_PASS(nng_listen(s1, addr, &l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); snprintf( addr, sizeof(addr), "ws://127.0.0.1:%d/some-other-location", port); @@ -58,16 +58,16 @@ test_wild_card_port(void) NUTS_OPEN(s5); NUTS_OPEN(s6); NUTS_PASS(nng_listen(s1, "ws://127.0.0.1:0/one", &l1, 0)); - NUTS_PASS(nng_listener_get_int(l1, NNG_OPT_TCP_BOUND_PORT, &port1)); + NUTS_PASS(nng_listener_get_int(l1, NNG_OPT_BOUND_PORT, &port1)); NUTS_TRUE(port1 != 0); snprintf(ws_url, sizeof(ws_url), "ws4://127.0.0.1:%d/two", port1); NUTS_PASS(nng_listen(s2, ws_url, &l2, 0)); - NUTS_PASS(nng_listener_get_int(l2, NNG_OPT_TCP_BOUND_PORT, &port2)); + NUTS_PASS(nng_listener_get_int(l2, NNG_OPT_BOUND_PORT, &port2)); NUTS_TRUE(port1 != 0); NUTS_TRUE(port1 == port2); // Now try a different wild card port. NUTS_PASS(nng_listen(s3, "ws4://127.0.0.1:0/three", &l3, 0)); - NUTS_PASS(nng_listener_get_int(l3, NNG_OPT_TCP_BOUND_PORT, &port3)); + NUTS_PASS(nng_listener_get_int(l3, NNG_OPT_BOUND_PORT, &port3)); NUTS_TRUE(port3 != 0); NUTS_TRUE(port3 != port1); @@ -127,7 +127,7 @@ test_empty_host(void) // we use ws4 to ensure 127.0.0.1 binding snprintf(addr, sizeof(addr), "ws4://:0/test"); NUTS_PASS(nng_listen(s1, addr, &l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); nng_msleep(100); snprintf(addr, sizeof(addr), "ws://127.0.0.1:%u/test", port); @@ -165,7 +165,7 @@ test_ws_recv_max(void) NUTS_PASS(nng_listener_get_size(l, NNG_OPT_RECVMAXSZ, &sz)); NUTS_TRUE(sz == 100); NUTS_PASS(nng_listener_start(l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_OPEN(s1); snprintf(url, sizeof(url), addr, port); diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index d1e8a5e7..d24e5bba 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -871,7 +871,7 @@ http_server_start(nni_http_server *s) if (s->port == 0) { int port; nng_stream_listener_get_int( - s->listener, NNG_OPT_TCP_BOUND_PORT, &port); + s->listener, NNG_OPT_BOUND_PORT, &port); s->port = (uint32_t) port; } nng_stream_listener_accept(s->listener, &s->accaio); diff --git a/src/supplemental/tls/tls_test.c b/src/supplemental/tls/tls_test.c index cbe9c0b9..a9c78ba2 100644 --- a/src/supplemental/tls/tls_test.c +++ b/src/supplemental/tls/tls_test.c @@ -100,8 +100,7 @@ test_tls_large_message(void) c1, nuts_server_crt, nuts_server_key, NULL)); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); @@ -187,8 +186,7 @@ test_tls_ecdsa(void) c1, nuts_ecdsa_server_crt, nuts_ecdsa_server_key, NULL)); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); @@ -274,8 +272,7 @@ test_tls_null_server_name(void) c1, nuts_server_crt, nuts_server_key, NULL)); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); @@ -383,8 +380,7 @@ test_tls_psk(void) NUTS_PASS(nng_tls_config_psk(c1, "identity", key, sizeof(key))); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); @@ -477,8 +473,7 @@ test_tls_psk_server_identities(void) NUTS_PASS(nng_tls_config_psk(c1, identity, key, sizeof(key))); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); @@ -567,8 +562,7 @@ test_tls_psk_bad_identity(void) NUTS_PASS(nng_tls_config_psk(c1, "identity1", key, sizeof(key))); NUTS_PASS(nng_stream_listener_set_tls(l, c1)); NUTS_PASS(nng_stream_listener_listen(l)); - NUTS_PASS( - nng_stream_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_stream_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); NUTS_TRUE(port > 0); NUTS_TRUE(port < 65536); diff --git a/src/supplemental/websocket/wssfile_test.c b/src/supplemental/websocket/wssfile_test.c index dde71129..c42290ef 100644 --- a/src/supplemental/websocket/wssfile_test.c +++ b/src/supplemental/websocket/wssfile_test.c @@ -81,7 +81,7 @@ test_invalid_verify(void) NUTS_PASS(nng_listener_create(&l, s1, addr)); init_listener_wss_file(l); NUTS_PASS(nng_listener_start(l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); nng_msleep(100); @@ -128,7 +128,7 @@ test_no_verify(void) NUTS_PASS(nng_listener_create(&l, s1, addr)); init_listener_wss_file(l); NUTS_PASS(nng_listener_start(l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); nng_msleep(100); snprintf(addr, sizeof(addr), "wss://127.0.0.1:%u/test", port); @@ -178,7 +178,7 @@ test_verify_works(void) NUTS_PASS(nng_listener_create(&l, s1, addr)); init_listener_wss_file(l); NUTS_PASS(nng_listener_start(l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); // It can take a bit for the listener to start up in clouds. nng_msleep(200); @@ -239,7 +239,7 @@ test_tls_config(void) init_listener_wss_file(l); NUTS_PASS(nng_listener_start(l, 0)); - NUTS_PASS(nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port)); + NUTS_PASS(nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port)); // make sure we cannot change the auth mode while running diff --git a/src/testing/marry.c b/src/testing/marry.c index a197fb01..2c5723db 100644 --- a/src/testing/marry.c +++ b/src/testing/marry.c @@ -374,7 +374,7 @@ nuts_marry_ex( if ((strstr(url, ":0") != NULL) && // If a TCP port of zero was selected, let's ask for the actual // port bound. - (nng_listener_get_int(l, NNG_OPT_TCP_BOUND_PORT, &port) == 0) && + (nng_listener_get_int(l, NNG_OPT_BOUND_PORT, &port) == 0) && (port > 0)) { replace_port_zero(url, addr, port); url = addr; |
