From 4367013d8b56105edd0d27d0b9b6da2becab9717 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 3 Nov 2024 08:38:22 -0800 Subject: Remove untyped stream option functions. The underlying stream APIs have no need for untyped accessors. Another step on the road to removal of NNI_TYPE_OPAQUE. --- docs/man/nng_stream_dialer_get.3str.adoc | 24 +------------------- docs/man/nng_stream_dialer_set.3str.adoc | 15 +++---------- docs/man/nng_stream_get.3str.adoc | 27 ++--------------------- docs/man/nng_stream_listener_get.3str.adoc | 28 +++--------------------- docs/man/nng_stream_listener_set.3str.adoc | 15 +++---------- docs/ref/migrate/nng1.md | 13 +++++++++++ include/nng/nng.h | 17 ++++----------- src/core/stream.c | 34 ----------------------------- src/supplemental/websocket/websocket_test.c | 9 ++------ tests/tcpsupp.c | 32 ++++++++++----------------- 10 files changed, 42 insertions(+), 172 deletions(-) diff --git a/docs/man/nng_stream_dialer_get.3str.adoc b/docs/man/nng_stream_dialer_get.3str.adoc index 4023e56f..13813c1f 100644 --- a/docs/man/nng_stream_dialer_get.3str.adoc +++ b/docs/man/nng_stream_dialer_get.3str.adoc @@ -20,8 +20,6 @@ nng_stream_dialer_get - get option from byte stream dialer ---- #include -int nng_stream_dialer_get(nng_stream_dialer *d, const char *opt, void *val, size_t *sizep); - int nng_stream_dialer_get_bool(nng_stream_dialer *d, const char *opt, bool *valp); int nng_stream_dialer_get_int(nng_stream_dialer *d, const char *opt, int *valp); @@ -42,7 +40,7 @@ int nng_stream_dialer_get_uint64(nng_stream_dialer *d, const char *opt, uint64_t == DESCRIPTION -The `nng_stream_dialer_get()` functions are used to retrieve option values for the +The `nng_stream_dialer_get()` functions are used to retrieve option values for the xref:nng_stream_dialer.5.adoc[byte stream dialer] _d_. The actual options that may be retrieved in this way vary. @@ -58,26 +56,6 @@ The forms vary based on the type of the option they take. The details of the type, size, and semantics of the option will depend on the actual option, and will be documented with the option itself. -`nng_stream_dialer_get()`:: -This function is untyped and can be used to retrieve the value of any option. -The caller must store a pointer to a buffer to receive the value in _val_, -and the size of the buffer shall be stored at the location referenced by -_sizep_. -+ -When the function returns, the actual size of the data copied (or that -would have been copied if sufficient space were present) is stored at -the location referenced by _sizep_. -If the caller's buffer is not large enough to hold the entire object, -then the copy is truncated. -Therefore the caller should check for truncation by verifying that the -returned size in _sizep_ does not exceed the original buffer size. -+ -It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero. -This can be used to determine the size of the buffer needed to receive -the object. -+ -TIP: It may be easier to use one of the typed forms of this function. - `nng_stream_dialer_get_bool()`:: This function is for options which take a Boolean (`bool`). diff --git a/docs/man/nng_stream_dialer_set.3str.adoc b/docs/man/nng_stream_dialer_set.3str.adoc index bd4ac478..6a610500 100644 --- a/docs/man/nng_stream_dialer_set.3str.adoc +++ b/docs/man/nng_stream_dialer_set.3str.adoc @@ -1,6 +1,6 @@ = nng_stream_dialer_set(3str) // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -20,8 +20,6 @@ nng_stream_dialer_set - set option on byte stream dialer ---- #include -int nng_stream_dialer_set(nng_stream_dialer *d, const char *name, const void *data, size_t size); - int nng_stream_dialer_set_bool(nng_stream_dialer *d, const char *opt, bool val); int nng_stream_dialer_set_int(nng_stream_dialer *d, const char *opt, int val); @@ -42,7 +40,7 @@ int nng_stream_dialer_set_addr(nng_stream_dialer *d, const char *opt, const nng_ == DESCRIPTION -The `nng_stream_dialer_set()` functions are used to configure options for the +The `nng_stream_dialer_set` functions are used to configure options for the xref:nng_stream.5.adoc[byte stream dialer] _d_. The actual options that may be configured in this way vary, and are specified by _opt_. @@ -57,13 +55,6 @@ documented with the transports and protocols themselves. The details of the type, size, and semantics of the option will depend on the actual option, and will be documented with the option itself. -`nng_stream_dialer_set()`:: -This function is untyped, and can be used to configure any arbitrary data. -The _val_ pointer addresses the data to copy, and _size_ is the -size of the objected located at _val_. -+ -TIP: It may be easier to use one of the typed forms of this function. - `nng_stream_dialer_set_bool()`:: This function is for options which take a Boolean (`bool`). @@ -130,4 +121,4 @@ xref:nng_options.5.adoc[nng_options(5)], xref:nng_ipc_options.5.adoc[nng_ipc_options(5)], xref:nng_tcp_options.5.adoc[nng_tcp_options(5)], xref:nng_tls_options.5.adoc[nng_tls_options(5)], -xref:nng_stream_dialer.5.adoc[nng_stream_dialer(5)] \ No newline at end of file +xref:nng_stream_dialer.5.adoc[nng_stream_dialer(5)] diff --git a/docs/man/nng_stream_get.3str.adoc b/docs/man/nng_stream_get.3str.adoc index 64ff626f..b0f8ee19 100644 --- a/docs/man/nng_stream_get.3str.adoc +++ b/docs/man/nng_stream_get.3str.adoc @@ -1,6 +1,6 @@ = nng_stream_get(3str) // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -20,8 +20,6 @@ nng_stream_get - get option from byte stream ---- #include -int nng_stream_get(nng_stream *s, const char *opt, void *val, size_t *sizep); - int nng_stream_get_bool(nng_stream *s, const char *opt, bool *valp); int nng_stream_get_int(nng_stream *s, const char *opt, int *valp); @@ -37,12 +35,11 @@ int nng_stream_get_addr(nng_stream *s, const char *opt, nng_sockaddr *valp); int nng_stream_get_string(nng_stream *s, const char *opt, char **valp); int nng_stream_get_uint64(nng_stream *s, const char *opt, uint64_t *valp); - ---- == DESCRIPTION -The `nng_stream_get()` functions are used to retrieve option values for the +The `nng_stream_get` functions are used to retrieve option values for the xref:nng_stream.5.adoc[byte stream] _conn_. The actual options that may be retrieved in this way vary. @@ -58,26 +55,6 @@ The forms vary based on the type of the option they take. The details of the type, size, and semantics of the option will depend on the actual option, and will be documented with the option itself. -`nng_stream_get()`:: -This function is untyped and can be used to retrieve the value of any option. -The caller must store a pointer to a buffer to receive the value in _val_, -and the size of the buffer shall be stored at the location referenced by -_sizep_. -+ -When the function returns, the actual size of the data copied (or that -would have been copied if sufficient space were present) is stored at -the location referenced by _sizep_. -If the caller's buffer is not large enough to hold the entire object, -then the copy is truncated. -Therefore the caller should check for truncation by verifying that the -returned size in _sizep_ does not exceed the original buffer size. -+ -It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero. -This can be used to determine the size of the buffer needed to receive -the object. -+ -TIP: It may be easier to use one of the typed forms of this function. - `nng_stream_get_bool()`:: This function is for options which take a Boolean (`bool`). diff --git a/docs/man/nng_stream_listener_get.3str.adoc b/docs/man/nng_stream_listener_get.3str.adoc index 927e36a8..77c8e4b1 100644 --- a/docs/man/nng_stream_listener_get.3str.adoc +++ b/docs/man/nng_stream_listener_get.3str.adoc @@ -1,6 +1,6 @@ = nng_stream_listener_get(3str) // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -20,8 +20,6 @@ nng_stream_listener_get - get option from byte stream listener ---- #include -int nng_stream_listener_get(nng_stream_listener *l, const char *opt, void *val, size_t *sizep); - int nng_stream_listener_get_bool(nng_stream_listener *l, const char *opt, bool *valp); int nng_stream_listener_get_int(nng_stream_listener *l, const char *opt, int *valp); @@ -42,8 +40,8 @@ int nng_stream_listener_get_uint64(nng_stream_listener *l, const char *opt, uint == DESCRIPTION -The `nng_stream_listener_get()` functions are used to retrieve option values -for the +The `nng_stream_listener_get` functions are used to retrieve option values +for the xref:nng_stream_listener.5.adoc[byte stream listener] _l_. The actual options that may be retrieved in this way vary. @@ -59,26 +57,6 @@ The forms vary based on the type of the option they take. The details of the type, size, and semantics of the option will depend on the actual option, and will be documented with the option itself. -`nng_stream_listener_get()`:: -This function is untyped and can be used to retrieve the value of any option. -The caller must store a pointer to a buffer to receive the value in _val_, -and the size of the buffer shall be stored at the location referenced by -_sizep_. -+ -When the function returns, the actual size of the data copied (or that -would have been copied if sufficient space were present) is stored at -the location referenced by _sizep_. -If the caller's buffer is not large enough to hold the entire object, -then the copy is truncated. -Therefore the caller should check for truncation by verifying that the -returned size in _sizep_ does not exceed the original buffer size. -+ -It is acceptable to pass `NULL` for _val_ if the value in _sizep_ is zero. -This can be used to determine the size of the buffer needed to receive -the object. -+ -TIP: It may be easier to use one of the typed forms of this function. - `nng_stream_listener_get_bool()`:: This function is for options which take a Boolean (`bool`). diff --git a/docs/man/nng_stream_listener_set.3str.adoc b/docs/man/nng_stream_listener_set.3str.adoc index ccabe5ca..08a852bf 100644 --- a/docs/man/nng_stream_listener_set.3str.adoc +++ b/docs/man/nng_stream_listener_set.3str.adoc @@ -1,6 +1,6 @@ = nng_stream_listener_set(3str) // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -20,8 +20,6 @@ nng_stream_listener_set - set option on byte stream listener ---- #include -int nng_stream_listener_set(nng_stream_listener *l, const char *name, const void *data, size_t size); - int nng_stream_listener_set_bool(nng_stream_listener *l, const char *opt, bool val); int nng_stream_listener_set_int(nng_stream_listener *l, const char *opt, int val); @@ -42,7 +40,7 @@ int nng_stream_listener_set_addr(nng_stream_listener *l, const char *opt, const == DESCRIPTION -The `nng_stream_listener_set()` functions are used to configure options for the +The `nng_stream_listener_set` functions are used to configure options for the xref:nng_stream.5.adoc[byte stream listener] _l_. The actual options that may be configured in this way vary, and are specified by _opt_. @@ -57,13 +55,6 @@ documented with the transports and protocols themselves. The details of the type, size, and semantics of the option will depend on the actual option, and will be documented with the option itself. -`nng_stream_listener_set()`:: -This function is untyped, and can be used to configure any arbitrary data. -The _val_ pointer addresses the data to copy, and _size_ is the -size of the objected located at _val_. -+ -TIP: It may be easier to use one of the typed forms of this function. - `nng_stream_listener_set_bool()`:: This function is for options which take a Boolean (`bool`). @@ -130,4 +121,4 @@ xref:nng_options.5.adoc[nng_options(5)], xref:nng_ipc_options.5.adoc[nng_ipc_options(5)], xref:nng_tcp_options.5.adoc[nng_tcp_options(5)], xref:nng_tls_options.5.adoc[nng_tls_options(5)], -xref:nng_stream_listener.5.adoc[nng_stream_listener(5)] \ No newline at end of file +xref:nng_stream_listener.5.adoc[nng_stream_listener(5)] diff --git a/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md index 65af2382..9d9cd01b 100644 --- a/docs/ref/migrate/nng1.md +++ b/docs/ref/migrate/nng1.md @@ -54,6 +54,19 @@ The `_getopt` and `_setopt` functions for contexts, listeners, and dialers are n present. Simply changing `_getopt` to `_get` or `_setopt` to `_set` in the function name should be sufficient in most cases. +## Untyped Option Functions Removed + +The following functions are removed. To access options, use a proper typed access function, +such as one ending in a suffix like `_bool` (to access a `bool` typed option). + +- `nng_pipe_get` +- `nng_stream_get` +- `nng_stream_set` +- `nng_stream_dialer_get` +- `nng_stream_dialer_set` +- `nng_stream_listener_get` +- `nng_stream_listener_set` + ## Stream Options The ability to set options on streams after they have been created is no longer present. diff --git a/include/nng/nng.h b/include/nng/nng.h index 074850c5..622846c9 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -708,7 +708,6 @@ NNG_DECL nng_pipe nng_msg_get_pipe(const nng_msg *); // we do permit an application to close a pipe. This can be useful, for // example during a connection notification, to disconnect a pipe that // is associated with an invalid or untrusted remote peer. -NNG_DECL int nng_pipe_get(nng_pipe, const char *, void *, size_t *); NNG_DECL int nng_pipe_get_bool(nng_pipe, const char *, bool *); NNG_DECL int nng_pipe_get_int(nng_pipe, const char *, int *); NNG_DECL int nng_pipe_get_ms(nng_pipe, const char *, nng_duration *); @@ -1166,12 +1165,8 @@ NNG_DECL int nng_stream_dialer_alloc_url( NNG_DECL void nng_stream_dialer_free(nng_stream_dialer *); NNG_DECL void nng_stream_dialer_close(nng_stream_dialer *); NNG_DECL void nng_stream_dialer_dial(nng_stream_dialer *, nng_aio *); -NNG_DECL int nng_stream_dialer_set( - nng_stream_dialer *, const char *, const void *, size_t); -NNG_DECL int nng_stream_dialer_get( - nng_stream_dialer *, const char *, void *, size_t *); -NNG_DECL int nng_stream_dialer_get_bool( - nng_stream_dialer *, const char *, bool *); +NNG_DECL int nng_stream_dialer_get_bool( + nng_stream_dialer *, const char *, bool *); NNG_DECL int nng_stream_dialer_get_int( nng_stream_dialer *, const char *, int *); NNG_DECL int nng_stream_dialer_get_ms( @@ -1209,12 +1204,8 @@ NNG_DECL void nng_stream_listener_free(nng_stream_listener *); NNG_DECL void nng_stream_listener_close(nng_stream_listener *); NNG_DECL int nng_stream_listener_listen(nng_stream_listener *); NNG_DECL void nng_stream_listener_accept(nng_stream_listener *, nng_aio *); -NNG_DECL int nng_stream_listener_set( - nng_stream_listener *, const char *, const void *, size_t); -NNG_DECL int nng_stream_listener_get( - nng_stream_listener *, const char *, void *, size_t *); -NNG_DECL int nng_stream_listener_get_bool( - nng_stream_listener *, const char *, bool *); +NNG_DECL int nng_stream_listener_get_bool( + nng_stream_listener *, const char *, bool *); NNG_DECL int nng_stream_listener_get_int( nng_stream_listener *, const char *, int *); NNG_DECL int nng_stream_listener_get_ms( diff --git a/src/core/stream.c b/src/core/stream.c index f1cf6301..4ac27705 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -289,12 +289,6 @@ nng_stream_listener_alloc(nng_stream_listener **lp, const char *uri) // Public stream options. -int -nng_stream_get(nng_stream *s, const char *n, void *v, size_t *szp) -{ - return (nni_stream_get(s, n, v, szp, NNI_TYPE_OPAQUE)); -} - int nng_stream_get_int(nng_stream *s, const char *n, int *v) { @@ -343,13 +337,6 @@ nng_stream_get_addr(nng_stream *s, const char *n, nng_sockaddr *v) return (nni_stream_get(s, n, v, NULL, NNI_TYPE_SOCKADDR)); } -int -nng_stream_dialer_get( - nng_stream_dialer *d, const char *n, void *v, size_t *szp) -{ - return (nni_stream_dialer_get(d, n, v, szp, NNI_TYPE_OPAQUE)); -} - int nng_stream_dialer_get_int(nng_stream_dialer *d, const char *n, int *v) { @@ -399,13 +386,6 @@ nng_stream_dialer_get_addr( return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_SOCKADDR)); } -int -nng_stream_listener_get( - nng_stream_listener *l, const char *n, void *v, size_t *szp) -{ - return (nni_stream_listener_get(l, n, v, szp, NNI_TYPE_OPAQUE)); -} - int nng_stream_listener_get_int(nng_stream_listener *l, const char *n, int *v) { @@ -457,13 +437,6 @@ nng_stream_listener_get_addr( return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_SOCKADDR)); } -int -nng_stream_dialer_set( - nng_stream_dialer *d, const char *n, const void *v, size_t sz) -{ - return (nni_stream_dialer_set(d, n, v, sz, NNI_TYPE_OPAQUE)); -} - int nng_stream_dialer_set_int(nng_stream_dialer *d, const char *n, int v) { @@ -515,13 +488,6 @@ nng_stream_dialer_set_addr( return (nni_stream_dialer_set(d, n, v, sizeof(*v), NNI_TYPE_SOCKADDR)); } -int -nng_stream_listener_set( - nng_stream_listener *l, const char *n, const void *v, size_t sz) -{ - return (nni_stream_listener_set(l, n, v, sz, NNI_TYPE_OPAQUE)); -} - int nng_stream_listener_set_int(nng_stream_listener *l, const char *n, int v) { diff --git a/src/supplemental/websocket/websocket_test.c b/src/supplemental/websocket/websocket_test.c index d784c1bc..f648f740 100644 --- a/src/supplemental/websocket/websocket_test.c +++ b/src/supplemental/websocket/websocket_test.c @@ -172,15 +172,10 @@ test_websocket_conn_props(void) NUTS_TRUE(sa1.s_in.sa_addr == sa2.s_in.sa_addr); NUTS_TRUE(sa1.s_in.sa_port == sa2.s_in.sa_port); - on = false; - sz = sizeof(on); - NUTS_PASS(nng_stream_get(c1, NNG_OPT_TCP_NODELAY, &on, &sz)); - NUTS_TRUE(sz == sizeof(on)); + NUTS_PASS(nng_stream_get_bool(c1, NNG_OPT_TCP_NODELAY, &on)); NUTS_TRUE(on == true); - sz = sizeof(on); - NUTS_PASS(nng_stream_get(c2, NNG_OPT_TCP_KEEPALIVE, &on, &sz)); - NUTS_TRUE(sz == sizeof(on)); + NUTS_PASS(nng_stream_get_bool(c2, NNG_OPT_TCP_KEEPALIVE, &on)); NUTS_FAIL( nng_stream_get_size(c1, NNG_OPT_TCP_NODELAY, &sz), NNG_EBADTYPE); diff --git a/tests/tcpsupp.c b/tests/tcpsupp.c index be947129..d7d5c38d 100644 --- a/tests/tcpsupp.c +++ b/tests/tcpsupp.c @@ -97,7 +97,6 @@ TestMain("Supplemental TCP", { char buf1[5]; char buf2[5]; bool on; - size_t sz; So(nng_aio_alloc(&aio1, NULL, NULL) == 0); @@ -110,19 +109,14 @@ TestMain("Supplemental TCP", { }); on = false; - sz = sizeof(on); - So(nng_stream_get(c1, - NNG_OPT_TCP_NODELAY, &on, - &sz) == 0); - So(sz == sizeof(on)); + So(nng_stream_get_bool(c1, + NNG_OPT_TCP_NODELAY, &on) == 0); So(on == true); on = false; - sz = sizeof(on); - So(nng_stream_get(c1, - NNG_OPT_TCP_KEEPALIVE, &on, - &sz) == 0); - So(sz == sizeof(on)); + So(nng_stream_get_bool(c1, + NNG_OPT_TCP_KEEPALIVE, + &on) == 0); // This relies on send completing for // for just 5 bytes, and on recv doing @@ -153,11 +147,9 @@ TestMain("Supplemental TCP", { So(memcmp(buf1, buf2, 5) == 0); Convey("Socket name matches", { - sz = sizeof(sa2); - So(nng_stream_get(c2, - NNG_OPT_LOCADDR, &sa2, - &sz) == 0); - So(sz == sizeof(sa2)); + So(nng_stream_get_addr(c2, + NNG_OPT_LOCADDR, + &sa2) == 0); So(sa2.s_in.sa_family == NNG_AF_INET); @@ -168,11 +160,9 @@ TestMain("Supplemental TCP", { }); Convey("Peer name matches", { - sz = sizeof(sa2); - So(nng_stream_get(c1, - NNG_OPT_REMADDR, &sa2, - &sz) == 0); - So(sz == sizeof(sa2)); + So(nng_stream_get_addr(c1, + NNG_OPT_REMADDR, + &sa2) == 0); So(sa2.s_in.sa_family == NNG_AF_INET); So(sa2.s_in.sa_addr == -- cgit v1.2.3-70-g09d2