aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
commit249932f3a208260f6b9c99d778b22d51cfabe87b (patch)
tree4fd4826127e9c225d5232c39d4ae1db89b539689
parenteb328da56c3fc7167b536dcb206df0abb0f4a9b9 (diff)
downloadnng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.gz
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.bz2
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.zip
fixes #1071 tran_chkopt can be cleaned up
This is a sweeping cleanup of the transport logic around options, and also harmonizes the names used when setting or getting options. Additionally, legacy methods are now moved into a separate file and can be elided via CMake or a preprocessor define. Fundamentally, the ability to set to transport options via the socket is deprecated; there are numerous problems with this and my earlier approaches to deal with this have been somewhat misguided. Further these approaches will not work with future protocol work that is planned (were some options need to be negotiated with peers at the time of connection establishment.) Documentation has been updated to reflect this. The test suites still make rather broad use of the older APIs, and will be converted later.
-rw-r--r--CMakeLists.txt22
-rw-r--r--docs/man/nng_ctx.5.adoc4
-rw-r--r--docs/man/nng_ctx_getopt.3.adoc5
-rw-r--r--docs/man/nng_ctx_setopt.3.adoc5
-rw-r--r--docs/man/nng_dialer_get.3.adoc5
-rw-r--r--docs/man/nng_dialer_getopt.3.adoc8
-rw-r--r--docs/man/nng_dialer_set.3.adoc5
-rw-r--r--docs/man/nng_dialer_setopt.3.adoc5
-rw-r--r--docs/man/nng_getopt.3.adoc5
-rw-r--r--docs/man/nng_listener_get.3.adoc5
-rw-r--r--docs/man/nng_listener_getopt.3.adoc9
-rw-r--r--docs/man/nng_listener_set.3.adoc5
-rw-r--r--docs/man/nng_listener_setopt.3.adoc9
-rw-r--r--docs/man/nng_options.5.adoc8
-rw-r--r--docs/man/nng_setopt.3.adoc5
-rw-r--r--docs/man/nng_socket_get.3.adoc10
-rw-r--r--docs/man/nng_socket_set.3.adoc12
-rw-r--r--include/nng/nng.h226
-rw-r--r--perf/perf.c12
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/core/options.c34
-rw-r--r--src/core/options.h180
-rw-r--r--src/core/platform.h29
-rw-r--r--src/core/socket.c85
-rw-r--r--src/core/stream.c428
-rw-r--r--src/core/stream.h29
-rw-r--r--src/core/tcp.h5
-rw-r--r--src/core/transport.c67
-rw-r--r--src/core/transport.h12
-rw-r--r--src/nng.c554
-rw-r--r--src/nng_legacy.c454
-rw-r--r--src/platform/posix/posix_ipcconn.c8
-rw-r--r--src/platform/posix/posix_ipcdial.c12
-rw-r--r--src/platform/posix/posix_ipclisten.c39
-rw-r--r--src/platform/posix/posix_tcpconn.c8
-rw-r--r--src/platform/posix/posix_tcpdial.c4
-rw-r--r--src/platform/posix/posix_tcplisten.c4
-rw-r--r--src/platform/windows/win_ipcconn.c10
-rw-r--r--src/platform/windows/win_ipcdial.c31
-rw-r--r--src/platform/windows/win_ipclisten.c44
-rw-r--r--src/platform/windows/win_tcpconn.c8
-rw-r--r--src/platform/windows/win_tcpdial.c6
-rw-r--r--src/platform/windows/win_tcplisten.c6
-rw-r--r--src/supplemental/http/http_api.h10
-rw-r--r--src/supplemental/http/http_client.c12
-rw-r--r--src/supplemental/http/http_conn.c4
-rw-r--r--src/supplemental/http/http_public.c16
-rw-r--r--src/supplemental/http/http_server.c12
-rw-r--r--src/supplemental/tcp/tcp.c58
-rw-r--r--src/supplemental/tls/tls_api.h1
-rw-r--r--src/supplemental/tls/tls_common.c119
-rw-r--r--src/supplemental/websocket/websocket.c111
-rw-r--r--src/supplemental/websocket/websocket.h3
-rw-r--r--src/transport/inproc/inproc.c31
-rw-r--r--src/transport/ipc/ipc.c40
-rw-r--r--src/transport/tcp/tcp.c52
-rw-r--r--src/transport/tls/tls.c53
-rw-r--r--src/transport/ws/websocket.c41
-rw-r--r--src/transport/zerotier/zerotier.c89
-rw-r--r--tests/sock.c1
-rw-r--r--tools/nngcat/nngcat.c43
61 files changed, 1782 insertions, 1338 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2c10644..e55470b4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,18 +78,17 @@ endif ()
# cross-compile situation. Cross-compiling users who still want to
# build these must enable them explicitly. Some of these switches
# must be enabled rather early as we use their values later.
-option(NNG_TESTS "Build and run tests" ${NNG_NATIVE_BUILD})
-option(NNG_TOOLS "Build extra tools" ${NNG_NATIVE_BUILD})
+option(NNG_TESTS "Build and run tests." ${NNG_NATIVE_BUILD})
+option(NNG_TOOLS "Build extra tools." ${NNG_NATIVE_BUILD})
option(NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
option(NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF)
-
# Enable access to private APIs for our own use.
add_definitions(-DNNG_PRIVATE)
if (NOT (BUILD_SHARED_LIBS))
set(NNG_STATIC_LIB ON)
- message(STATUS "Building static libs")
+ message(STATUS "Building static libs.")
endif ()
# These are library targets. The "nng" library is the main public library.
@@ -109,6 +108,21 @@ target_compile_definitions(nng_testing PUBLIC NNG_STATIC_LIB NNG_TEST_LIB NNG_PR
add_library(nng_private INTERFACE)
target_compile_definitions(nng_private INTERFACE NNG_PRIVATE)
+# Eliding deprecated functionality can be used to build a slimmed down
+# version of the library, or alternatively to test for application
+# preparedness for expected feature removals (in the next major release.)
+# Applications can also set the NNG_ELIDE_DEPRECATED preprocessor symbol
+# before including <nng/nng.h> -- this will prevent declarations from
+# being exposed to applications, but it will not affect their ABI
+# availability for existing compiled applications.
+# Note: Currently this breaks the test suite, so we only do it
+# for the public library.
+option(NNG_ELIDE_DEPRECATED "Elide deprecated functionality." OFF)
+if (NNG_ELIDE_DEPRECATED)
+ target_compile_definitions(nng, NNG_ELIDE_DEPRECATED)
+endif()
+
+
# We can use rlimit to configure the stack size for systems
# that have too small defaults. This is not used for Windows,
# which can grow thread stacks sensibly. (Note that NNG can get
diff --git a/docs/man/nng_ctx.5.adoc b/docs/man/nng_ctx.5.adoc
index b097d866..cc859c48 100644
--- a/docs/man/nng_ctx.5.adoc
+++ b/docs/man/nng_ctx.5.adoc
@@ -162,11 +162,11 @@ start_echo_service(nng_socket rep_socket)
xref:libnng.3.adoc[libnng(3)],
xref:nng_ctx_close.3.adoc[nng_ctx_close(3)],
xref:nng_ctx_open.3.adoc[nng_ctx_open(3)],
-xref:nng_ctx_getopt.3.adoc[nng_ctx_getopt(3)],
+xref:nng_ctx_get.3.adoc[nng_ctx_get(3)],
xref:nng_ctx_id.3.adoc[nng_ctx_id(3)],
xref:nng_ctx_recv.3.adoc[nng_ctx_recv(3)],
xref:nng_ctx_send.3.adoc[nng_ctx_send(3)],
-xref:nng_ctx_setopt.3.adoc[nng_ctx_setopt(3)],
+xref:nng_ctx_set.3.adoc[nng_ctx_set(3)],
xref:nng_dialer.5.adoc[nng_dialer(5)],
xref:nng_listener.5.adoc[nng_listener(5)],
xref:nng_socket.5.adoc[nng_socket(5)],
diff --git a/docs/man/nng_ctx_getopt.3.adoc b/docs/man/nng_ctx_getopt.3.adoc
index daba5e59..5b7afd70 100644
--- a/docs/man/nng_ctx_getopt.3.adoc
+++ b/docs/man/nng_ctx_getopt.3.adoc
@@ -1,6 +1,6 @@
= nng_ctx_getopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -37,7 +37,8 @@ int nng_ctx_getopt_uint64(nng_ctx ctx, const char *opt, uint64_t *u64p);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_ctx_get.3.adoc[nng_ctx_get].
+IMPORTANT: These functions are deprecated. Please see xref:nng_ctx_get.3.adoc[nng_ctx_get].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, context)))
The `nng_ctx_getopt()` functions are used to retrieve option values for
diff --git a/docs/man/nng_ctx_setopt.3.adoc b/docs/man/nng_ctx_setopt.3.adoc
index 1fd36e66..f6f7f9ef 100644
--- a/docs/man/nng_ctx_setopt.3.adoc
+++ b/docs/man/nng_ctx_setopt.3.adoc
@@ -1,6 +1,6 @@
= nng_ctx_setopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -36,7 +36,8 @@ int nng_ctx_setopt_uint64(nng_ctx ctx, const char *opt, uint64_t u64);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_ctx_set.3.adoc[nng_ctx_set].
+IMPORTANT: These functions are deprecated. Please see xref:nng_ctx_set.3.adoc[nng_ctx_set].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, context)))
The `nng_ctx_setopt()` functions are used to configure options for
diff --git a/docs/man/nng_dialer_get.3.adoc b/docs/man/nng_dialer_get.3.adoc
index 29acb811..86f606a9 100644
--- a/docs/man/nng_dialer_get.3.adoc
+++ b/docs/man/nng_dialer_get.3.adoc
@@ -1,6 +1,6 @@
= nng_dialer_get(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -47,8 +47,7 @@ the xref:nng_dialer.5.adoc[dialer] _d_.
The actual options that may be retrieved in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options are documented with the transports themselves.
=== Forms
diff --git a/docs/man/nng_dialer_getopt.3.adoc b/docs/man/nng_dialer_getopt.3.adoc
index 4f8b3a3e..f69f433f 100644
--- a/docs/man/nng_dialer_getopt.3.adoc
+++ b/docs/man/nng_dialer_getopt.3.adoc
@@ -1,6 +1,6 @@
= nng_dialer_getopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -41,7 +41,8 @@ int nng_dialer_getopt_uint64(nng_dialer d, const char *opt, uint64_t *u64p);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_dialer_get.3.adoc[nng_dialer_get].
+IMPORTANT: These functions are deprecated. Please see xref:nng_dialer_get.3.adoc[nng_dialer_get].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, dialer)))
The `nng_dialer_getopt()` functions are used to retrieve option values for
@@ -49,8 +50,7 @@ the xref:nng_dialer.5.adoc[dialer] _d_.
The actual options that may be retrieved in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options are documented with the transports themselves.
=== Forms
diff --git a/docs/man/nng_dialer_set.3.adoc b/docs/man/nng_dialer_set.3.adoc
index 76f20e6c..3363eae9 100644
--- a/docs/man/nng_dialer_set.3.adoc
+++ b/docs/man/nng_dialer_set.3.adoc
@@ -1,6 +1,6 @@
= nng_dialer_set(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -46,8 +46,7 @@ the xref:nng_dialer.5.adoc[dialer] _d_.
The actual options that may be configured in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options are documented with the
-transports themselves.
+Additionally some transport-specific options are documented with the transports themselves.
NOTE: Once a dialer has started, it is generally not possible to change
its configuration.
diff --git a/docs/man/nng_dialer_setopt.3.adoc b/docs/man/nng_dialer_setopt.3.adoc
index a554acb5..3aaff1eb 100644
--- a/docs/man/nng_dialer_setopt.3.adoc
+++ b/docs/man/nng_dialer_setopt.3.adoc
@@ -1,6 +1,6 @@
= nng_dialer_setopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -40,7 +40,8 @@ int nng_dialer_setopt_uint64(nng_dialer d, const char *opt, uint64_t u64);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_dialer_set.3.adoc[nng_dialer_set].
+IMPORTANT: These functions are deprecated. Please see xref:nng_dialer_set.3.adoc[nng_dialer_set].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, dialer)))
The `nng_dialer_setopt()` functions are used to configure options for
diff --git a/docs/man/nng_getopt.3.adoc b/docs/man/nng_getopt.3.adoc
index de3e882f..0c65bd2d 100644
--- a/docs/man/nng_getopt.3.adoc
+++ b/docs/man/nng_getopt.3.adoc
@@ -1,6 +1,6 @@
= nng_getopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -39,7 +39,8 @@ int nng_getopt_uint64(nng_socket s, const char *opt, uint64_t *u64p);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_socket_get.3.adoc[nng_socket_get].
+IMPORTANT: These functions are deprecated. Please see xref:nng_socket_get.3.adoc[nng_socket_get].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, socket)))
The `nng_getopt()` functions are used to retrieve option values for
diff --git a/docs/man/nng_listener_get.3.adoc b/docs/man/nng_listener_get.3.adoc
index bd59ffa3..83ae6986 100644
--- a/docs/man/nng_listener_get.3.adoc
+++ b/docs/man/nng_listener_get.3.adoc
@@ -1,6 +1,6 @@
= nng_listener_get(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -47,8 +47,7 @@ the xref:nng_listener.5.adoc[listener] _l_.
The actual options that may be retrieved in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options are documented with the transports themselves.
=== Forms
diff --git a/docs/man/nng_listener_getopt.3.adoc b/docs/man/nng_listener_getopt.3.adoc
index e232da96..828f440d 100644
--- a/docs/man/nng_listener_getopt.3.adoc
+++ b/docs/man/nng_listener_getopt.3.adoc
@@ -1,6 +1,6 @@
= nng_listener_getopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -41,7 +41,8 @@ int nng_listener_getopt_uint64(nng_listener l, const char *opt, uint64_t *u64p);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_listener_get.3.adoc[nng_listener_get].
+IMPORTANT: These functions are deprecated. Please see xref:nng_listener_get.3.adoc[nng_listener_get].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, listener)))
The `nng_listener_getopt()` functions are used to retrieve option values for
@@ -49,8 +50,8 @@ the xref:nng_listener.5.adoc[listener] _l_.
The actual options that may be retrieved in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options
+are documented with the transports themselves.
=== Forms
diff --git a/docs/man/nng_listener_set.3.adoc b/docs/man/nng_listener_set.3.adoc
index 89e3ca20..0cfd2112 100644
--- a/docs/man/nng_listener_set.3.adoc
+++ b/docs/man/nng_listener_set.3.adoc
@@ -1,6 +1,6 @@
= nng_listener_set(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -46,8 +46,7 @@ the xref:nng_listener.5.adoc[listener] _l_.
The actual options that may be configured in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options are documented with the transports themselves.
NOTE: Once a listener has started, it is generally not possible to change
its configuration.
diff --git a/docs/man/nng_listener_setopt.3.adoc b/docs/man/nng_listener_setopt.3.adoc
index 595b8a19..25411adc 100644
--- a/docs/man/nng_listener_setopt.3.adoc
+++ b/docs/man/nng_listener_setopt.3.adoc
@@ -1,6 +1,6 @@
= nng_listener_setopt(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -40,7 +40,8 @@ int nng_listener_setopt_uint64(nng_listener l, const char *opt, uint64_t u64);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_listener_set.3.adoc[nng_listener_set].
+IMPORTANT: These functions are deprecated. Please see xref:nng_listener_set.3.adoc[nng_listener_set].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, listener)))
The `nng_listener_setopt()` functions are used to configure options for
@@ -48,8 +49,8 @@ the xref:nng_listener.5.adoc[listener] _l_.
The actual options that may be configured in this way
vary, and many are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific options and protocol-specific options
-are documented with the transports and protocols themselves.
+Additionally some transport-specific options
+are documented with the transports themselves.
NOTE: Once a listener has started, it is generally not possible to change
its configuration.
diff --git a/docs/man/nng_options.5.adoc b/docs/man/nng_options.5.adoc
index fa78453c..eb1c873b 100644
--- a/docs/man/nng_options.5.adoc
+++ b/docs/man/nng_options.5.adoc
@@ -196,6 +196,14 @@ per-dialer or per-listener basis.
IMPORTANT: Applications on hostile networks should set this to a non-zero
value to prevent denial-of-service attacks.
+
+IMPORTANT: This option should be set before any listeners or dialers are added.
+Ideally this option should be set on specific dialers or listeners; setting it
+on the socket globally is deprecated behavior, and might not work in a future release,
+or might only work for endpoints that have not yet been created.
+(Maximum receive sizes might be negotiated during connection establishment for
+future transports, which means that the option needs to be set before any connections
+are established.)
++
NOTE: Some transports may have further message size restrictions.
[[NNG_OPT_RECVTIMEO]]
diff --git a/docs/man/nng_setopt.3.adoc b/docs/man/nng_setopt.3.adoc
index 8a526399..6c21cf95 100644
--- a/docs/man/nng_setopt.3.adoc
+++ b/docs/man/nng_setopt.3.adoc
@@ -1,6 +1,6 @@
= nng_setopt(3)
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -38,7 +38,8 @@ int nng_setopt_uint64(nng_socket s, const char *opt, uint64_t u64);
== DESCRIPTION
-NOTE: These functions are deprecated. Please see xref:nng_socket_set.3.adoc[nng_socket_set].
+IMPORTANT: These functions are deprecated. Please see xref:nng_socket_set.3.adoc[nng_socket_set].
+They may not be present if the library was built with `NNG_ELIDE_DEPRECATED`.
(((options, socket)))
The `nng_setopt()` functions are used to configure options for
diff --git a/docs/man/nng_socket_get.3.adoc b/docs/man/nng_socket_get.3.adoc
index 6c2ec87e..6d8456ad 100644
--- a/docs/man/nng_socket_get.3.adoc
+++ b/docs/man/nng_socket_get.3.adoc
@@ -1,6 +1,6 @@
= nng_socket_get(3)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -47,8 +47,12 @@ the xref:nng_socket.5.adoc[socket] _s_.
The actual options that may be retrieved in this way vary.
A number of them are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally transport-specific options and protocol-specific options are
-documented with the transports and protocols themselves.
+Additionally protocol-specific options are documented with the protocols themselves.
+
+IMPORTANT: Access to transport options via this function is deprecated, and may be
+removed from a future release. Applications should instead make use of
+xref:nng_dialer_get.3.adoc[nng_dialer_get] or
+xref:nng_listener_get.3.adoc[nng_listener_get] for specific dialers or listeners.
=== Forms
diff --git a/docs/man/nng_socket_set.3.adoc b/docs/man/nng_socket_set.3.adoc
index 0b6df4f9..aa5784f3 100644
--- a/docs/man/nng_socket_set.3.adoc
+++ b/docs/man/nng_socket_set.3.adoc
@@ -1,6 +1,6 @@
= nng_socket_set(3)
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -45,13 +45,17 @@ The actual options that may be configured in this way vary, and are
specified by _opt_.
A number of them are documented in xref:nng_options.5.adoc[nng_options(5)].
-Additionally some transport-specific and protocol-specific options are
-documented with the transports and protocols themselves.
+Protocol-specific options are documented with the protocol in question.
+
+IMPORTANT: Access to transport options via this function is deprecated, and may be
+removed from a future release. Applications should instead make use of
+xref:nng_dialer_set.3.adoc[nng_dialer_get] or
+xref:nng_listener_set.3.adoc[nng_listener_get] for specific dialers or listeners.
=== Forms
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.
+on the actual option, and is documented with the option itself.
`nng_socket_set()`::
This function is untyped, and can be used to configure any arbitrary data.
diff --git a/include/nng/nng.h b/include/nng/nng.h
index 32861023..20454a17 100644
--- a/include/nng/nng.h
+++ b/include/nng/nng.h
@@ -215,34 +215,6 @@ NNG_DECL int nng_close(nng_socket);
// if the socket is not valid.
NNG_DECL int nng_socket_id(nng_socket);
-// nng_closeall closes all open sockets. Do not call this from
-// a library; it will affect all sockets.
-NNG_DECL void nng_closeall(void);
-
-// nng_setopt sets an option for a specific socket.
-NNG_DECL int nng_setopt(nng_socket, const char *, const void *, size_t);
-NNG_DECL int nng_setopt_bool(nng_socket, const char *, bool);
-NNG_DECL int nng_setopt_int(nng_socket, const char *, int);
-NNG_DECL int nng_setopt_ms(nng_socket, const char *, nng_duration);
-NNG_DECL int nng_setopt_size(nng_socket, const char *, size_t);
-NNG_DECL int nng_setopt_uint64(nng_socket, const char *, uint64_t);
-NNG_DECL int nng_setopt_string(nng_socket, const char *, const char *);
-NNG_DECL int nng_setopt_ptr(nng_socket, const char *, void *);
-
-// nng_socket_getopt obtains the option for a socket.
-NNG_DECL int nng_getopt(nng_socket, const char *, void *, size_t *);
-NNG_DECL int nng_getopt_bool(nng_socket, const char *, bool *);
-NNG_DECL int nng_getopt_int(nng_socket, const char *, int *);
-NNG_DECL int nng_getopt_ms(nng_socket, const char *, nng_duration *);
-NNG_DECL int nng_getopt_size(nng_socket, const char *, size_t *);
-NNG_DECL int nng_getopt_uint64(nng_socket, const char *, uint64_t *);
-NNG_DECL int nng_getopt_ptr(nng_socket, const char *, void **);
-
-// nng_getopt_string is special -- it allocates a string to hold the
-// resulting string, which should be freed with nng_strfree when it is
-// no logner needed.
-NNG_DECL int nng_getopt_string(nng_socket, const char *, char **);
-
NNG_DECL int nng_socket_set(nng_socket, const char *, const void *, size_t);
NNG_DECL int nng_socket_set_bool(nng_socket, const char *, bool);
NNG_DECL int nng_socket_set_int(nng_socket, const char *, int);
@@ -331,35 +303,6 @@ NNG_DECL int nng_dialer_id(nng_dialer);
// invalid.
NNG_DECL int nng_listener_id(nng_listener);
-// nng_dialer_setopt sets an option for a specific dialer. Note
-// dialer options may not be altered on a running dialer.
-NNG_DECL int nng_dialer_setopt(nng_dialer, const char *, const void *, size_t);
-NNG_DECL int nng_dialer_setopt_bool(nng_dialer, const char *, bool);
-NNG_DECL int nng_dialer_setopt_int(nng_dialer, const char *, int);
-NNG_DECL int nng_dialer_setopt_ms(nng_dialer, const char *, nng_duration);
-NNG_DECL int nng_dialer_setopt_size(nng_dialer, const char *, size_t);
-NNG_DECL int nng_dialer_setopt_uint64(nng_dialer, const char *, uint64_t);
-NNG_DECL int nng_dialer_setopt_ptr(nng_dialer, const char *, void *);
-NNG_DECL int nng_dialer_setopt_string(nng_dialer, const char *, const char *);
-
-// nng_dialer_getopt obtains the option for a dialer. This will
-// fail for options that a particular dialer is not interested in,
-// even if they were set on the socket.
-NNG_DECL int nng_dialer_getopt(nng_dialer, const char *, void *, size_t *);
-NNG_DECL int nng_dialer_getopt_bool(nng_dialer, const char *, bool *);
-NNG_DECL int nng_dialer_getopt_int(nng_dialer, const char *, int *);
-NNG_DECL int nng_dialer_getopt_ms(nng_dialer, const char *, nng_duration *);
-NNG_DECL int nng_dialer_getopt_size(nng_dialer, const char *, size_t *);
-NNG_DECL int nng_dialer_getopt_sockaddr(
- nng_dialer, const char *, nng_sockaddr *);
-NNG_DECL int nng_dialer_getopt_uint64(nng_dialer, const char *, uint64_t *);
-NNG_DECL int nng_dialer_getopt_ptr(nng_dialer, const char *, void **);
-
-// nng_dialer_getopt_string is special -- it allocates a string to hold the
-// resulting string, which should be freed with nng_strfree when it is
-// no logner needed.
-NNG_DECL int nng_dialer_getopt_string(nng_dialer, const char *, char **);
-
NNG_DECL int nng_dialer_set(nng_dialer, const char *, const void *, size_t);
NNG_DECL int nng_dialer_set_bool(nng_dialer, const char *, bool);
NNG_DECL int nng_dialer_set_int(nng_dialer, const char *, int);
@@ -381,41 +324,6 @@ NNG_DECL int nng_dialer_get_ptr(nng_dialer, const char *, void **);
NNG_DECL int nng_dialer_get_ms(nng_dialer, const char *, nng_duration *);
NNG_DECL int nng_dialer_get_addr(nng_dialer, const char *, nng_sockaddr *);
-// nng_listener_setopt sets an option for a dialer. This value is
-// not stored in the socket. Subsequent setopts on the socket may
-// override these value however. Note listener options may not be altered
-// on a running listener.
-NNG_DECL int nng_listener_setopt(
- nng_listener, const char *, const void *, size_t);
-NNG_DECL int nng_listener_setopt_bool(nng_listener, const char *, bool);
-NNG_DECL int nng_listener_setopt_int(nng_listener, const char *, int);
-NNG_DECL int nng_listener_setopt_ms(nng_listener, const char *, nng_duration);
-NNG_DECL int nng_listener_setopt_size(nng_listener, const char *, size_t);
-NNG_DECL int nng_listener_setopt_uint64(nng_listener, const char *, uint64_t);
-NNG_DECL int nng_listener_setopt_ptr(nng_listener, const char *, void *);
-NNG_DECL int nng_listener_setopt_string(
- nng_listener, const char *, const char *);
-
-// nng_listener_getopt obtains the option for a listener. This will
-// fail for options that a particular listener is not interested in,
-// even if they were set on the socket.
-NNG_DECL int nng_listener_getopt(nng_listener, const char *, void *, size_t *);
-NNG_DECL int nng_listener_getopt_bool(nng_listener, const char *, bool *);
-NNG_DECL int nng_listener_getopt_int(nng_listener, const char *, int *);
-NNG_DECL int nng_listener_getopt_ms(
- nng_listener, const char *, nng_duration *);
-NNG_DECL int nng_listener_getopt_size(nng_listener, const char *, size_t *);
-NNG_DECL int nng_listener_getopt_sockaddr(
- nng_listener, const char *, nng_sockaddr *);
-NNG_DECL int nng_listener_getopt_uint64(
- nng_listener, const char *, uint64_t *);
-NNG_DECL int nng_listener_getopt_ptr(nng_listener, const char *, void **);
-
-// nng_listener_getopt_string is special -- it allocates a string to hold the
-// resulting string, which should be freed with nng_strfree when it is
-// no logner needed.
-NNG_DECL int nng_listener_getopt_string(nng_listener, const char *, char **);
-
NNG_DECL int nng_listener_set(
nng_listener, const char *, const void *, size_t);
NNG_DECL int nng_listener_set_bool(nng_listener, const char *, bool);
@@ -517,26 +425,6 @@ NNG_DECL void nng_ctx_recv(nng_ctx, nng_aio *);
// uses a local context instead of the socket global context.
NNG_DECL void nng_ctx_send(nng_ctx, nng_aio *);
-// nng_ctx_getopt is used to retrieve a context-specific option. This
-// can only be used for those options that relate to specific context
-// tunables (which does include NNG_OPT_SENDTIMEO and NNG_OPT_RECVTIMEO);
-// see the protocol documentation for more details.
-NNG_DECL int nng_ctx_getopt(nng_ctx, const char *, void *, size_t *);
-NNG_DECL int nng_ctx_getopt_bool(nng_ctx, const char *, bool *);
-NNG_DECL int nng_ctx_getopt_int(nng_ctx, const char *, int *);
-NNG_DECL int nng_ctx_getopt_ms(nng_ctx, const char *, nng_duration *);
-NNG_DECL int nng_ctx_getopt_size(nng_ctx, const char *, size_t *);
-
-// nng_ctx_setopt is used to set a context-specific option. This
-// can only be used for those options that relate to specific context
-// tunables (which does include NNG_OPT_SENDTIMEO and NNG_OPT_RECVTIMEO);
-// see the protocol documentation for more details.
-NNG_DECL int nng_ctx_setopt(nng_ctx, const char *, const void *, size_t);
-NNG_DECL int nng_ctx_setopt_bool(nng_ctx, const char *, bool);
-NNG_DECL int nng_ctx_setopt_int(nng_ctx, const char *, int);
-NNG_DECL int nng_ctx_setopt_ms(nng_ctx, const char *, nng_duration);
-NNG_DECL int nng_ctx_setopt_size(nng_ctx, const char *, size_t);
-
NNG_DECL int nng_ctx_get(nng_ctx, const char *, void *, size_t *);
NNG_DECL int nng_ctx_get_bool(nng_ctx, const char *, bool *);
NNG_DECL int nng_ctx_get_int(nng_ctx, const char *, int *);
@@ -741,24 +629,10 @@ NNG_DECL void nng_msg_header_clear(nng_msg *);
NNG_DECL void nng_msg_set_pipe(nng_msg *, nng_pipe);
NNG_DECL nng_pipe nng_msg_get_pipe(const nng_msg *);
-// nng_msg_getopt is defunct, and should not be used by programs. It
-// always returns NNG_ENOTSUP.
-NNG_DECL int nng_msg_getopt(nng_msg *, int, void *, size_t *);
-
// Pipe API. Generally pipes are only "observable" to applications, but
// 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_getopt(nng_pipe, const char *, void *, size_t *);
-NNG_DECL int nng_pipe_getopt_bool(nng_pipe, const char *, bool *);
-NNG_DECL int nng_pipe_getopt_int(nng_pipe, const char *, int *);
-NNG_DECL int nng_pipe_getopt_ms(nng_pipe, const char *, nng_duration *);
-NNG_DECL int nng_pipe_getopt_size(nng_pipe, const char *, size_t *);
-NNG_DECL int nng_pipe_getopt_sockaddr(nng_pipe, const char *, nng_sockaddr *);
-NNG_DECL int nng_pipe_getopt_uint64(nng_pipe, const char *, uint64_t *);
-NNG_DECL int nng_pipe_getopt_ptr(nng_pipe, const char *, void **);
-NNG_DECL int nng_pipe_getopt_string(nng_pipe, const char *, char **);
-
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 *);
@@ -1296,6 +1170,106 @@ NNG_DECL int nng_stream_listener_set_ptr(
NNG_DECL int nng_stream_listener_set_addr(
nng_stream_listener *, const char *, const nng_sockaddr *);
+
+#ifndef NNG_ELIDE_DEPRECATED
+// These are legacy APIs that have been deprecated.
+// Their use is strongly discouraged.
+
+// nng_msg_getopt is defunct, and should not be used by programs. It
+// always returns NNG_ENOTSUP.
+NNG_DECL int nng_msg_getopt(nng_msg *, int, void *, size_t *);
+
+// Socket options. Use nng_socket_get and nng_socket_set isnetadl
+NNG_DECL int nng_getopt(nng_socket, const char *, void *, size_t *);
+NNG_DECL int nng_getopt_bool(nng_socket, const char *, bool *);
+NNG_DECL int nng_getopt_int(nng_socket, const char *, int *);
+NNG_DECL int nng_getopt_ms(nng_socket, const char *, nng_duration *);
+NNG_DECL int nng_getopt_size(nng_socket, const char *, size_t *);
+NNG_DECL int nng_getopt_uint64(nng_socket, const char *, uint64_t *);
+NNG_DECL int nng_getopt_ptr(nng_socket, const char *, void **);
+NNG_DECL int nng_getopt_string(nng_socket, const char *, char **);
+NNG_DECL int nng_setopt(nng_socket, const char *, const void *, size_t);
+NNG_DECL int nng_setopt_bool(nng_socket, const char *, bool);
+NNG_DECL int nng_setopt_int(nng_socket, const char *, int);
+NNG_DECL int nng_setopt_ms(nng_socket, const char *, nng_duration);
+NNG_DECL int nng_setopt_size(nng_socket, const char *, size_t);
+NNG_DECL int nng_setopt_uint64(nng_socket, const char *, uint64_t);
+NNG_DECL int nng_setopt_string(nng_socket, const char *, const char *);
+NNG_DECL int nng_setopt_ptr(nng_socket, const char *, void *);
+
+// Context options. Use nng_ctx_get and nng_ctx_set instead.
+NNG_DECL int nng_ctx_getopt(nng_ctx, const char *, void *, size_t *);
+NNG_DECL int nng_ctx_getopt_bool(nng_ctx, const char *, bool *);
+NNG_DECL int nng_ctx_getopt_int(nng_ctx, const char *, int *);
+NNG_DECL int nng_ctx_getopt_ms(nng_ctx, const char *, nng_duration *);
+NNG_DECL int nng_ctx_getopt_size(nng_ctx, const char *, size_t *);
+NNG_DECL int nng_ctx_setopt(nng_ctx, const char *, const void *, size_t);
+NNG_DECL int nng_ctx_setopt_bool(nng_ctx, const char *, bool);
+NNG_DECL int nng_ctx_setopt_int(nng_ctx, const char *, int);
+NNG_DECL int nng_ctx_setopt_ms(nng_ctx, const char *, nng_duration);
+NNG_DECL int nng_ctx_setopt_size(nng_ctx, const char *, size_t);
+
+// Dialer options. Use nng_dialer_get and nng_dialer_set instead.
+NNG_DECL int nng_dialer_getopt(nng_dialer, const char *, void *, size_t *);
+NNG_DECL int nng_dialer_getopt_bool(nng_dialer, const char *, bool *);
+NNG_DECL int nng_dialer_getopt_int(nng_dialer, const char *, int *);
+NNG_DECL int nng_dialer_getopt_ms(nng_dialer, const char *, nng_duration *);
+NNG_DECL int nng_dialer_getopt_size(nng_dialer, const char *, size_t *);
+NNG_DECL int nng_dialer_getopt_sockaddr(
+ nng_dialer, const char *, nng_sockaddr *);
+NNG_DECL int nng_dialer_getopt_uint64(nng_dialer, const char *, uint64_t *);
+NNG_DECL int nng_dialer_getopt_ptr(nng_dialer, const char *, void **);
+NNG_DECL int nng_dialer_getopt_string(nng_dialer, const char *, char **);
+NNG_DECL int nng_dialer_setopt(nng_dialer, const char *, const void *, size_t);
+NNG_DECL int nng_dialer_setopt_bool(nng_dialer, const char *, bool);
+NNG_DECL int nng_dialer_setopt_int(nng_dialer, const char *, int);
+NNG_DECL int nng_dialer_setopt_ms(nng_dialer, const char *, nng_duration);
+NNG_DECL int nng_dialer_setopt_size(nng_dialer, const char *, size_t);
+NNG_DECL int nng_dialer_setopt_uint64(nng_dialer, const char *, uint64_t);
+NNG_DECL int nng_dialer_setopt_ptr(nng_dialer, const char *, void *);
+NNG_DECL int nng_dialer_setopt_string(nng_dialer, const char *, const char *);
+
+// Listener options. Use nng_listener_get and nng_listener_set instead.
+NNG_DECL int nng_listener_getopt(nng_listener, const char *, void *, size_t *);
+NNG_DECL int nng_listener_getopt_bool(nng_listener, const char *, bool *);
+NNG_DECL int nng_listener_getopt_int(nng_listener, const char *, int *);
+NNG_DECL int nng_listener_getopt_ms(
+ nng_listener, const char *, nng_duration *);
+NNG_DECL int nng_listener_getopt_size(nng_listener, const char *, size_t *);
+NNG_DECL int nng_listener_getopt_sockaddr(
+ nng_listener, const char *, nng_sockaddr *);
+NNG_DECL int nng_listener_getopt_uint64(
+ nng_listener, const char *, uint64_t *);
+NNG_DECL int nng_listener_getopt_ptr(nng_listener, const char *, void **);
+NNG_DECL int nng_listener_getopt_string(nng_listener, const char *, char **);
+NNG_DECL int nng_listener_setopt(
+ nng_listener, const char *, const void *, size_t);
+NNG_DECL int nng_listener_setopt_bool(nng_listener, const char *, bool);
+NNG_DECL int nng_listener_setopt_int(nng_listener, const char *, int);
+NNG_DECL int nng_listener_setopt_ms(nng_listener, const char *, nng_duration);
+NNG_DECL int nng_listener_setopt_size(nng_listener, const char *, size_t);
+NNG_DECL int nng_listener_setopt_uint64(nng_listener, const char *, uint64_t);
+NNG_DECL int nng_listener_setopt_ptr(nng_listener, const char *, void *);
+NNG_DECL int nng_listener_setopt_string(
+ nng_listener, const char *, const char *);
+
+// Pipe options. Use nng_pipe_get instead.
+NNG_DECL int nng_pipe_getopt(nng_pipe, const char *, void *, size_t *);
+NNG_DECL int nng_pipe_getopt_bool(nng_pipe, const char *, bool *);
+NNG_DECL int nng_pipe_getopt_int(nng_pipe, const char *, int *);
+NNG_DECL int nng_pipe_getopt_ms(nng_pipe, const char *, nng_duration *);
+NNG_DECL int nng_pipe_getopt_size(nng_pipe, const char *, size_t *);
+NNG_DECL int nng_pipe_getopt_sockaddr(nng_pipe, const char *, nng_sockaddr *);
+NNG_DECL int nng_pipe_getopt_uint64(nng_pipe, const char *, uint64_t *);
+NNG_DECL int nng_pipe_getopt_ptr(nng_pipe, const char *, void **);
+NNG_DECL int nng_pipe_getopt_string(nng_pipe, const char *, char **);
+
+// nng_closeall closes all open sockets. Do not call this from
+// a library; it will affect all sockets.
+NNG_DECL void nng_closeall(void);
+
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/perf/perf.c b/perf/perf.c
index 6df2873c..f1995aba 100644
--- a/perf/perf.c
+++ b/perf/perf.c
@@ -554,9 +554,9 @@ throughput_server(const char *addr, size_t msgsize, int count)
if ((rv = nng_pair_open(&s)) != 0) {
die("nng_socket: %s", nng_strerror(rv));
}
- rv = nng_setopt_int(s, NNG_OPT_RECVBUF, 128);
+ rv = nng_socket_set_int(s, NNG_OPT_RECVBUF, 128);
if (rv != 0) {
- die("nng_setopt(nng_opt_recvbuf): %s", nng_strerror(rv));
+ die("nng_socket_set(nng_opt_recvbuf): %s", nng_strerror(rv));
}
// XXX: set no delay
@@ -617,14 +617,14 @@ throughput_client(const char *addr, size_t msgsize, int count)
// XXX: set no delay
// XXX: other options (TLS in the future?, Linger?)
- rv = nng_setopt_int(s, NNG_OPT_SENDBUF, 128);
+ rv = nng_socket_set_int(s, NNG_OPT_SENDBUF, 128);
if (rv != 0) {
- die("nng_setopt(nng_opt_sendbuf): %s", nng_strerror(rv));
+ die("nng_socket_set(nng_opt_sendbuf): %s", nng_strerror(rv));
}
- rv = nng_setopt_ms(s, NNG_OPT_RECVTIMEO, 5000);
+ rv = nng_socket_set_ms(s, NNG_OPT_RECVTIMEO, 5000);
if (rv != 0) {
- die("nng_setopt(nng_opt_recvtimeo): %s", nng_strerror(rv));
+ die("nng_socket_set(nng_opt_recvtimeo): %s", nng_strerror(rv));
}
if ((rv = nng_dial(s, addr, NULL, 0)) != 0) {
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 889b770d..57e6596c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,7 +8,7 @@
# found online at https://opensource.org/licenses/MIT.
#
-nng_sources(nng.c)
+nng_sources(nng.c nng_legacy.c)
nng_headers(nng/nng.h)
diff --git a/src/core/options.c b/src/core/options.c
index 82735369..5de87c61 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -55,6 +55,7 @@ nni_copyin_bool(bool *bp, const void *v, size_t sz, nni_type t)
if (sz != sizeof(bool)) {
return (NNG_EINVAL);
}
+ // NB: C99 does not require that sizeof (bool) == 1.
if (bp != NULL) {
memcpy(bp, v, sz);
}
@@ -158,15 +159,18 @@ nni_copyin_str(char *s, const void *v, size_t sz, size_t maxsz, nni_type t)
switch (t) {
case NNI_TYPE_STRING:
+ z = v == NULL ? 0 : strlen(v);
+ break;
case NNI_TYPE_OPAQUE:
- if ((z = nni_strnlen(v, sz)) >= sz) {
+ z = v == NULL ? 0 : nni_strnlen(v, sz);
+ if (z >= sz) {
return (NNG_EINVAL); // missing terminator
}
break;
default:
return (NNG_EBADTYPE);
}
- if (z > maxsz) {
+ if (z >= maxsz) {
return (NNG_EINVAL); // too long
}
if (s != NULL) {
@@ -245,7 +249,6 @@ nni_copyout_bool(bool b, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_BOOL:
- NNI_ASSERT(*szp == sizeof(b));
*(bool *) dst = b;
return (0);
case NNI_TYPE_OPAQUE:
@@ -260,7 +263,6 @@ nni_copyout_int(int i, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_INT32:
- NNI_ASSERT(*szp == sizeof(i));
*(int *) dst = i;
return (0);
case NNI_TYPE_OPAQUE:
@@ -275,7 +277,6 @@ nni_copyout_ms(nng_duration d, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_DURATION:
- NNI_ASSERT(*szp == sizeof(d));
*(nng_duration *) dst = d;
return (0);
case NNI_TYPE_OPAQUE:
@@ -290,7 +291,6 @@ nni_copyout_ptr(void *p, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_POINTER:
- NNI_ASSERT(*szp == sizeof(p));
*(void **) dst = p;
return (0);
case NNI_TYPE_OPAQUE:
@@ -305,7 +305,6 @@ nni_copyout_size(size_t s, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_SIZE:
- NNI_ASSERT(*szp == sizeof(s));
*(size_t *) dst = s;
return (0);
case NNI_TYPE_OPAQUE:
@@ -321,7 +320,6 @@ nni_copyout_sockaddr(
{
switch (t) {
case NNI_TYPE_SOCKADDR:
- NNI_ASSERT(*szp == sizeof(*sap));
*(nng_sockaddr *) dst = *sap;
return (0);
case NNI_TYPE_OPAQUE:
@@ -336,7 +334,6 @@ nni_copyout_u64(uint64_t u, void *dst, size_t *szp, nni_type t)
{
switch (t) {
case NNI_TYPE_UINT64:
- NNI_ASSERT(*szp == sizeof(u));
*(uint64_t *) dst = u;
return (0);
case NNI_TYPE_OPAQUE:
@@ -353,7 +350,6 @@ nni_copyout_str(const char *str, void *dst, size_t *szp, nni_type t)
switch (t) {
case NNI_TYPE_STRING:
- NNI_ASSERT(*szp == sizeof(char *));
if ((s = nni_strdup(str)) == NULL) {
return (NNG_ENOMEM);
}
@@ -399,19 +395,3 @@ nni_setopt(const nni_option *opts, const char *nm, void *arg, const void *buf,
}
return (NNG_ENOTSUP);
}
-
-int
-nni_chkopt(const nni_chkoption *opts, const char *nm, const void *buf,
- size_t sz, nni_type t)
-{
- while (opts->o_name != NULL) {
- if (strcmp(opts->o_name, nm) == 0) {
- if (opts->o_check == NULL) {
- return (NNG_EREADONLY);
- }
- return (opts->o_check(buf, sz, t));
- }
- opts++;
- }
- return (NNG_ENOTSUP);
-} \ No newline at end of file
diff --git a/src/core/options.h b/src/core/options.h
index 41d10365..9c5d4817 100644
--- a/src/core/options.h
+++ b/src/core/options.h
@@ -74,191 +74,11 @@ struct nni_option_s {
int (*o_set)(void *, const void *, size_t, nni_type);
};
-typedef struct nni_chkoption_s nni_chkoption;
-struct nni_chkoption_s {
- const char *o_name;
- // o_check can be NULL for read-only options
- int (*o_check)(const void *, size_t, nni_type);
-};
-
// nni_getopt and nni_setopt are helper functions to implement options
// based on arrays of nni_option structures.
extern int nni_getopt(
const nni_option *, const char *, void *, void *, size_t *, nni_type);
extern int nni_setopt(
const nni_option *, const char *, void *, const void *, size_t, nni_type);
-extern int nni_chkopt(
- const nni_chkoption *, const char *, const void *, size_t, nni_type);
-
-//
-// This next block sets up to define the various typed option functions.
-// To make it easier to cover them all at once, we use macros.
-//
-
-#define NNI_DEFGET(base, pointer) \
- int nng_##base##_get( \
- nng_##base pointer s, const char *nm, void *vp, size_t *szp) \
- { \
- return (nni_##base##_getx(s, nm, vp, szp, NNI_TYPE_OPAQUE)); \
- }
-
-#define NNI_DEFTYPEDGET(base, suffix, pointer, type, nnitype) \
- int nng_##base##_get_##suffix( \
- nng_##base pointer s, const char *nm, type *vp) \
- { \
- size_t sz = sizeof(*vp); \
- return (nni_##base##_getx(s, nm, vp, &sz, nnitype)); \
- }
-
-#define NNI_DEFGETALL(base) \
- NNI_DEFGET(base, ) \
- NNI_DEFTYPEDGET(base, int, , int, NNI_TYPE_INT32) \
- NNI_DEFTYPEDGET(base, bool, , bool, NNI_TYPE_BOOL) \
- NNI_DEFTYPEDGET(base, size, , size_t, NNI_TYPE_SIZE) \
- NNI_DEFTYPEDGET(base, uint64, , uint64_t, NNI_TYPE_UINT64) \
- NNI_DEFTYPEDGET(base, string, , char *, NNI_TYPE_STRING) \
- NNI_DEFTYPEDGET(base, ptr, , void *, NNI_TYPE_POINTER) \
- NNI_DEFTYPEDGET(base, ms, , nng_duration, NNI_TYPE_DURATION) \
- NNI_DEFTYPEDGET(base, addr, , nng_sockaddr, NNI_TYPE_SOCKADDR)
-
-#define NNI_DEFGETALL_PTR(base) \
- NNI_DEFGET(base, *) \
- NNI_DEFTYPEDGET(base, int, *, int, NNI_TYPE_INT32) \
- NNI_DEFTYPEDGET(base, bool, *, bool, NNI_TYPE_BOOL) \
- NNI_DEFTYPEDGET(base, size, *, size_t, NNI_TYPE_SIZE) \
- NNI_DEFTYPEDGET(base, uint64, *, uint64_t, NNI_TYPE_UINT64) \
- NNI_DEFTYPEDGET(base, string, *, char *, NNI_TYPE_STRING) \
- NNI_DEFTYPEDGET(base, ptr, *, void *, NNI_TYPE_POINTER) \
- NNI_DEFTYPEDGET(base, ms, *, nng_duration, NNI_TYPE_DURATION) \
- NNI_DEFTYPEDGET(base, addr, *, nng_sockaddr, NNI_TYPE_SOCKADDR)
-
-#define NNI_DEFSET(base, pointer) \
- int nng_##base##_set( \
- nng_##base pointer s, const char *nm, const void *vp, size_t sz) \
- { \
- return (nni_##base##_setx(s, nm, vp, sz, NNI_TYPE_OPAQUE)); \
- }
-
-#define NNI_DEFTYPEDSETEX(base, suffix, pointer, type, len, nnitype) \
- int nng_##base##_set_##suffix( \
- nng_##base pointer s, const char *nm, type v) \
- { \
- return (nni_##base##_setx(s, nm, &v, len, nnitype)); \
- }
-
-#define NNI_DEFTYPEDSET(base, suffix, pointer, type, nnitype) \
- int nng_##base##_set_##suffix( \
- nng_##base pointer s, const char *nm, type v) \
- { \
- return (nni_##base##_setx(s, nm, &v, sizeof(v), nnitype)); \
- }
-
-#define NNI_DEFSTRINGSET(base, pointer) \
- int nng_##base##_set_string( \
- nng_##base pointer s, const char *nm, const char *v) \
- { \
- return (nni_##base##_setx(s, nm, v, \
- v != NULL ? strlen(v) + 1 : 0, NNI_TYPE_STRING)); \
- }
-
-#define NNI_DEFSOCKADDRSET(base, pointer) \
- int nng_##base##_set_addr( \
- nng_##base pointer s, const char *nm, const nng_sockaddr *v) \
- { \
- return (nni_##base##_setx( \
- s, nm, v, sizeof(*v), NNI_TYPE_SOCKADDR)); \
- }
-
-#define NNI_DEFSETALL(base) \
- NNI_DEFSET(base, ) \
- NNI_DEFTYPEDSET(base, int, , int, NNI_TYPE_INT32) \
- NNI_DEFTYPEDSET(base, bool, , bool, NNI_TYPE_BOOL) \
- NNI_DEFTYPEDSET(base, size, , size_t, NNI_TYPE_SIZE) \
- NNI_DEFTYPEDSET(base, uint64, , uint64_t, NNI_TYPE_UINT64) \
- NNI_DEFTYPEDSET(base, ms, , nng_duration, NNI_TYPE_DURATION) \
- NNI_DEFTYPEDSET(base, ptr, , void *, NNI_TYPE_POINTER) \
- NNI_DEFSTRINGSET(base, ) \
- NNI_DEFSOCKADDRSET(base, )
-
-#define NNI_DEFSETALL_PTR(base) \
- NNI_DEFSET(base, *) \
- NNI_DEFTYPEDSET(base, int, *, int, NNI_TYPE_INT32) \
- NNI_DEFTYPEDSET(base, bool, *, bool, NNI_TYPE_BOOL) \
- NNI_DEFTYPEDSET(base, size, *, size_t, NNI_TYPE_SIZE) \
- NNI_DEFTYPEDSET(base, uint64, *, uint64_t, NNI_TYPE_UINT64) \
- NNI_DEFTYPEDSET(base, ms, *, nng_duration, NNI_TYPE_DURATION) \
- NNI_DEFTYPEDSET(base, ptr, *, void *, NNI_TYPE_POINTER) \
- NNI_DEFSTRINGSET(base, *) \
- NNI_DEFSOCKADDRSET(base, *)
-
-#define NNI_LEGACY_DEFGET(base) \
- int nng_##base##_getopt( \
- nng_##base s, const char *nm, void *vp, size_t *szp) \
- { \
- return (nng_##base##_get(s, nm, vp, szp)); \
- }
-
-#define NNI_LEGACY_DEFTYPEDGET(base, suffix, type) \
- int nng_##base##_getopt_##suffix( \
- nng_##base s, const char *nm, type *vp) \
- { \
- return (nng_##base##_get_##suffix(s, nm, vp)); \
- }
-
-#define NNI_LEGACY_DEFSOCKADDRGET(base) \
- int nng_##base##_getopt_sockaddr( \
- nng_##base s, const char *nm, nng_sockaddr *vp) \
- { \
- return (nng_##base##_get_addr(s, nm, vp)); \
- }
-
-#define NNI_LEGACY_DEFGETALL(base) \
- NNI_LEGACY_DEFGET(base) \
- NNI_LEGACY_DEFTYPEDGET(base, int, int) \
- NNI_LEGACY_DEFTYPEDGET(base, bool, bool) \
- NNI_LEGACY_DEFTYPEDGET(base, size, size_t) \
- NNI_LEGACY_DEFTYPEDGET(base, uint64, uint64_t) \
- NNI_LEGACY_DEFTYPEDGET(base, string, char *) \
- NNI_LEGACY_DEFTYPEDGET(base, ptr, void *) \
- NNI_LEGACY_DEFTYPEDGET(base, ms, nng_duration) \
- NNI_LEGACY_DEFSOCKADDRGET(base)
-
-#define NNI_LEGACY_DEFSET(base) \
- int nng_##base##_setopt( \
- nng_##base s, const char *nm, const void *vp, size_t sz) \
- { \
- return (nng_##base##_set(s, nm, vp, sz)); \
- }
-
-#define NNI_LEGACY_DEFTYPEDSET(base, suffix, type) \
- int nng_##base##_setopt_##suffix(nng_##base s, const char *nm, type v) \
- { \
- return (nng_##base##_set_##suffix(s, nm, v)); \
- }
-
-#define NNI_LEGACY_DEFSTRINGSET(base) \
- int nng_##base##_setopt_string( \
- nng_##base s, const char *nm, const char *v) \
- { \
- return (nng_##base##_set_string(s, nm, v)); \
- }
-
-#define NNI_LEGACY_DEFSOCKADDRSET(base) \
- int nng_##base##_setopt_sockaddr( \
- nng_##base s, const char *nm, const nng_sockaddr *v) \
- { \
- return (nng_##base##_set_addr(s, nm, v)); \
- }
-
-#define NNI_LEGACY_DEFSETALL(base) \
- NNI_LEGACY_DEFSET(base) \
- NNI_LEGACY_DEFTYPEDSET(base, int, int) \
- NNI_LEGACY_DEFTYPEDSET(base, bool, bool) \
- NNI_LEGACY_DEFTYPEDSET(base, size, size_t) \
- NNI_LEGACY_DEFTYPEDSET(base, uint64, uint64_t) \
- NNI_LEGACY_DEFTYPEDSET(base, ms, nng_duration) \
- NNI_LEGACY_DEFTYPEDSET(base, ptr, void*) \
- NNI_LEGACY_DEFSTRINGSET(base) \
- NNI_LEGACY_DEFSOCKADDRSET(base)
#endif // CORE_OPTIONS_H
diff --git a/src/core/platform.h b/src/core/platform.h
index 704e338d..35d42339 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -280,8 +280,8 @@ extern int nni_tcp_dialer_init(nni_tcp_dialer **);
extern void nni_tcp_dialer_fini(nni_tcp_dialer *);
// nni_tcp_dialer_close closes the dialer.
-// Further operations on it should return NNG_ECLOSED. Any in-progress
-// connection will be aborted.
+// Further operations on it should return NNG_ECLOSED.
+// Any in-progress connection will be aborted.
extern void nni_tcp_dialer_close(nni_tcp_dialer *);
// nni_tcp_dial attempts to create an outgoing connection,
@@ -289,16 +289,12 @@ extern void nni_tcp_dialer_close(nni_tcp_dialer *);
// output will be an nni_tcp_conn * associated with the remote server.
extern void nni_tcp_dial(nni_tcp_dialer *, const nng_sockaddr *, nni_aio *);
-// nni_tcp_dialer_getopt gets an option from the dialer.
-extern int nni_tcp_dialer_setopt(
+// nni_tcp_dialer_set sets an option on the dialer.
+extern int nni_tcp_dialer_set(
nni_tcp_dialer *, const char *, const void *, size_t, nni_type);
-// nni_tcp_dialer_setopt sets an option on the dialer. There is special
-// support for NNG_OPT_LOCADDR, which will be the source address (if legal)
-// for new connections, except that the port will be ignored. The
-// NNG_OPT_TCP_NODELAY and NNG_OPT_TCP_KEEPALIVE options work to set the
-// initial values of those options on newly created connections.
-extern int nni_tcp_dialer_getopt(
+// nni_tcp_dialer_get gets an option on the dialer.
+extern int nni_tcp_dialer_get(
nni_tcp_dialer *, const char *, void *, size_t *, nni_type);
// nni_tcp_listener_init creates a new listener object, unbound.
@@ -321,14 +317,14 @@ extern int nni_tcp_listener_listen(nni_tcp_listener *, const nni_sockaddr *);
// associated with the remote peer.
extern void nni_tcp_listener_accept(nni_tcp_listener *, nni_aio *);
-// nni_tcp_listener_getopt gets an option from the listener.
-extern int nni_tcp_listener_setopt(
+// nni_tcp_listener_set sets an option on the listener.
+extern int nni_tcp_listener_set(
nni_tcp_listener *, const char *, const void *, size_t, nni_type);
-// nni_tcp_listener_setopt sets an option on the listener. The most common
+// nni_tcp_listener_get gets an option from the listener. The most common
// use for this is to retrieve the setting of the NNG_OPT_TCP_LOCADDR
// address after binding to wild card port (0).
-extern int nni_tcp_listener_getopt(
+extern int nni_tcp_listener_get(
nni_tcp_listener *, const char *, void *, size_t *, nni_type);
// nni_resolv_ip resolves a DNS host and service name asynchronously.
@@ -339,8 +335,8 @@ extern int nni_tcp_listener_getopt(
// connect(). The host part may be NULL only if passive is true.
// Symbolic service names will be looked up assuming SOCK_STREAM, so
// they may not work with UDP.
-extern void nni_resolv_ip(const char *, const char *, int, bool,
- nng_sockaddr *sa, nni_aio *);
+extern void nni_resolv_ip(
+ const char *, const char *, int, bool, nng_sockaddr *sa, nni_aio *);
// nni_parse_ip parses an IP address, without a port.
extern int nni_parse_ip(const char *, nng_sockaddr *);
@@ -361,7 +357,6 @@ typedef struct nni_ipc_listener nni_ipc_listener;
// be stubs that just return NNG_ENOTSUP.
extern int nni_ipc_dialer_alloc(nng_stream_dialer **, const nng_url *);
extern int nni_ipc_listener_alloc(nng_stream_listener **, const nng_url *);
-extern int nni_ipc_checkopt(const char *, const void *, size_t, nni_type);
//
// UDP support. UDP is not connection oriented, and only has the notion
diff --git a/src/core/socket.c b/src/core/socket.c
index 72c55c7a..f741b6f0 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -983,11 +983,9 @@ int
nni_sock_setopt(
nni_sock *s, const char *name, const void *v, size_t sz, nni_type t)
{
- int rv;
- nni_dialer * d;
- nni_listener *l;
- nni_sockopt * optv;
- nni_sockopt * oldv = NULL;
+ int rv;
+ nni_sockopt *optv;
+ nni_sockopt *oldv = NULL;
nni_mtx_lock(&s->s_mx);
if (s->s_closing) {
@@ -1012,17 +1010,67 @@ nni_sock_setopt(
}
nni_mtx_unlock(&s->s_mx);
- // Validation of generic and transport options. This is stateless, so
- // transports should not fail to set an option later if they
- // passed it here.
+ // Validation of generic and transport options.
+ // NOTE: Setting transport options via socket is deprecated.
+ // These options should be set on the endpoint to which they apply.
if ((strcmp(name, NNG_OPT_RECONNMINT) == 0) ||
(strcmp(name, NNG_OPT_RECONNMAXT) == 0)) {
- nng_duration ms;
- if ((rv = nni_copyin_ms(&ms, v, sz, t)) != 0) {
+ if ((rv = nni_copyin_ms(NULL, v, sz, t)) != 0) {
return (rv);
}
- } else if ((rv = nni_tran_chkopt(name, v, sz, t)) != 0) {
- return (rv);
+
+ } else if (strcmp(name, NNG_OPT_RECVMAXSZ) == 0) {
+ if ((rv = nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t)) !=
+ 0) {
+ return (rv);
+ }
+
+#if !defined(NNG_ELIDE_DEPRECATED)
+ // TCP options, set via socket is deprecated.
+ } else if ((strcmp(name, NNG_OPT_TCP_KEEPALIVE) == 0) ||
+ (strcmp(name, NNG_OPT_TCP_NODELAY)) == 0) {
+ if ((rv = nni_copyin_bool(NULL, v, sz, t)) != 0) {
+ return (rv);
+ }
+#endif
+
+#if defined(NNG_SUPP_TLS) && !defined(NNG_ELIDE_DEPRECATED)
+ // TLS options may not be supported if TLS is not
+ // compiled in. Supporting all these is deprecated.
+ } else if (strcmp(name, NNG_OPT_TLS_CONFIG) == 0) {
+ if ((rv = nni_copyin_ptr(NULL, v, sz, t)) != 0) {
+ return (rv);
+ }
+ } else if ((strcmp(name, NNG_OPT_TLS_SERVER_NAME) == 0) ||
+ (strcmp(name, NNG_OPT_TLS_CA_FILE) == 0) ||
+ (strcmp(name, NNG_OPT_TLS_CERT_KEY_FILE) == 0)) {
+ if ((t != NNI_TYPE_OPAQUE) && (t != NNI_TYPE_STRING)) {
+ return (NNG_EBADTYPE);
+ }
+ if (nni_strnlen(v, sz) >= sz) {
+ return (NNG_EINVAL);
+ }
+ } else if ((strcmp(name, NNG_OPT_TLS_AUTH_MODE) == 0)) {
+ // 0, 1, or 2 (none, optional, required)
+ if ((rv = nni_copyin_int(NULL, v, sz, 0, 2, t)) != 0) {
+ return (rv);
+ }
+#endif
+
+#if defined(NNG_PLATFORM_POSIX) && !defined(NNG_SUPPRESS_DEPRECATED)
+ } else if (strcmp(name, NNG_OPT_IPC_PERMISSIONS) == 0) {
+ // UNIX mode bits are 0777, but allow set id and sticky bits
+ if ((rv = nni_copyin_int(NULL, v, sz, 0, 07777, t)) != 0) {
+ return (rv);
+ }
+#endif
+
+#if defined(NNG_PLATFORM_WINDOWS) && !defined(NNG_SUPPRESS_DEPRECATED)
+ } else if (strcmp(name, NNG_OPT_IPC_SECURITY_DESCRIPTOR) == 0) {
+ if ((rv = nni_copyin_ptr(NULL, v, sz, t)) == 0) {
+ return (rv);
+ }
+#endif
}
// Prepare a copy of the socket option.
@@ -1058,6 +1106,10 @@ nni_sock_setopt(
}
}
+#ifndef NNG_ELIDE_DEPRCATED
+ nni_dialer * d;
+ nni_listener *l;
+
// Apply the options. Failure to set any option on any
// transport (other than ENOTSUP) stops the operation
// altogether. Its important that transport wide checks
@@ -1084,6 +1136,7 @@ nni_sock_setopt(
}
}
}
+#endif
if (rv == 0) {
// Remove and toss the old value; we are using a new one.
@@ -1151,10 +1204,12 @@ nni_sock_getopt(
}
}
- if (sopt->sz > *szp) {
- sz = *szp;
+ if (szp != NULL) {
+ if (sopt->sz > *szp) {
+ sz = *szp;
+ }
+ *szp = sopt->sz;
}
- *szp = sopt->sz;
memcpy(val, sopt->data, sz);
rv = 0;
break;
diff --git a/src/core/stream.c b/src/core/stream.c
index 9309a3a0..418bfb15 100644
--- a/src/core/stream.c
+++ b/src/core/stream.c
@@ -23,90 +23,76 @@ static struct {
const char *scheme;
int (*dialer_alloc)(nng_stream_dialer **, const nng_url *);
int (*listener_alloc)(nng_stream_listener **, const nng_url *);
- int (*checkopt)(const char *, const void *, size_t, nni_type);
} stream_drivers[] = {
{
.scheme = "ipc",
.dialer_alloc = nni_ipc_dialer_alloc,
.listener_alloc = nni_ipc_listener_alloc,
- .checkopt = nni_ipc_checkopt,
},
#ifdef NNG_PLATFORM_POSIX
{
.scheme = "unix",
.dialer_alloc = nni_ipc_dialer_alloc,
.listener_alloc = nni_ipc_listener_alloc,
- .checkopt = nni_ipc_checkopt,
},
#endif
#ifdef NNG_HAVE_ABSTRACT_SOCKETS
{
- .scheme = "abstract",
- .dialer_alloc = nni_ipc_dialer_alloc,
- .listener_alloc = nni_ipc_listener_alloc,
- .checkopt = nni_ipc_checkopt,
- },
+ .scheme = "abstract",
+ .dialer_alloc = nni_ipc_dialer_alloc,
+ .listener_alloc = nni_ipc_listener_alloc,
+ },
#endif
- {
+ {
.scheme = "tcp",
.dialer_alloc = nni_tcp_dialer_alloc,
.listener_alloc = nni_tcp_listener_alloc,
- .checkopt = nni_tcp_checkopt,
},
{
.scheme = "tcp4",
.dialer_alloc = nni_tcp_dialer_alloc,
.listener_alloc = nni_tcp_listener_alloc,
- .checkopt = nni_tcp_checkopt,
},
{
.scheme = "tcp6",
.dialer_alloc = nni_tcp_dialer_alloc,
.listener_alloc = nni_tcp_listener_alloc,
- .checkopt = nni_tcp_checkopt,
},
{
.scheme = "tls+tcp",
.dialer_alloc = nni_tls_dialer_alloc,
.listener_alloc = nni_tls_listener_alloc,
- .checkopt = nni_tls_checkopt,
},
{
.scheme = "tls+tcp4",
.dialer_alloc = nni_tls_dialer_alloc,
.listener_alloc = nni_tls_listener_alloc,
- .checkopt = nni_tls_checkopt,
},
{
.scheme = "tls+tcp6",
.dialer_alloc = nni_tls_dialer_alloc,
.listener_alloc = nni_tls_listener_alloc,
- .checkopt = nni_tls_checkopt,
},
{
.scheme = "ws",
.dialer_alloc = nni_ws_dialer_alloc,
.listener_alloc = nni_ws_listener_alloc,
- .checkopt = nni_ws_checkopt,
},
- {
- .scheme = "ws4",
- .dialer_alloc = nni_ws_dialer_alloc,
- .listener_alloc = nni_ws_listener_alloc,
- .checkopt = nni_ws_checkopt,
- },
- {
- .scheme = "ws6",
- .dialer_alloc = nni_ws_dialer_alloc,
- .listener_alloc = nni_ws_listener_alloc,
- .checkopt = nni_ws_checkopt,
- },
- {
+ {
+ .scheme = "ws4",
+ .dialer_alloc = nni_ws_dialer_alloc,
+ .listener_alloc = nni_ws_listener_alloc,
+ },
+ {
+ .scheme = "ws6",
+ .dialer_alloc = nni_ws_dialer_alloc,
+ .listener_alloc = nni_ws_listener_alloc,
+ },
+ {
.scheme = "wss",
.dialer_alloc = nni_ws_dialer_alloc,
.listener_alloc = nni_ws_listener_alloc,
- .checkopt = nni_ws_checkopt,
},
{
.scheme = NULL,
@@ -140,17 +126,17 @@ nng_stream_recv(nng_stream *s, nng_aio *aio)
}
int
-nni_stream_getx(
+nni_stream_get(
nng_stream *s, const char *nm, void *data, size_t *szp, nni_type t)
{
- return (s->s_getx(s, nm, data, szp, t));
+ return (s->s_get(s, nm, data, szp, t));
}
int
-nni_stream_setx(
+nni_stream_set(
nng_stream *s, const char *nm, const void *data, size_t sz, nni_type t)
{
- return (s->s_setx(s, nm, data, sz, t));
+ return (s->s_set(s, nm, data, sz, t));
}
void
@@ -208,17 +194,17 @@ nng_stream_dialer_alloc(nng_stream_dialer **dp, const char *uri)
}
int
-nni_stream_dialer_getx(
+nni_stream_dialer_get(
nng_stream_dialer *d, const char *nm, void *data, size_t *szp, nni_type t)
{
- return (d->sd_getx(d, nm, data, szp, t));
+ return (d->sd_get(d, nm, data, szp, t));
}
int
-nni_stream_dialer_setx(nng_stream_dialer *d, const char *nm, const void *data,
+nni_stream_dialer_set(nng_stream_dialer *d, const char *nm, const void *data,
size_t sz, nni_type t)
{
- return (d->sd_setx(d, nm, data, sz, t));
+ return (d->sd_set(d, nm, data, sz, t));
}
void
@@ -246,17 +232,17 @@ nng_stream_listener_accept(nng_stream_listener *l, nng_aio *aio)
}
int
-nni_stream_listener_getx(nng_stream_listener *l, const char *nm, void *data,
+nni_stream_listener_get(nng_stream_listener *l, const char *nm, void *data,
size_t *szp, nni_type t)
{
- return (l->sl_getx(l, nm, data, szp, t));
+ return (l->sl_get(l, nm, data, szp, t));
}
int
-nni_stream_listener_setx(nng_stream_listener *l, const char *nm,
+nni_stream_listener_set(nng_stream_listener *l, const char *nm,
const void *data, size_t sz, nni_type t)
{
- return (l->sl_setx(l, nm, data, sz, t));
+ return (l->sl_set(l, nm, data, sz, t));
}
int
@@ -294,26 +280,348 @@ nng_stream_listener_alloc(nng_stream_listener **lp, const char *uri)
return (rv);
}
+// Public stream options.
+
int
-nni_stream_checkopt(const char *scheme, const char *name, const void *data,
- size_t sz, nni_type t)
+nng_stream_get(nng_stream *s, const char *n, void *v, size_t *szp)
{
- for (int i = 0; stream_drivers[i].scheme != NULL; i++) {
- if (strcmp(stream_drivers[i].scheme, scheme) != 0) {
- continue;
- }
- if (stream_drivers[i].checkopt == NULL) {
- return (NNG_ENOTSUP);
- }
- return (stream_drivers[i].checkopt(name, data, sz, t));
- }
- return (NNG_ENOTSUP);
+ return (nni_stream_get(s, n, v, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_stream_get_int(nng_stream *s, const char *n, int *v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_stream_get_bool(nng_stream *s, const char *n, bool *v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_get_size(nng_stream *s, const char *n, size_t *v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_get_uint64(nng_stream *s, const char *n, uint64_t *v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_stream_get_string(nng_stream *s, const char *n, char **v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_get_ptr(nng_stream *s, const char *n, void **v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_get_ms(nng_stream *s, const char *n, nng_duration *v)
+{
+ return (nni_stream_get(s, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+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)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_stream_dialer_get_bool(nng_stream_dialer *d, const char *n, bool *v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_dialer_get_size(nng_stream_dialer *d, const char *n, size_t *v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_dialer_get_uint64(nng_stream_dialer *d, const char *n, uint64_t *v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_stream_dialer_get_string(nng_stream_dialer *d, const char *n, char **v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_dialer_get_ptr(nng_stream_dialer *d, const char *n, void **v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_dialer_get_ms(nng_stream_dialer *d, const char *n, nng_duration *v)
+{
+ return (nni_stream_dialer_get(d, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_stream_dialer_get_addr(
+ nng_stream_dialer *d, const char *n, nng_sockaddr *v)
+{
+ 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)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_stream_listener_get_bool(nng_stream_listener *l, const char *n, bool *v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_listener_get_size(nng_stream_listener *l, const char *n, size_t *v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_listener_get_uint64(
+ nng_stream_listener *l, const char *n, uint64_t *v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_stream_listener_get_string(nng_stream_listener *l, const char *n, char **v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_listener_get_ptr(nng_stream_listener *l, const char *n, void **v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_listener_get_ms(
+ nng_stream_listener *l, const char *n, nng_duration *v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_stream_listener_get_addr(
+ nng_stream_listener *l, const char *n, nng_sockaddr *v)
+{
+ return (nni_stream_listener_get(l, n, v, NULL, NNI_TYPE_SOCKADDR));
+}
+
+int
+nng_stream_set(nng_stream *s, const char *n, const void *v, size_t sz)
+{
+ return (nni_stream_set(s, n, v, sz, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_stream_set_int(nng_stream *s, const char *n, int v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_stream_set_bool(nng_stream *s, const char *n, bool v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_set_size(nng_stream *s, const char *n, size_t v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_set_uint64(nng_stream *s, const char *n, uint64_t v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_UINT64));
}
-NNI_DEFGETALL_PTR(stream)
-NNI_DEFGETALL_PTR(stream_dialer)
-NNI_DEFGETALL_PTR(stream_listener)
+int
+nng_stream_set_ms(nng_stream *s, const char *n, nng_duration v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_stream_set_ptr(nng_stream *s, const char *n, void *v)
+{
+ return (nni_stream_set(s, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_set_string(nng_stream *s, const char *n, const char *v)
+{
+ return (nni_stream_set(
+ s, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_set_addr(nng_stream *s, const char *n, const nng_sockaddr *v)
+{
+ return (nni_stream_set(s, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
-NNI_DEFSETALL_PTR(stream)
-NNI_DEFSETALL_PTR(stream_dialer)
-NNI_DEFSETALL_PTR(stream_listener) \ No newline at end of file
+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)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_stream_dialer_set_bool(nng_stream_dialer *d, const char *n, bool v)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_dialer_set_size(nng_stream_dialer *d, const char *n, size_t v)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_dialer_set_uint64(nng_stream_dialer *d, const char *n, uint64_t v)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_UINT64));
+}
+
+int
+nng_stream_dialer_set_ms(nng_stream_dialer *d, const char *n, nng_duration v)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_stream_dialer_set_ptr(nng_stream_dialer *d, const char *n, void *v)
+{
+ return (nni_stream_dialer_set(d, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_dialer_set_string(
+ nng_stream_dialer *d, const char *n, const char *v)
+{
+ return (nni_stream_dialer_set(
+ d, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_dialer_set_addr(
+ nng_stream_dialer *d, const char *n, const nng_sockaddr *v)
+{
+ 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)
+{
+ return (nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_stream_listener_set_bool(nng_stream_listener *l, const char *n, bool v)
+{
+ return (nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_stream_listener_set_size(nng_stream_listener *l, const char *n, size_t v)
+{
+ return (nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_stream_listener_set_uint64(
+ nng_stream_listener *l, const char *n, uint64_t v)
+{
+ return (nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_UINT64));
+}
+
+int
+nng_stream_listener_set_ms(
+ nng_stream_listener *l, const char *n, nng_duration v)
+{
+ return (
+ nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_stream_listener_set_ptr(nng_stream_listener *l, const char *n, void *v)
+{
+ return (
+ nni_stream_listener_set(l, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_stream_listener_set_string(
+ nng_stream_listener *l, const char *n, const char *v)
+{
+ return (nni_stream_listener_set(
+ l, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_stream_listener_set_addr(
+ nng_stream_listener *l, const char *n, const nng_sockaddr *v)
+{
+ return (
+ nni_stream_listener_set(l, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
diff --git a/src/core/stream.h b/src/core/stream.h
index 18914979..eb3cb93b 100644
--- a/src/core/stream.h
+++ b/src/core/stream.h
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -16,24 +16,21 @@
#include "core/nng_impl.h"
// Private property operations (these include the types.)
-extern int nni_stream_getx(
+extern int nni_stream_get(
nng_stream *, const char *, void *, size_t *, nni_type);
-extern int nni_stream_setx(
+extern int nni_stream_set(
nng_stream *, const char *, const void *, size_t, nni_type);
-extern int nni_stream_dialer_getx(
+extern int nni_stream_dialer_get(
nng_stream_dialer *, const char *, void *, size_t *, nni_type);
-extern int nni_stream_dialer_setx(
+extern int nni_stream_dialer_set(
nng_stream_dialer *, const char *, const void *, size_t, nni_type);
-extern int nni_stream_listener_getx(
+extern int nni_stream_listener_get(
nng_stream_listener *, const char *, void *, size_t *, nni_type);
-extern int nni_stream_listener_setx(
+extern int nni_stream_listener_set(
nng_stream_listener *, const char *, const void *, size_t, nni_type);
-extern int nni_stream_checkopt(
- const char *, const char *, const void *, size_t, nni_type);
-
// This is the common implementation of a connected byte stream. It should be
// the first element of any implementation. Applications are not permitted to
// access it directly.
@@ -42,8 +39,8 @@ struct nng_stream {
void (*s_close)(void *);
void (*s_recv)(void *, nng_aio *);
void (*s_send)(void *, nng_aio *);
- int (*s_getx)(void *, const char *, void *, size_t *, nni_type);
- int (*s_setx)(void *, const char *, const void *, size_t, nni_type);
+ int (*s_get)(void *, const char *, void *, size_t *, nni_type);
+ int (*s_set)(void *, const char *, const void *, size_t, nni_type);
};
// Dialer implementation. Stream dialers create streams.
@@ -51,8 +48,8 @@ struct nng_stream_dialer {
void (*sd_free)(void *);
void (*sd_close)(void *);
void (*sd_dial)(void *, nng_aio *);
- int (*sd_getx)(void *, const char *, void *, size_t *, nni_type);
- int (*sd_setx)(void *, const char *, const void *, size_t, nni_type);
+ int (*sd_get)(void *, const char *, void *, size_t *, nni_type);
+ int (*sd_set)(void *, const char *, const void *, size_t, nni_type);
};
// Listener implementation. Stream listeners accept connections and create
@@ -62,8 +59,8 @@ struct nng_stream_listener {
void (*sl_close)(void *);
int (*sl_listen)(void *);
void (*sl_accept)(void *, nng_aio *);
- int (*sl_getx)(void *, const char *, void *, size_t *, nni_type);
- int (*sl_setx)(void *, const char *, const void *, size_t, nni_type);
+ int (*sl_get)(void *, const char *, void *, size_t *, nni_type);
+ int (*sl_set)(void *, const char *, const void *, size_t, nni_type);
};
#endif // CORE_STREAM_H
diff --git a/src/core/tcp.h b/src/core/tcp.h
index ac4398d0..6e1829dc 100644
--- a/src/core/tcp.h
+++ b/src/core/tcp.h
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -18,7 +18,4 @@
extern int nni_tcp_dialer_alloc(nng_stream_dialer **, const nng_url *);
extern int nni_tcp_listener_alloc(nng_stream_listener **, const nng_url *);
-// nni_tcp_checkopt is used to validate (generically) options.
-extern int nni_tcp_checkopt(const char *, const void *, size_t, nni_type);
-
#endif // CORE_TCP_H
diff --git a/src/core/transport.c b/src/core/transport.c
index 071ea0c7..78859078 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -111,73 +111,6 @@ nni_tran_find(nni_url *url)
return (NULL);
}
-int
-nni_tran_chkopt(const char *name, const void *v, size_t sz, int typ)
-{
- nni_transport *t;
- int rv = NNG_ENOTSUP;
-
- nni_mtx_lock(&nni_tran_lk);
- NNI_LIST_FOREACH (&nni_tran_list, t) {
- const nni_tran_dialer_ops * dops;
- const nni_tran_listener_ops *lops;
- const nni_option * o;
-
- // Check option entry point is cleaner than endpoint hacks.
- if (t->t_tran.tran_checkopt != NULL) {
- rv = t->t_tran.tran_checkopt(name, v, sz, typ);
- if (rv != NNG_ENOTSUP) {
- nni_mtx_unlock(&nni_tran_lk);
- return (rv);
- }
- continue;
- }
-
- // Generally we look for endpoint options. We check both
- // dialers and listeners.
- dops = t->t_tran.tran_dialer;
- if ((dops->d_setopt != NULL) &&
- ((rv = dops->d_setopt(NULL, name, v, sz, typ)) !=
- NNG_ENOTSUP)) {
- nni_mtx_unlock(&nni_tran_lk);
- return (rv);
- }
- for (o = dops->d_options; o && o->o_name != NULL; o++) {
- if (strcmp(name, o->o_name) != 0) {
- continue;
- }
- if (o->o_set == NULL) {
- nni_mtx_unlock(&nni_tran_lk);
- return (NNG_EREADONLY);
- }
- nni_mtx_unlock(&nni_tran_lk);
- rv = o->o_set(NULL, v, sz, typ);
- return (rv);
- }
- lops = t->t_tran.tran_listener;
- if ((lops->l_setopt != NULL) &&
- ((rv = lops->l_setopt(NULL, name, v, sz, typ)) !=
- NNG_ENOTSUP)) {
- nni_mtx_unlock(&nni_tran_lk);
- return (rv);
- }
- for (o = lops->l_options; o && o->o_name != NULL; o++) {
- if (strcmp(name, o->o_name) != 0) {
- continue;
- }
- if (o->o_set == NULL) {
- nni_mtx_unlock(&nni_tran_lk);
- return (NNG_EREADONLY);
- }
- nni_mtx_unlock(&nni_tran_lk);
- rv = o->o_set(NULL, v, sz, typ);
- return (rv);
- }
- }
- nni_mtx_unlock(&nni_tran_lk);
- return (rv);
-}
-
// nni_tran_sys_init initializes the entire transport subsystem, including
// each individual transport.
diff --git a/src/core/transport.h b/src/core/transport.h
index 84d9c1d9..b2da2c7a 100644
--- a/src/core/transport.h
+++ b/src/core/transport.h
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -29,7 +29,8 @@
#define NNI_TRANSPORT_V4 0x54520004
#define NNI_TRANSPORT_V5 0x54520005
#define NNI_TRANSPORT_V6 0x54220006
-#define NNI_TRANSPORT_VERSION NNI_TRANSPORT_V6
+#define NNI_TRANSPORT_V7 0x54220006
+#define NNI_TRANSPORT_VERSION NNI_TRANSPORT_V7
// Endpoint operations are called by the socket in a
// protocol-independent fashion. The socket makes individual calls,
@@ -183,18 +184,11 @@ struct nni_tran {
// tran_fini, if not NULL, is called during library deinitialization.
// It should release any global resources, close any open files, etc.
void (*tran_fini)(void);
-
- // tran_chkopt is used to check option validity; this is used as
- // an initial filter on the data, without actually setting anything.
- // This can be useful, for example, before any transports are
- // configured on the socket.
- int (*tran_checkopt)(const char *, const void *, size_t, nni_type);
};
// These APIs are used by the framework internally, and not for use by
// transport implementations.
extern nni_tran *nni_tran_find(nni_url *);
-extern int nni_tran_chkopt(const char *, const void *, size_t, int);
extern int nni_tran_sys_init(void);
extern void nni_tran_sys_fini(void);
extern int nni_tran_register(const nni_tran *);
diff --git a/src/nng.c b/src/nng.c
index 28876e07..059ec461 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -52,12 +52,6 @@ nng_socket_id(nng_socket s)
return (((int) s.id > 0) ? (int) s.id : -1);
}
-void
-nng_closeall(void)
-{
- nni_sock_closeall();
-}
-
void *
nng_alloc(size_t sz)
{
@@ -323,7 +317,7 @@ nng_ctx_send(nng_ctx cid, nng_aio *aio)
}
static int
-nni_ctx_getx(nng_ctx id, const char *n, void *v, size_t *szp, nni_type t)
+ctx_get(nng_ctx id, const char *n, void *v, size_t *szp, nni_type t)
{
nni_ctx *ctx;
int rv;
@@ -339,8 +333,62 @@ nni_ctx_getx(nng_ctx id, const char *n, void *v, size_t *szp, nni_type t)
return (rv);
}
+int
+nng_ctx_get(nng_ctx id, const char *n, void *v, size_t *szp)
+{
+ return (ctx_get(id, n, v, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_ctx_get_int(nng_ctx id, const char *n, int *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_ctx_get_bool(nng_ctx id, const char *n, bool *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_ctx_get_size(nng_ctx id, const char *n, size_t *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_ctx_get_uint64(nng_ctx id, const char *n, uint64_t *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_ctx_get_string(nng_ctx id, const char *n, char **v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_ctx_get_ptr(nng_ctx id, const char *n, void **v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_ctx_get_ms(nng_ctx id, const char *n, nng_duration *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_ctx_get_addr(nng_ctx id, const char *n, nng_sockaddr *v)
+{
+ return (ctx_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
+}
+
static int
-nni_ctx_setx(nng_ctx id, const char *n, const void *v, size_t sz, nni_type t)
+ctx_set(nng_ctx id, const char *n, const void *v, size_t sz, nni_type t)
{
nni_ctx *ctx;
int rv;
@@ -356,8 +404,60 @@ nni_ctx_setx(nng_ctx id, const char *n, const void *v, size_t sz, nni_type t)
return (rv);
}
-NNI_LEGACY_DEFGETALL(ctx)
-NNI_LEGACY_DEFSETALL(ctx)
+int
+nng_ctx_set(nng_ctx id, const char *n, const void *v, size_t sz)
+{
+ return (ctx_set(id, n, v, sz, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_ctx_set_int(nng_ctx id, const char *n, int v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_ctx_set_bool(nng_ctx id, const char *n, bool v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_ctx_set_size(nng_ctx id, const char *n, size_t v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_ctx_set_uint64(nng_ctx id, const char *n, uint64_t v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_UINT64));
+}
+
+int
+nng_ctx_set_ms(nng_ctx id, const char *n, nng_duration v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_ctx_set_ptr(nng_ctx id, const char *n, void *v)
+{
+ return (ctx_set(id, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_ctx_set_string(nng_ctx id, const char *n, const char *v)
+{
+ return (ctx_set(
+ id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_ctx_set_addr(nng_ctx id, const char *n, const nng_sockaddr *v)
+{
+ return (ctx_set(id, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
int
nng_dial(nng_socket sid, const char *addr, nng_dialer *dp, int flags)
@@ -503,8 +603,7 @@ nng_dialer_id(nng_dialer d)
}
static int
-nni_dialer_setx(
- nng_dialer did, const char *n, const void *v, size_t sz, nni_type t)
+dialer_set(nng_dialer id, const char *n, const void *v, size_t sz, nni_type t)
{
nni_dialer *d;
int rv;
@@ -512,7 +611,7 @@ nni_dialer_setx(
if ((rv = nni_init()) != 0) {
return (rv);
}
- if ((rv = nni_dialer_find(&d, did.id)) != 0) {
+ if ((rv = nni_dialer_find(&d, id.id)) != 0) {
return (rv);
}
rv = nni_dialer_setopt(d, n, v, sz, t);
@@ -520,9 +619,63 @@ nni_dialer_setx(
return (rv);
}
+int
+nng_dialer_set(nng_dialer id, const char *n, const void *v, size_t sz)
+{
+ return (dialer_set(id, n, v, sz, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_dialer_set_int(nng_dialer id, const char *n, int v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_dialer_set_bool(nng_dialer id, const char *n, bool v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_dialer_set_size(nng_dialer id, const char *n, size_t v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_dialer_set_uint64(nng_dialer id, const char *n, uint64_t v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_UINT64));
+}
+
+int
+nng_dialer_set_ms(nng_dialer id, const char *n, nng_duration v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_dialer_set_ptr(nng_dialer id, const char *n, void *v)
+{
+ return (dialer_set(id, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_dialer_set_string(nng_dialer id, const char *n, const char *v)
+{
+ return (dialer_set(
+ id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_dialer_set_addr(nng_dialer id, const char *n, const nng_sockaddr *v)
+{
+ return (dialer_set(id, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
+
static int
-nni_dialer_getx(
- nng_dialer did, const char *n, void *v, size_t *szp, nni_type t)
+dialer_get(nng_dialer id, const char *n, void *v, size_t *szp, nni_type t)
{
nni_dialer *d;
int rv;
@@ -530,7 +683,7 @@ nni_dialer_getx(
if ((rv = nni_init()) != 0) {
return (rv);
}
- if ((rv = nni_dialer_find(&d, did.id)) != 0) {
+ if ((rv = nni_dialer_find(&d, id.id)) != 0) {
return (rv);
}
rv = nni_dialer_getopt(d, n, v, szp, t);
@@ -538,11 +691,62 @@ nni_dialer_getx(
return (rv);
}
-NNI_LEGACY_DEFGETALL(dialer)
-NNI_LEGACY_DEFSETALL(dialer)
+int
+nng_dialer_get(nng_dialer id, const char *n, void *v, size_t *szp)
+{
+ return (dialer_get(id, n, v, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_dialer_get_int(nng_dialer id, const char *n, int *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_INT32));
+}
int
-nni_listener_setx(
+nng_dialer_get_bool(nng_dialer id, const char *n, bool *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_dialer_get_size(nng_dialer id, const char *n, size_t *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_dialer_get_uint64(nng_dialer id, const char *n, uint64_t *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_dialer_get_string(nng_dialer id, const char *n, char **v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_dialer_get_ptr(nng_dialer id, const char *n, void **v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_dialer_get_ms(nng_dialer id, const char *n, nng_duration *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_dialer_get_addr(nng_dialer id, const char *n, nng_sockaddr *v)
+{
+ return (dialer_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
+}
+
+static int
+listener_set(
nng_listener lid, const char *name, const void *v, size_t sz, nni_type t)
{
nni_listener *l;
@@ -560,7 +764,62 @@ nni_listener_setx(
}
int
-nni_listener_getx(
+nng_listener_set(nng_listener id, const char *n, const void *v, size_t sz)
+{
+ return (listener_set(id, n, v, sz, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_listener_set_int(nng_listener id, const char *n, int v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
+
+int
+nng_listener_set_bool(nng_listener id, const char *n, bool v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_BOOL));
+}
+
+int
+nng_listener_set_size(nng_listener id, const char *n, size_t v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_SIZE));
+}
+
+int
+nng_listener_set_uint64(nng_listener id, const char *n, uint64_t v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_UINT64));
+}
+
+int
+nng_listener_set_ms(nng_listener id, const char *n, nng_duration v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
+}
+
+int
+nng_listener_set_ptr(nng_listener id, const char *n, void *v)
+{
+ return (listener_set(id, n, &v, sizeof(v), NNI_TYPE_POINTER));
+}
+
+int
+nng_listener_set_string(nng_listener id, const char *n, const char *v)
+{
+ return (listener_set(
+ id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
+}
+
+int
+nng_listener_set_addr(nng_listener id, const char *n, const nng_sockaddr *v)
+{
+ return (listener_set(id, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
+
+static int
+listener_get(
nng_listener lid, const char *name, void *v, size_t *szp, nni_type t)
{
nni_listener *l;
@@ -577,8 +836,59 @@ nni_listener_getx(
return (rv);
}
-NNI_LEGACY_DEFGETALL(listener)
-NNI_LEGACY_DEFSETALL(listener)
+int
+nng_listener_get(nng_listener id, const char *n, void *v, size_t *szp)
+{
+ return (listener_get(id, n, v, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_listener_get_int(nng_listener id, const char *n, int *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_listener_get_bool(nng_listener id, const char *n, bool *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_listener_get_size(nng_listener id, const char *n, size_t *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_listener_get_uint64(nng_listener id, const char *n, uint64_t *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_listener_get_string(nng_listener id, const char *n, char **v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_listener_get_ptr(nng_listener id, const char *n, void **v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_listener_get_ms(nng_listener id, const char *n, nng_duration *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_listener_get_addr(nng_listener id, const char *n, nng_sockaddr *v)
+{
+ return (listener_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
+}
int
nng_dialer_close(nng_dialer did)
@@ -607,7 +917,7 @@ nng_listener_close(nng_listener lid)
}
static int
-nni_socket_setx(
+socket_set(
nng_socket s, const char *name, const void *val, size_t sz, nni_type t)
{
nni_sock *sock;
@@ -625,118 +935,129 @@ nni_socket_setx(
}
int
-nng_setopt(nng_socket s, const char *name, const void *val, size_t sz)
+nng_socket_set(nng_socket id, const char *n, const void *v, size_t sz)
{
- return (nng_socket_set(s, name, val, sz));
+ return (socket_set(id, n, v, sz, NNI_TYPE_OPAQUE));
}
-static int
-nni_socket_getx(
- nng_socket s, const char *name, void *val, size_t *szp, nni_type t)
+int
+nng_socket_set_int(nng_socket id, const char *n, int v)
{
- nni_sock *sock;
- int rv;
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_INT32));
+}
- if ((rv = nni_init()) != 0) {
- return (rv);
- }
- if ((rv = nni_sock_find(&sock, s.id)) != 0) {
- return (rv);
- }
- rv = nni_sock_getopt(sock, name, val, szp, t);
- nni_sock_rele(sock);
- return (rv);
+int
+nng_socket_set_bool(nng_socket id, const char *n, bool v)
+{
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_BOOL));
}
int
-nng_getopt(nng_socket s, const char *name, void *val, size_t *szp)
+nng_socket_set_size(nng_socket id, const char *n, size_t v)
{
- return (nng_socket_get(s, name, val, szp));
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_SIZE));
}
-// Convenience option wrappers.
int
-nng_setopt_int(nng_socket s, const char *name, int val)
+nng_socket_set_uint64(nng_socket id, const char *n, uint64_t v)
{
- return (nng_socket_set_int(s, name, val));
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_UINT64));
}
int
-nng_setopt_bool(nng_socket s, const char *name, bool val)
+nng_socket_set_ms(nng_socket id, const char *n, nng_duration v)
{
- return (nng_socket_set_bool(s, name, val));
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_DURATION));
}
int
-nng_setopt_size(nng_socket s, const char *name, size_t val)
+nng_socket_set_ptr(nng_socket id, const char *n, void *v)
{
- return (nng_socket_set_size(s, name, val));
+ return (socket_set(id, n, &v, sizeof(v), NNI_TYPE_POINTER));
}
int
-nng_setopt_ms(nng_socket s, const char *name, nng_duration val)
+nng_socket_set_string(nng_socket id, const char *n, const char *v)
{
- return (nng_socket_set_ms(s, name, val));
+ return (socket_set(
+ id, n, v, v == NULL ? 0 : strlen(v) + 1, NNI_TYPE_STRING));
}
int
-nng_setopt_uint64(nng_socket s, const char *name, uint64_t val)
+nng_socket_set_addr(nng_socket id, const char *n, const nng_sockaddr *v)
{
- return (nng_socket_set_uint64(s, name, val));
+ return (socket_set(id, n, v, sizeof(*v), NNI_TYPE_SOCKADDR));
+}
+
+static int
+socket_get(nng_socket s, const char *name, void *val, size_t *szp, nni_type t)
+{
+ nni_sock *sock;
+ int rv;
+
+ if ((rv = nni_init()) != 0) {
+ return (rv);
+ }
+ if ((rv = nni_sock_find(&sock, s.id)) != 0) {
+ return (rv);
+ }
+ rv = nni_sock_getopt(sock, name, val, szp, t);
+ nni_sock_rele(sock);
+ return (rv);
}
int
-nng_setopt_ptr(nng_socket s, const char *name, void *val)
+nng_socket_get(nng_socket id, const char *n, void *v, size_t *szp)
{
- return (nng_socket_set_ptr(s, name, val));
+ return (socket_get(id, n, v, szp, NNI_TYPE_OPAQUE));
}
int
-nng_setopt_string(nng_socket s, const char *name, const char *val)
+nng_socket_get_int(nng_socket id, const char *n, int *v)
{
- return (nng_socket_set_string(s, name, val));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_INT32));
}
int
-nng_getopt_bool(nng_socket s, const char *name, bool *valp)
+nng_socket_get_bool(nng_socket id, const char *n, bool *v)
{
- return (nng_socket_get_bool(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_BOOL));
}
int
-nng_getopt_int(nng_socket s, const char *name, int *valp)
+nng_socket_get_size(nng_socket id, const char *n, size_t *v)
{
- return (nng_socket_get_int(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_SIZE));
}
int
-nng_getopt_size(nng_socket s, const char *name, size_t *valp)
+nng_socket_get_uint64(nng_socket id, const char *n, uint64_t *v)
{
- return (nng_socket_get_size(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_UINT64));
}
int
-nng_getopt_uint64(nng_socket s, const char *name, uint64_t *valp)
+nng_socket_get_string(nng_socket id, const char *n, char **v)
{
- return (nng_socket_get_uint64(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_STRING));
}
int
-nng_getopt_ms(nng_socket s, const char *name, nng_duration *valp)
+nng_socket_get_ptr(nng_socket id, const char *n, void **v)
{
- return (nng_socket_get_ms(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_POINTER));
}
int
-nng_getopt_ptr(nng_socket s, const char *name, void **valp)
+nng_socket_get_ms(nng_socket id, const char *n, nng_duration *v)
{
- return (nng_socket_get_ptr(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_DURATION));
}
int
-nng_getopt_string(nng_socket s, const char *name, char **valp)
+nng_socket_get_addr(nng_socket id, const char *n, nng_sockaddr *v)
{
- return (nng_socket_get_string(s, name, valp));
+ return (socket_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
}
int
@@ -856,7 +1177,7 @@ nng_strerror(int num)
}
static int
-nni_pipe_getx(nng_pipe p, const char *name, void *val, size_t *szp, nni_type t)
+pipe_get(nng_pipe p, const char *name, void *val, size_t *szp, nni_type t)
{
int rv;
nni_pipe *pipe;
@@ -872,7 +1193,59 @@ nni_pipe_getx(nng_pipe p, const char *name, void *val, size_t *szp, nni_type t)
return (rv);
}
-NNI_LEGACY_DEFGETALL(pipe)
+int
+nng_pipe_get(nng_pipe id, const char *n, void *v, size_t *szp)
+{
+ return (pipe_get(id, n, v, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_pipe_get_int(nng_pipe id, const char *n, int *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_INT32));
+}
+
+int
+nng_pipe_get_bool(nng_pipe id, const char *n, bool *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_BOOL));
+}
+
+int
+nng_pipe_get_size(nng_pipe id, const char *n, size_t *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_SIZE));
+}
+
+int
+nng_pipe_get_uint64(nng_pipe id, const char *n, uint64_t *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_UINT64));
+}
+
+int
+nng_pipe_get_string(nng_pipe id, const char *n, char **v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_STRING));
+}
+
+int
+nng_pipe_get_ptr(nng_pipe id, const char *n, void **v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_POINTER));
+}
+
+int
+nng_pipe_get_ms(nng_pipe id, const char *n, nng_duration *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_DURATION));
+}
+
+int
+nng_pipe_get_addr(nng_pipe id, const char *n, nng_sockaddr *v)
+{
+ return (pipe_get(id, n, v, NULL, NNI_TYPE_SOCKADDR));
+}
nng_socket
nng_pipe_socket(nng_pipe p)
@@ -931,16 +1304,6 @@ nng_pipe_id(nng_pipe p)
return (((int) p.id > 0) ? (int) p.id : -1);
}
-NNI_DEFSETALL(ctx)
-NNI_DEFGETALL(ctx)
-NNI_DEFSETALL(dialer)
-NNI_DEFGETALL(dialer)
-NNI_DEFSETALL(listener)
-NNI_DEFGETALL(listener)
-NNI_DEFSETALL(socket)
-NNI_DEFGETALL(socket)
-NNI_DEFGETALL(pipe)
-
// Message handling.
int
nng_msg_alloc(nng_msg **msgp, size_t size)
@@ -1349,19 +1712,6 @@ nng_msg_set_pipe(nng_msg *msg, nng_pipe p)
nni_msg_set_pipe(msg, p.id);
}
-// This function is not supported, but we keep it around to
-// satisfy link dependencies in old programs. It has never done
-// anything useful.
-int
-nng_msg_getopt(nng_msg *msg, int opt, void *ptr, size_t *szp)
-{
- NNI_ARG_UNUSED(msg);
- NNI_ARG_UNUSED(opt);
- NNI_ARG_UNUSED(ptr);
- NNI_ARG_UNUSED(szp);
- return (NNG_ENOTSUP);
-}
-
int
nng_aio_alloc(nng_aio **app, void (*cb)(void *), void *arg)
{
@@ -1447,20 +1797,6 @@ nng_aio_set_timeout(nng_aio *aio, nni_duration when)
int
nng_aio_set_iov(nng_aio *aio, unsigned niov, const nng_iov *iov)
{
-// We limit the niov to prevent user insanity. This is required
-// to avoid stack allocations that might smash the stack. The
-// assumption is that we can always put at least 1kB on the stack --
-// our nng_iov structures are 16B. Systems without stack allocation
-// get a smaller limit, because we use an automatic variable.
-#if defined(NNG_HAVE_ALLOCA) || defined(_WIN32)
- if (niov > 64) {
- return (NNG_EINVAL);
- }
-#else
- if (niov > 16) {
- return (NNG_EINVAL);
- }
-#endif
return (nni_aio_set_iov(aio, niov, iov));
}
diff --git a/src/nng_legacy.c b/src/nng_legacy.c
new file mode 100644
index 00000000..c38d0a23
--- /dev/null
+++ b/src/nng_legacy.c
@@ -0,0 +1,454 @@
+//
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+//
+// This software is supplied under the terms of the MIT License, a
+// copy of which should be located in the distribution where this
+// file was obtained (LICENSE.txt). A copy of the license may also be
+// found online at https://opensource.org/licenses/MIT.
+//
+
+#ifndef NNG_ELIDE_DEPRECATED
+#include "core/nng_impl.h"
+
+// These are legacy APIs that we would prefer nobody used.
+// Eventually they will likely be removed. For now we have
+// to continue to provide them for compatibility.
+
+// This function is not supported, but we keep it around to
+// satisfy link dependencies in old programs. It has never done
+// anything useful.
+int
+nng_msg_getopt(nng_msg *msg, int opt, void *ptr, size_t *szp)
+{
+ NNI_ARG_UNUSED(msg);
+ NNI_ARG_UNUSED(opt);
+ NNI_ARG_UNUSED(ptr);
+ NNI_ARG_UNUSED(szp);
+ return (NNG_ENOTSUP);
+}
+
+int
+nng_getopt(nng_socket id, const char *n, void *v, size_t *sz)
+{
+ return (nng_socket_get(id, n, v, sz));
+}
+
+int
+nng_getopt_int(nng_socket id, const char *n, int *v)
+{
+ return (nng_socket_get_int(id, n, v));
+}
+
+int
+nng_getopt_uint64(nng_socket id, const char *n, uint64_t *v)
+{
+ return (nng_socket_get_uint64(id, n, v));
+}
+
+int
+nng_getopt_bool(nng_socket id, const char *n, bool *v)
+{
+ return (nng_socket_get_bool(id, n, v));
+}
+
+int
+nng_getopt_size(nng_socket id, const char *n, size_t *v)
+{
+ return (nng_socket_get_size(id, n, v));
+}
+
+int
+nng_getopt_ms(nng_socket id, const char *n, nng_duration *v)
+{
+ return (nng_socket_get_ms(id, n, v));
+}
+
+int
+nng_getopt_string(nng_socket id, const char *n, char **v)
+{
+ return (nng_socket_get_string(id, n, v));
+}
+
+int
+nng_setopt(nng_socket id, const char *name, const void *v, size_t sz)
+{
+ return (nng_socket_set(id, name, v, sz));
+}
+
+int
+nng_setopt_bool(nng_socket id, const char *n, bool v)
+{
+ return (nng_socket_set_bool(id, n, v));
+}
+
+int
+nng_setopt_int(nng_socket id, const char *n, int v)
+{
+ return (nng_socket_set_int(id, n, v));
+}
+
+int
+nng_setopt_ms(nng_socket id, const char *n, nng_duration v)
+{
+ return (nng_socket_set_ms(id, n, v));
+}
+
+int
+nng_setopt_size(nng_socket id, const char *n, size_t v)
+{
+ return (nng_socket_set_size(id, n, v));
+}
+
+int
+nng_setopt_uint64(nng_socket id, const char *n, uint64_t v)
+{
+ return (nng_socket_set_uint64(id, n, v));
+}
+
+int
+nng_setopt_string(nng_socket id, const char *n, const char *v)
+{
+ return (nng_socket_set_string(id, n, v));
+}
+
+int
+nng_setopt_ptr(nng_socket id, const char *n, void *v)
+{
+ return (nng_socket_set_ptr(id, n, v));
+}
+
+// Contexts.
+
+int
+nng_ctx_getopt(nng_ctx id, const char *n, void *v, size_t *sz)
+{
+ return (nng_ctx_get(id, n, v, sz));
+}
+
+int
+nng_ctx_getopt_int(nng_ctx id, const char *n, int *v)
+{
+ return (nng_ctx_get_int(id, n, v));
+}
+
+int
+nng_ctx_getopt_bool(nng_ctx id, const char *n, bool *v)
+{
+ return (nng_ctx_get_bool(id, n, v));
+}
+
+int
+nng_ctx_getopt_size(nng_ctx id, const char *n, size_t *v)
+{
+ return (nng_ctx_get_size(id, n, v));
+}
+
+int
+nng_ctx_getopt_ms(nng_ctx id, const char *n, nng_duration *v)
+{
+ return (nng_ctx_get_ms(id, n, v));
+}
+
+int
+nng_ctx_setopt(nng_ctx id, const char *name, const void *v, size_t sz)
+{
+ return (nng_ctx_set(id, name, v, sz));
+}
+
+int
+nng_ctx_setopt_bool(nng_ctx id, const char *n, bool v)
+{
+ return (nng_ctx_set_bool(id, n, v));
+}
+
+int
+nng_ctx_setopt_int(nng_ctx id, const char *n, int v)
+{
+ return (nng_ctx_set_int(id, n, v));
+}
+
+int
+nng_ctx_setopt_ms(nng_ctx id, const char *n, nng_duration v)
+{
+ return (nng_ctx_set_ms(id, n, v));
+}
+
+int
+nng_ctx_setopt_size(nng_ctx id, const char *n, size_t v)
+{
+ return (nng_ctx_set_size(id, n, v));
+}
+
+// Dialers.
+
+int
+nng_dialer_getopt(nng_dialer id, const char *n, void *v, size_t *sz)
+{
+ return (nng_dialer_get(id, n, v, sz));
+}
+
+int
+nng_dialer_getopt_int(nng_dialer id, const char *n, int *v)
+{
+ return (nng_dialer_get_int(id, n, v));
+}
+
+int
+nng_dialer_getopt_bool(nng_dialer id, const char *n, bool *v)
+{
+ return (nng_dialer_get_bool(id, n, v));
+}
+
+int
+nng_dialer_getopt_size(nng_dialer id, const char *n, size_t *v)
+{
+ return (nng_dialer_get_size(id, n, v));
+}
+
+int
+nng_dialer_getopt_uint64(nng_dialer id, const char *n, uint64_t *v)
+{
+ return (nng_dialer_get_uint64(id, n, v));
+}
+
+int
+nng_dialer_getopt_string(nng_dialer id, const char *n, char **v)
+{
+ return (nng_dialer_get_string(id, n, v));
+}
+
+int
+nng_dialer_getopt_ptr(nng_dialer id, const char *n, void **v)
+{
+ return (nng_dialer_get_ptr(id, n, v));
+}
+
+int
+nng_dialer_getopt_ms(nng_dialer id, const char *n, nng_duration *v)
+{
+ return (nng_dialer_get_ms(id, n, v));
+}
+
+int
+nng_dialer_getopt_sockaddr(nng_dialer id, const char *n, nng_sockaddr *v)
+{
+ return (nng_dialer_get_addr(id, n, v));
+}
+
+int
+nng_dialer_setopt(
+ nng_dialer id, const char *name, const void *v, size_t sz)
+{
+ return (nng_dialer_set(id, name, v, sz));
+}
+
+int
+nng_dialer_setopt_bool(nng_dialer id, const char *n, bool v)
+{
+ return (nng_dialer_set_bool(id, n, v));
+}
+
+int
+nng_dialer_setopt_int(nng_dialer id, const char *n, int v)
+{
+ return (nng_dialer_set_int(id, n, v));
+}
+
+int
+nng_dialer_setopt_ms(nng_dialer id, const char *n, nng_duration v)
+{
+ return (nng_dialer_set_ms(id, n, v));
+}
+
+int
+nng_dialer_setopt_size(nng_dialer id, const char *n, size_t v)
+{
+ return (nng_dialer_set_size(id, n, v));
+}
+
+int
+nng_dialer_setopt_uint64(nng_dialer id, const char *n, uint64_t v)
+{
+ return (nng_dialer_set_uint64(id, n, v));
+}
+
+int
+nng_dialer_setopt_ptr(nng_dialer id, const char *n, void *v)
+{
+ return (nng_dialer_set_ptr(id, n, v));
+}
+
+int
+nng_dialer_setopt_string(nng_dialer id, const char *n, const char *v)
+{
+ return (nng_dialer_set_string(id, n, v));
+}
+
+// Listeners.
+
+int
+nng_listener_getopt(nng_listener id, const char *n, void *v, size_t *sz)
+{
+ return (nng_listener_get(id, n, v, sz));
+}
+
+int
+nng_listener_getopt_int(nng_listener id, const char *n, int *v)
+{
+ return (nng_listener_get_int(id, n, v));
+}
+
+int
+nng_listener_getopt_bool(nng_listener id, const char *n, bool *v)
+{
+ return (nng_listener_get_bool(id, n, v));
+}
+
+int
+nng_listener_getopt_size(nng_listener id, const char *n, size_t *v)
+{
+ return (nng_listener_get_size(id, n, v));
+}
+
+int
+nng_listener_getopt_uint64(nng_listener id, const char *n, uint64_t *v)
+{
+ return (nng_listener_get_uint64(id, n, v));
+}
+
+int
+nng_listener_getopt_string(nng_listener id, const char *n, char **v)
+{
+ return (nng_listener_get_string(id, n, v));
+}
+
+int
+nng_listener_getopt_ptr(nng_listener id, const char *n, void **v)
+{
+ return (nng_listener_get_ptr(id, n, v));
+}
+
+int
+nng_listener_getopt_ms(nng_listener id, const char *n, nng_duration *v)
+{
+ return (nng_listener_get_ms(id, n, v));
+}
+
+int
+nng_listener_getopt_sockaddr(nng_listener id, const char *n, nng_sockaddr *v)
+{
+ return (nng_listener_get_addr(id, n, v));
+}
+
+int
+nng_listener_setopt(
+ nng_listener id, const char *name, const void *v, size_t sz)
+{
+ return (nng_listener_set(id, name, v, sz));
+}
+
+int
+nng_listener_setopt_bool(nng_listener id, const char *n, bool v)
+{
+ return (nng_listener_set_bool(id, n, v));
+}
+
+int
+nng_listener_setopt_int(nng_listener id, const char *n, int v)
+{
+ return (nng_listener_set_int(id, n, v));
+}
+
+int
+nng_listener_setopt_ms(nng_listener id, const char *n, nng_duration v)
+{
+ return (nng_listener_set_ms(id, n, v));
+}
+
+int
+nng_listener_setopt_size(nng_listener id, const char *n, size_t v)
+{
+ return (nng_listener_set_size(id, n, v));
+}
+
+int
+nng_listener_setopt_uint64(nng_listener id, const char *n, uint64_t v)
+{
+ return (nng_listener_set_uint64(id, n, v));
+}
+
+int
+nng_listener_setopt_ptr(nng_listener id, const char *n, void *v)
+{
+ return (nng_listener_set_ptr(id, n, v));
+}
+
+int
+nng_listener_setopt_string(nng_listener id, const char *n, const char *v)
+{
+ return (nng_listener_set_string(id, n, v));
+}
+
+// Pipes
+
+int
+nng_pipe_getopt(nng_pipe id, const char *n, void *v, size_t *sz)
+{
+ return (nng_pipe_get(id, n, v, sz));
+}
+
+int
+nng_pipe_getopt_int(nng_pipe id, const char *n, int *v)
+{
+ return (nng_pipe_get_int(id, n, v));
+}
+
+int
+nng_pipe_getopt_bool(nng_pipe id, const char *n, bool *v)
+{
+ return (nng_pipe_get_bool(id, n, v));
+}
+
+int
+nng_pipe_getopt_size(nng_pipe id, const char *n, size_t *v)
+{
+ return (nng_pipe_get_size(id, n, v));
+}
+
+int
+nng_pipe_getopt_uint64(nng_pipe id, const char *n, uint64_t *v)
+{
+ return (nng_pipe_get_uint64(id, n, v));
+}
+
+int
+nng_pipe_getopt_string(nng_pipe id, const char *n, char **v)
+{
+ return (nng_pipe_get_string(id, n, v));
+}
+
+int
+nng_pipe_getopt_ptr(nng_pipe id, const char *n, void **v)
+{
+ return (nng_pipe_get_ptr(id, n, v));
+}
+
+int
+nng_pipe_getopt_ms(nng_pipe id, const char *n, nng_duration *v)
+{
+ return (nng_pipe_get_ms(id, n, v));
+}
+
+int
+nng_pipe_getopt_sockaddr(nng_pipe id, const char *n, nng_sockaddr *v)
+{
+ return (nng_pipe_get_addr(id, n, v));
+}
+
+void
+nng_closeall(void)
+{
+ nni_sock_closeall();
+}
+
+#endif // NNG_ELIDE_DEPRECATED \ No newline at end of file
diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c
index e77d54a4..825ecd4b 100644
--- a/src/platform/posix/posix_ipcconn.c
+++ b/src/platform/posix/posix_ipcconn.c
@@ -531,14 +531,14 @@ static const nni_option ipc_options[] = {
};
static int
-ipc_getx(void *arg, const char *name, void *val, size_t *szp, nni_type t)
+ipc_get(void *arg, const char *name, void *val, size_t *szp, nni_type t)
{
ipc_conn *c = arg;
return (nni_getopt(ipc_options, name, c, val, szp, t));
}
static int
-ipc_setx(void *arg, const char *name, const void *val, size_t sz, nni_type t)
+ipc_set(void *arg, const char *name, const void *val, size_t sz, nni_type t)
{
ipc_conn *c = arg;
return (nni_setopt(ipc_options, name, c, val, sz, t));
@@ -559,8 +559,8 @@ nni_posix_ipc_alloc(nni_ipc_conn **cp, nni_sockaddr *sa, nni_ipc_dialer *d)
c->stream.s_close = ipc_close;
c->stream.s_send = ipc_send;
c->stream.s_recv = ipc_recv;
- c->stream.s_getx = ipc_getx;
- c->stream.s_setx = ipc_setx;
+ c->stream.s_get = ipc_get;
+ c->stream.s_set = ipc_set;
c->sa = *sa;
nni_mtx_init(&c->mtx);
diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c
index b25f7340..69ed4f77 100644
--- a/src/platform/posix/posix_ipcdial.c
+++ b/src/platform/posix/posix_ipcdial.c
@@ -244,15 +244,15 @@ static const nni_option ipc_dialer_options[] = {
},
};
-int
-ipc_dialer_getx(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
+static int
+ipc_dialer_get(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
{
ipc_dialer *d = arg;
return (nni_getopt(ipc_dialer_options, nm, d, buf, szp, t));
}
-int
-ipc_dialer_setx(
+static int
+ipc_dialer_set(
void *arg, const char *nm, const void *buf, size_t sz, nni_type t)
{
ipc_dialer *d = arg;
@@ -306,8 +306,8 @@ nni_ipc_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
d->sd.sd_free = ipc_dialer_free;
d->sd.sd_close = ipc_dialer_close;
d->sd.sd_dial = ipc_dialer_dial;
- d->sd.sd_getx = ipc_dialer_getx;
- d->sd.sd_setx = ipc_dialer_setx;
+ d->sd.sd_get = ipc_dialer_get;
+ d->sd.sd_set = ipc_dialer_set;
nni_atomic_init_bool(&d->fini);
nni_atomic_init64(&d->ref);
nni_atomic_inc64(&d->ref);
diff --git a/src/platform/posix/posix_ipclisten.c b/src/platform/posix/posix_ipclisten.c
index 9c0b55db..f2511487 100644
--- a/src/platform/posix/posix_ipclisten.c
+++ b/src/platform/posix/posix_ipclisten.c
@@ -269,7 +269,7 @@ static const nni_option ipc_listener_options[] = {
};
static int
-ipc_listener_getx(
+ipc_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ipc_listener *l = arg;
@@ -277,7 +277,7 @@ ipc_listener_getx(
}
static int
-ipc_listener_setx(
+ipc_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
ipc_listener *l = arg;
@@ -527,40 +527,9 @@ nni_ipc_listener_alloc(nng_stream_listener **lp, const nng_url *url)
l->sl.sl_close = ipc_listener_close;
l->sl.sl_listen = ipc_listener_listen;
l->sl.sl_accept = ipc_listener_accept;
- l->sl.sl_getx = ipc_listener_getx;
- l->sl.sl_setx = ipc_listener_setx;
+ l->sl.sl_get = ipc_listener_get;
+ l->sl.sl_set = ipc_listener_set;
*lp = (void *) l;
return (0);
}
-
-static int
-ipc_check_perms(const void *buf, size_t sz, nni_type t)
-{
- int32_t mode;
- int rv;
-
- if ((rv = nni_copyin_int(&mode, buf, sz, 0, S_IFMT, t)) != 0) {
- return (rv);
- }
- if ((mode & S_IFMT) != 0) {
- return (NNG_EINVAL);
- }
- return (0);
-}
-
-static const nni_chkoption ipc_chkopts[] = {
- {
- .o_name = NNG_OPT_IPC_PERMISSIONS,
- .o_check = ipc_check_perms,
- },
- {
- .o_name = NULL,
- },
-};
-
-int
-nni_ipc_checkopt(const char *name, const void *data, size_t sz, nni_type t)
-{
- return (nni_chkopt(ipc_chkopts, name, data, sz, t));
-}
diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c
index 3c8c3715..9684fe27 100644
--- a/src/platform/posix/posix_tcpconn.c
+++ b/src/platform/posix/posix_tcpconn.c
@@ -463,14 +463,14 @@ static const nni_option tcp_options[] = {
};
static int
-tcp_getx(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+tcp_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
nni_tcp_conn *c = arg;
return (nni_getopt(tcp_options, name, c, buf, szp, t));
}
static int
-tcp_setx(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
+tcp_set(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
nni_tcp_conn *c = arg;
return (nni_setopt(tcp_options, name, c, buf, sz, t));
@@ -495,8 +495,8 @@ nni_posix_tcp_alloc(nni_tcp_conn **cp, nni_tcp_dialer *d)
c->stream.s_close = tcp_close;
c->stream.s_recv = tcp_recv;
c->stream.s_send = tcp_send;
- c->stream.s_getx = tcp_getx;
- c->stream.s_setx = tcp_setx;
+ c->stream.s_get = tcp_get;
+ c->stream.s_set = tcp_set;
*cp = c;
return (0);
diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c
index 767717af..f7568db3 100644
--- a/src/platform/posix/posix_tcpdial.c
+++ b/src/platform/posix/posix_tcpdial.c
@@ -398,14 +398,14 @@ static const nni_option tcp_dialer_options[] = {
};
int
-nni_tcp_dialer_getopt(
+nni_tcp_dialer_get(
nni_tcp_dialer *d, const char *name, void *buf, size_t *szp, nni_type t)
{
return (nni_getopt(tcp_dialer_options, name, d, buf, szp, t));
}
int
-nni_tcp_dialer_setopt(nni_tcp_dialer *d, const char *name, const void *buf,
+nni_tcp_dialer_set(nni_tcp_dialer *d, const char *name, const void *buf,
size_t sz, nni_type t)
{
return (nni_setopt(tcp_dialer_options, name, d, buf, sz, t));
diff --git a/src/platform/posix/posix_tcplisten.c b/src/platform/posix/posix_tcplisten.c
index 3a2ea62b..e1c0b90c 100644
--- a/src/platform/posix/posix_tcplisten.c
+++ b/src/platform/posix/posix_tcplisten.c
@@ -416,14 +416,14 @@ static const nni_option tcp_listener_options[] = {
};
int
-nni_tcp_listener_getopt(
+nni_tcp_listener_get(
nni_tcp_listener *l, const char *name, void *buf, size_t *szp, nni_type t)
{
return (nni_getopt(tcp_listener_options, name, l, buf, szp, t));
}
int
-nni_tcp_listener_setopt(nni_tcp_listener *l, const char *name, const void *buf,
+nni_tcp_listener_set(nni_tcp_listener *l, const char *name, const void *buf,
size_t sz, nni_type t)
{
return (nni_setopt(tcp_listener_options, name, l, buf, sz, t));
diff --git a/src/platform/windows/win_ipcconn.c b/src/platform/windows/win_ipcconn.c
index aacd3601..b8dc62d3 100644
--- a/src/platform/windows/win_ipcconn.c
+++ b/src/platform/windows/win_ipcconn.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -381,14 +381,14 @@ static const nni_option ipc_conn_options[] = {
};
static int
-ipc_setx(void *arg, const char *nm, const void *val, size_t sz, nni_opt_type t)
+ipc_set(void *arg, const char *nm, const void *val, size_t sz, nni_opt_type t)
{
ipc_conn *c = arg;
return (nni_setopt(ipc_conn_options, nm, c, val, sz, t));
}
static int
-ipc_getx(void *arg, const char *nm, void *val, size_t *szp, nni_opt_type t)
+ipc_get(void *arg, const char *nm, void *val, size_t *szp, nni_opt_type t)
{
ipc_conn *c = arg;
return (nni_getopt(ipc_conn_options, nm, c, val, szp, t));
@@ -415,8 +415,8 @@ nni_win_ipc_init(
c->stream.s_close = ipc_close;
c->stream.s_send = ipc_send;
c->stream.s_recv = ipc_recv;
- c->stream.s_getx = ipc_getx;
- c->stream.s_setx = ipc_setx;
+ c->stream.s_get = ipc_get;
+ c->stream.s_set = ipc_set;
if (((rv = nni_win_io_init(&c->recv_io, ipc_recv_cb, c)) != 0) ||
((rv = nni_win_io_init(&c->send_io, ipc_send_cb, c)) != 0)) {
diff --git a/src/platform/windows/win_ipcdial.c b/src/platform/windows/win_ipcdial.c
index c210b7be..16052749 100644
--- a/src/platform/windows/win_ipcdial.c
+++ b/src/platform/windows/win_ipcdial.c
@@ -38,7 +38,7 @@ typedef struct ipc_dial_work {
int exit;
} ipc_dial_work;
-static ipc_dial_work ipc_connecter;
+static ipc_dial_work ipc_connector;
static void
ipc_dial_thr(void *arg)
@@ -125,7 +125,7 @@ static void
ipc_dial_cancel(nni_aio *aio, void *arg, int rv)
{
ipc_dialer * d = arg;
- ipc_dial_work *w = &ipc_connecter;
+ ipc_dial_work *w = &ipc_connector;
nni_mtx_lock(&w->mtx);
if (nni_aio_list_active(aio)) {
@@ -140,9 +140,10 @@ ipc_dial_cancel(nni_aio *aio, void *arg, int rv)
}
static void
-ipc_dialer_dial(ipc_dialer *d, nni_aio *aio)
+ipc_dialer_dial(void *arg, nni_aio *aio)
{
- ipc_dial_work *w = &ipc_connecter;
+ ipc_dialer * d = arg;
+ ipc_dial_work *w = &ipc_connector;
int rv;
if (nni_aio_begin(aio) != 0) {
@@ -174,7 +175,7 @@ static void
ipc_dialer_close(void *arg)
{
ipc_dialer * d = arg;
- ipc_dial_work *w = &ipc_connecter;
+ ipc_dial_work *w = &ipc_connector;
nni_aio * aio;
nni_mtx_lock(&w->mtx);
@@ -206,16 +207,16 @@ static const nni_option ipc_dialer_options[] = {
},
};
-int
-ipc_dialer_setx(
+static int
+ipc_dialer_set(
void *arg, const char *nm, const void *buf, size_t sz, nni_type t)
{
ipc_dialer *d = arg;
return (nni_setopt(ipc_dialer_options, nm, d, buf, sz, t));
}
-int
-ipc_dialer_getx(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
+static int
+ipc_dialer_get(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
{
ipc_dialer *d = arg;
return (nni_getopt(ipc_dialer_options, nm, d, buf, szp, t));
@@ -228,7 +229,7 @@ nni_ipc_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
int rv;
if ((strcmp(url->u_scheme, "ipc") != 0) || (url->u_path == NULL) ||
- (strlen(url->u_path) == 0)||
+ (strlen(url->u_path) == 0) ||
(strlen(url->u_path) >= NNG_MAXADDRLEN)) {
return (NNG_EADDRINVAL);
}
@@ -247,8 +248,8 @@ nni_ipc_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
d->sd.sd_free = ipc_dialer_free;
d->sd.sd_close = ipc_dialer_close;
d->sd.sd_dial = ipc_dialer_dial;
- d->sd.sd_getx = ipc_dialer_getx;
- d->sd.sd_setx = ipc_dialer_setx;
+ d->sd.sd_get = ipc_dialer_get;
+ d->sd.sd_set = ipc_dialer_set;
nni_aio_list_init(&d->aios);
*dp = (void *) d;
return (0);
@@ -258,7 +259,7 @@ int
nni_win_ipc_sysinit(void)
{
int rv;
- ipc_dial_work *worker = &ipc_connecter;
+ ipc_dial_work *worker = &ipc_connector;
NNI_LIST_INIT(&worker->workers, ipc_dialer, node);
NNI_LIST_INIT(&worker->waiters, ipc_dialer, node);
@@ -270,7 +271,7 @@ nni_win_ipc_sysinit(void)
if (rv != 0) {
return (rv);
}
- nni_thr_set_name(&worker->thr, "nng:ipc:dial");
+ nni_thr_set_name(&worker->thr, "nng:ipc:dial");
nni_thr_run(&worker->thr);
return (0);
@@ -279,7 +280,7 @@ nni_win_ipc_sysinit(void)
void
nni_win_ipc_sysfini(void)
{
- ipc_dial_work *worker = &ipc_connecter;
+ ipc_dial_work *worker = &ipc_connector;
nni_reap_drain(); // so that listeners get cleaned up.
diff --git a/src/platform/windows/win_ipclisten.c b/src/platform/windows/win_ipclisten.c
index 65a7a8d7..c5f31b22 100644
--- a/src/platform/windows/win_ipclisten.c
+++ b/src/platform/windows/win_ipclisten.c
@@ -178,16 +178,16 @@ static const nni_option ipc_listener_options[] = {
},
};
-int
-ipc_listener_setx(
+static int
+ipc_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
ipc_listener *l = arg;
return (nni_setopt(ipc_listener_options, name, l, buf, sz, t));
}
-int
-ipc_listener_getx(
+static int
+ipc_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ipc_listener *l = arg;
@@ -349,8 +349,8 @@ nni_ipc_listener_alloc(nng_stream_listener **lp, const nng_url *url)
l->sl.sl_close = ipc_listener_close;
l->sl.sl_listen = ipc_listener_listen;
l->sl.sl_accept = ipc_listener_accept;
- l->sl.sl_getx = ipc_listener_getx;
- l->sl.sl_setx = ipc_listener_setx;
+ l->sl.sl_get = ipc_listener_get;
+ l->sl.sl_set = ipc_listener_set;
snprintf(l->sa.s_ipc.sa_path, NNG_MAXADDRLEN, "%s", url->u_path);
nni_aio_list_init(&l->aios);
nni_mtx_init(&l->mtx);
@@ -358,35 +358,3 @@ nni_ipc_listener_alloc(nng_stream_listener **lp, const nng_url *url)
*lp = (void *) l;
return (0);
}
-
-static int
-ipc_check_sec_desc(const void *buf, size_t sz, nni_type t)
-{
- void *desc;
- int rv;
-
- if ((rv = nni_copyin_ptr(&desc, buf, sz, t)) != 0) {
- return (rv);
- }
- if (!IsValidSecurityDescriptor((SECURITY_DESCRIPTOR *) desc)) {
- return (NNG_EINVAL);
- }
-
- return (0);
-}
-
-static const nni_chkoption ipc_chkopts[] = {
- {
- .o_name = NNG_OPT_IPC_SECURITY_DESCRIPTOR,
- .o_check = ipc_check_sec_desc,
- },
- {
- .o_name = NULL,
- },
-};
-
-int
-nni_ipc_checkopt(const char *name, const void *data, size_t sz, nni_type t)
-{
- return (nni_chkopt(ipc_chkopts, name, data, sz, t));
-}
diff --git a/src/platform/windows/win_tcpconn.c b/src/platform/windows/win_tcpconn.c
index 8016458b..f0e7c955 100644
--- a/src/platform/windows/win_tcpconn.c
+++ b/src/platform/windows/win_tcpconn.c
@@ -386,14 +386,14 @@ static const nni_option tcp_options[] = {
};
static int
-tcp_getx(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+tcp_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
nni_tcp_conn *c = arg;
return (nni_getopt(tcp_options, name, c, buf, szp, t));
}
static int
-tcp_setx(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
+tcp_set(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
nni_tcp_conn *c = arg;
return (nni_setopt(tcp_options, name, c, buf, sz, t));
@@ -448,8 +448,8 @@ nni_win_tcp_init(nni_tcp_conn **connp, SOCKET s)
c->ops.s_free = tcp_free;
c->ops.s_send = tcp_send;
c->ops.s_recv = tcp_recv;
- c->ops.s_getx = tcp_getx;
- c->ops.s_setx = tcp_setx;
+ c->ops.s_get = tcp_get;
+ c->ops.s_set = tcp_set;
if (((rv = nni_win_io_init(&c->recv_io, tcp_recv_cb, c)) != 0) ||
((rv = nni_win_io_init(&c->send_io, tcp_send_cb, c)) != 0) ||
diff --git a/src/platform/windows/win_tcpdial.c b/src/platform/windows/win_tcpdial.c
index 89c5bf6a..12ebdca6 100644
--- a/src/platform/windows/win_tcpdial.c
+++ b/src/platform/windows/win_tcpdial.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -397,14 +397,14 @@ static const nni_option tcp_dialer_options[] = {
};
int
-nni_tcp_dialer_getopt(
+nni_tcp_dialer_get(
nni_tcp_dialer *d, const char *name, void *buf, size_t *szp, nni_type t)
{
return (nni_getopt(tcp_dialer_options, name, d, buf, szp, t));
}
int
-nni_tcp_dialer_setopt(nni_tcp_dialer *d, const char *name, const void *buf,
+nni_tcp_dialer_set(nni_tcp_dialer *d, const char *name, const void *buf,
size_t sz, nni_type t)
{
return (nni_setopt(tcp_dialer_options, name, d, buf, sz, t));
diff --git a/src/platform/windows/win_tcplisten.c b/src/platform/windows/win_tcplisten.c
index 18e552a6..9c5fec3c 100644
--- a/src/platform/windows/win_tcplisten.c
+++ b/src/platform/windows/win_tcplisten.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -431,14 +431,14 @@ static const nni_option tcp_listener_options[] = {
};
int
-nni_tcp_listener_getopt(
+nni_tcp_listener_get(
nni_tcp_listener *l, const char *name, void *buf, size_t *szp, nni_type t)
{
return (nni_getopt(tcp_listener_options, name, l, buf, szp, t));
}
int
-nni_tcp_listener_setopt(nni_tcp_listener *l, const char *name, const void *buf,
+nni_tcp_listener_set(nni_tcp_listener *l, const char *name, const void *buf,
size_t sz, nni_type t)
{
return (nni_setopt(tcp_listener_options, name, l, buf, sz, t));
diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h
index 1305b5a0..33947abf 100644
--- a/src/supplemental/http/http_api.h
+++ b/src/supplemental/http/http_api.h
@@ -205,9 +205,9 @@ extern int nni_http_server_set_tls(nni_http_server *, struct nng_tls_config *);
extern int nni_http_server_get_tls(
nni_http_server *, struct nng_tls_config **);
-extern int nni_http_server_setx(
+extern int nni_http_server_set(
nni_http_server *, const char *, const void *, size_t, nni_type);
-extern int nni_http_server_getx(
+extern int nni_http_server_get(
nni_http_server *, const char *, void *, size_t *, nni_type);
// nni_http_server_start starts listening on the supplied port.
@@ -359,9 +359,9 @@ extern int nni_http_client_set_tls(nni_http_client *, struct nng_tls_config *);
extern int nni_http_client_get_tls(
nni_http_client *, struct nng_tls_config **);
-extern int nni_http_client_setx(
- nni_http_client *, const char *, const void *, size_t, nni_type);
-extern int nni_http_client_getx(
+extern int nni_http_client_set(
+ nni_http_client *, const char *, const void *buf, size_t, nni_type);
+extern int nni_http_client_get(
nni_http_client *, const char *, void *, size_t *, nni_type);
extern void nni_http_client_connect(nni_http_client *, nni_aio *);
diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c
index 68f0f61c..c420e1ff 100644
--- a/src/supplemental/http/http_client.c
+++ b/src/supplemental/http/http_client.c
@@ -142,7 +142,7 @@ int
nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls)
{
int rv;
- rv = nni_stream_dialer_setx(c->dialer, NNG_OPT_TLS_CONFIG, &tls,
+ rv = nni_stream_dialer_set(c->dialer, NNG_OPT_TLS_CONFIG, &tls,
sizeof(tls), NNI_TYPE_POINTER);
return (rv);
}
@@ -152,24 +152,24 @@ nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp)
{
size_t sz = sizeof(*tlsp);
int rv;
- rv = nni_stream_dialer_getx(
+ rv = nni_stream_dialer_get(
c->dialer, NNG_OPT_TLS_CONFIG, tlsp, &sz, NNI_TYPE_POINTER);
return (rv);
}
int
-nni_http_client_setx(nni_http_client *c, const char *name, const void *buf,
+nni_http_client_set(nni_http_client *c, const char *name, const void *buf,
size_t sz, nni_type t)
{
// We have no local options, but we just pass them straight through.
- return (nni_stream_dialer_setx(c->dialer, name, buf, sz, t));
+ return (nni_stream_dialer_set(c->dialer, name, buf, sz, t));
}
int
-nni_http_client_getx(
+nni_http_client_get(
nni_http_client *c, const char *name, void *buf, size_t *szp, nni_type t)
{
- return (nni_stream_dialer_getx(c->dialer, name, buf, szp, t));
+ return (nni_stream_dialer_get(c->dialer, name, buf, szp, t));
}
static void
diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c
index 4b0c81c0..646a3067 100644
--- a/src/supplemental/http/http_conn.c
+++ b/src/supplemental/http/http_conn.c
@@ -656,7 +656,7 @@ nni_http_conn_getopt(
if (conn->closed) {
rv = NNG_ECLOSED;
} else {
- rv = nni_stream_getx(conn->sock, name, buf, szp, t);
+ rv = nni_stream_get(conn->sock, name, buf, szp, t);
}
nni_mtx_unlock(&conn->mtx);
return (rv);
@@ -671,7 +671,7 @@ nni_http_conn_setopt(nni_http_conn *conn, const char *name, const void *buf,
if (conn->closed) {
rv = NNG_ECLOSED;
} else {
- rv = nni_stream_setx(conn->sock, name, buf, sz, t);
+ rv = nni_stream_set(conn->sock, name, buf, sz, t);
}
nni_mtx_unlock(&conn->mtx);
return (rv);
diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c
index 60ca2693..7900aa7f 100644
--- a/src/supplemental/http/http_public.c
+++ b/src/supplemental/http/http_public.c
@@ -779,29 +779,29 @@ nng_http_server_set_tls(nng_http_server *srv, struct nng_tls_config *cfg)
}
int
-nng_http_server_get_tls(nng_http_server *srv, struct nng_tls_config **cfgp)
+nng_http_server_get_tls(nng_http_server *srv, struct nng_tls_config **cfg)
{
#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS)
- return (nni_http_server_get_tls(srv, cfgp));
+ return (nni_http_server_get_tls(srv, cfg));
#else
NNI_ARG_UNUSED(srv);
- NNI_ARG_UNUSED(cfgp);
+ NNI_ARG_UNUSED(cfg);
return (NNG_ENOTSUP);
#endif
}
int
-nng_http_server_get_addr(nng_http_server *srv, nng_sockaddr *addrp)
+nng_http_server_get_addr(nng_http_server *srv, nng_sockaddr *addr)
{
#ifdef NNG_SUPP_HTTP
size_t size = sizeof(nng_sockaddr);
- if (srv == NULL || addrp == NULL)
+ if (srv == NULL || addr == NULL)
return NNG_EINVAL;
- return (nni_http_server_getx(
- srv, NNG_OPT_LOCADDR, addrp, &size, NNI_TYPE_SOCKADDR));
+ return (nni_http_server_get(
+ srv, NNG_OPT_LOCADDR, addr, &size, NNI_TYPE_SOCKADDR));
#else
NNI_ARG_UNUSED(srv);
- NNI_ARG_UNUSED(addrp);
+ NNI_ARG_UNUSED(addr);
return (NNG_ENOTSUP);
#endif
}
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index d43dd888..46f2ce8a 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -1869,7 +1869,7 @@ int
nni_http_server_set_tls(nni_http_server *s, nng_tls_config *tls)
{
int rv;
- rv = nni_stream_listener_setx(s->listener, NNG_OPT_TLS_CONFIG, &tls,
+ rv = nni_stream_listener_set(s->listener, NNG_OPT_TLS_CONFIG, &tls,
sizeof(tls), NNI_TYPE_POINTER);
return (rv);
}
@@ -1879,24 +1879,24 @@ nni_http_server_get_tls(nni_http_server *s, nng_tls_config **tlsp)
{
size_t sz = sizeof(*tlsp);
int rv;
- rv = nni_stream_listener_getx(
+ rv = nni_stream_listener_get(
s->listener, NNG_OPT_TLS_CONFIG, tlsp, &sz, NNI_TYPE_POINTER);
return (rv);
}
int
-nni_http_server_setx(nni_http_server *s, const char *name, const void *buf,
+nni_http_server_set(nni_http_server *s, const char *name, const void *buf,
size_t sz, nni_type t)
{
// We have no local options, but we just pass them straight through.
- return (nni_stream_listener_setx(s->listener, name, buf, sz, t));
+ return (nni_stream_listener_set(s->listener, name, buf, sz, t));
}
int
-nni_http_server_getx(
+nni_http_server_get(
nni_http_server *s, const char *name, void *buf, size_t *szp, nni_type t)
{
- return (nni_stream_listener_getx(s->listener, name, buf, szp, t));
+ return (nni_stream_listener_get(s->listener, name, buf, szp, t));
}
void
diff --git a/src/supplemental/tcp/tcp.c b/src/supplemental/tcp/tcp.c
index cde79051..2b1bd987 100644
--- a/src/supplemental/tcp/tcp.c
+++ b/src/supplemental/tcp/tcp.c
@@ -186,19 +186,19 @@ tcp_dialer_dial(void *arg, nng_aio *aio)
}
static int
-tcp_dialer_getx(
+tcp_dialer_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tcp_dialer *d = arg;
- return (nni_tcp_dialer_getopt(d->d, name, buf, szp, t));
+ return (nni_tcp_dialer_get(d->d, name, buf, szp, t));
}
static int
-tcp_dialer_setx(
+tcp_dialer_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
tcp_dialer *d = arg;
- return (nni_tcp_dialer_setopt(d->d, name, buf, sz, t));
+ return (nni_tcp_dialer_set(d->d, name, buf, sz, t));
}
static int
@@ -224,8 +224,8 @@ tcp_dialer_alloc(tcp_dialer **dp)
d->ops.sd_close = tcp_dialer_close;
d->ops.sd_free = tcp_dialer_free;
d->ops.sd_dial = tcp_dialer_dial;
- d->ops.sd_getx = tcp_dialer_getx;
- d->ops.sd_setx = tcp_dialer_setx;
+ d->ops.sd_get = tcp_dialer_get;
+ d->ops.sd_set = tcp_dialer_set;
*dp = d;
return (0);
@@ -320,7 +320,7 @@ tcp_listener_get_port(void *arg, void *buf, size_t *szp, nni_type t)
uint8_t * paddr;
sz = sizeof(sa);
- rv = nni_tcp_listener_getopt(
+ rv = nni_tcp_listener_get(
l->l, NNG_OPT_LOCADDR, &sa, &sz, NNI_TYPE_SOCKADDR);
if (rv != 0) {
return (rv);
@@ -349,22 +349,22 @@ tcp_listener_get_port(void *arg, void *buf, size_t *szp, nni_type t)
}
static int
-tcp_listener_getx(
+tcp_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tcp_listener *l = arg;
if (strcmp(name, NNG_OPT_TCP_BOUND_PORT) == 0) {
return (tcp_listener_get_port(l, buf, szp, t));
}
- return (nni_tcp_listener_getopt(l->l, name, buf, szp, t));
+ return (nni_tcp_listener_get(l->l, name, buf, szp, t));
}
static int
-tcp_listener_setx(
+tcp_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
tcp_listener *l = arg;
- return (nni_tcp_listener_setopt(l->l, name, buf, sz, t));
+ return (nni_tcp_listener_set(l->l, name, buf, sz, t));
}
static int
@@ -386,8 +386,8 @@ tcp_listener_alloc_addr(nng_stream_listener **lp, const nng_sockaddr *sa)
l->ops.sl_close = tcp_listener_close;
l->ops.sl_listen = tcp_listener_listen;
l->ops.sl_accept = tcp_listener_accept;
- l->ops.sl_getx = tcp_listener_getx;
- l->ops.sl_setx = tcp_listener_setx;
+ l->ops.sl_get = tcp_listener_get;
+ l->ops.sl_set = tcp_listener_set;
*lp = (void *) l;
return (0);
@@ -434,35 +434,3 @@ nni_tcp_listener_alloc(nng_stream_listener **lp, const nng_url *url)
return (tcp_listener_alloc_addr(lp, &sa));
}
-
-static int
-tcp_check_bool(const void *val, size_t sz, nni_type t)
-{
- return (nni_copyin_bool(NULL, val, sz, t));
-}
-
-static const nni_chkoption tcp_chkopts[] = {
- {
- .o_name = NNG_OPT_TCP_KEEPALIVE,
- .o_check = tcp_check_bool,
- },
- {
- .o_name = NNG_OPT_TCP_NODELAY,
- .o_check = tcp_check_bool,
- },
- {
- .o_name = NNG_OPT_TCP_BOUND_PORT,
- },
- {
- .o_name = NNG_OPT_LOCADDR,
- },
- {
- .o_name = NULL,
- },
-};
-
-int
-nni_tcp_checkopt(const char *name, const void *data, size_t sz, nni_type t)
-{
- return (nni_chkopt(tcp_chkopts, name, data, sz, t));
-}
diff --git a/src/supplemental/tls/tls_api.h b/src/supplemental/tls/tls_api.h
index 642b9072..0c3e3155 100644
--- a/src/supplemental/tls/tls_api.h
+++ b/src/supplemental/tls/tls_api.h
@@ -18,6 +18,5 @@
// object. All fields will be zeroed.
extern int nni_tls_dialer_alloc(nng_stream_dialer **, const nng_url *);
extern int nni_tls_listener_alloc(nng_stream_listener **, const nng_url *);
-extern int nni_tls_checkopt(const char *, const void *, size_t, nni_type);
#endif // NNG_SUPPLEMENTAL_TLS_TLS_API_H
diff --git a/src/supplemental/tls/tls_common.c b/src/supplemental/tls/tls_common.c
index 243ac20e..e23fb4d8 100644
--- a/src/supplemental/tls/tls_common.c
+++ b/src/supplemental/tls/tls_common.c
@@ -188,13 +188,18 @@ tls_dialer_dial(void *arg, nng_aio *aio)
static int
tls_check_string(const void *v, size_t sz, nni_opt_type t)
{
- if ((t != NNI_TYPE_OPAQUE) && (t != NNI_TYPE_STRING)) {
+ switch (t) {
+ case NNI_TYPE_OPAQUE:
+ if (nni_strnlen(v, sz) >= sz) {
+ return (NNG_EINVAL);
+ }
+ return (0);
+ case NNI_TYPE_STRING:
+ // Caller is assumed to pass a good string.
+ return (0);
+ default:
return (NNG_EBADTYPE);
}
- if (nni_strnlen(v, sz) >= sz) {
- return (NNG_EINVAL);
- }
- return (0);
}
static int
@@ -326,13 +331,13 @@ static const nni_option tls_dialer_opts[] = {
};
static int
-tls_dialer_getx(
+tls_dialer_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tls_dialer *d = arg;
int rv;
- rv = nni_stream_dialer_getx(d->d, name, buf, szp, t);
+ rv = nni_stream_dialer_get(d->d, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tls_dialer_opts, name, d, buf, szp, t);
}
@@ -340,13 +345,13 @@ tls_dialer_getx(
}
static int
-tls_dialer_setx(
+tls_dialer_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
tls_dialer *d = arg;
int rv;
- rv = nni_stream_dialer_setx(d->d, name, buf, sz, t);
+ rv = nni_stream_dialer_set(d->d, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tls_dialer_opts, name, d, buf, sz, t);
}
@@ -391,8 +396,8 @@ nni_tls_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
d->ops.sd_close = tls_dialer_close;
d->ops.sd_free = tls_dialer_free;
d->ops.sd_dial = tls_dialer_dial;
- d->ops.sd_getx = tls_dialer_getx;
- d->ops.sd_setx = tls_dialer_setx;
+ d->ops.sd_get = tls_dialer_get;
+ d->ops.sd_set = tls_dialer_set;
*dp = (void *) d;
return (rv);
}
@@ -586,13 +591,13 @@ static const nni_option tls_listener_opts[] = {
};
static int
-tls_listener_getx(
+tls_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
int rv;
tls_listener *l = arg;
- rv = nni_stream_listener_getx(l->l, name, buf, szp, t);
+ rv = nni_stream_listener_get(l->l, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tls_listener_opts, name, l, buf, szp, t);
}
@@ -600,13 +605,13 @@ tls_listener_getx(
}
static int
-tls_listener_setx(
+tls_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
int rv;
tls_listener *l = arg;
- rv = nni_stream_listener_setx(l->l, name, buf, sz, t);
+ rv = nni_stream_listener_set(l->l, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tls_listener_opts, name, l, buf, sz, t);
}
@@ -649,80 +654,12 @@ nni_tls_listener_alloc(nng_stream_listener **lp, const nng_url *url)
l->ops.sl_close = tls_listener_close;
l->ops.sl_accept = tls_listener_accept;
l->ops.sl_listen = tls_listener_listen;
- l->ops.sl_getx = tls_listener_getx;
- l->ops.sl_setx = tls_listener_setx;
+ l->ops.sl_get = tls_listener_get;
+ l->ops.sl_set = tls_listener_set;
*lp = (void *) l;
return (0);
}
-// The following checks exist for socket configuration, when we need to
-// configure an option on a socket before any transport is configured
-// underneath.
-
-static int
-tls_check_config(const void *buf, size_t sz, nni_type t)
-{
- int rv;
- nng_tls_config *cfg;
-
- if ((rv = nni_copyin_ptr((void **) &cfg, buf, sz, t)) != 0) {
- return (rv);
- }
- if (cfg == NULL) {
- return (NNG_EINVAL);
- }
- return (0);
-}
-
-static int
-tls_check_auth_mode(const void *buf, size_t sz, nni_type t)
-{
- int mode;
- int rv;
-
- rv = nni_copyin_int(&mode, buf, sz, NNG_TLS_AUTH_MODE_NONE,
- NNG_TLS_AUTH_MODE_REQUIRED, t);
- return (rv);
-}
-
-static const nni_chkoption tls_check_opts[] = {
- {
- .o_name = NNG_OPT_TLS_CONFIG,
- .o_check = tls_check_config,
- },
- {
- .o_name = NNG_OPT_TLS_SERVER_NAME,
- .o_check = tls_check_string,
- },
- {
- .o_name = NNG_OPT_TLS_CA_FILE,
- .o_check = tls_check_string,
- },
- {
- .o_name = NNG_OPT_TLS_CERT_KEY_FILE,
- .o_check = tls_check_string,
- },
- {
- .o_name = NNG_OPT_TLS_AUTH_MODE,
- .o_check = tls_check_auth_mode,
- },
- {
- .o_name = NULL,
- },
-};
-
-int
-nni_tls_checkopt(const char *name, const void *data, size_t sz, nni_type t)
-{
- int rv;
-
- rv = nni_chkopt(tls_check_opts, name, data, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tcp", name, data, sz, t);
- }
- return (rv);
-}
-
static void
tls_cancel(nni_aio *aio, void *arg, int rv)
{
@@ -826,7 +763,7 @@ static const nni_option tls_options[] = {
};
static int
-tls_setx(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
+tls_set(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
tls_conn * conn = arg;
int rv;
@@ -834,19 +771,19 @@ tls_setx(void *arg, const char *name, const void *buf, size_t sz, nni_type t)
tcp = (conn != NULL) ? conn->tcp : NULL;
- if ((rv = nni_stream_setx(tcp, name, buf, sz, t)) != NNG_ENOTSUP) {
+ if ((rv = nni_stream_set(tcp, name, buf, sz, t)) != NNG_ENOTSUP) {
return (rv);
}
return (nni_setopt(tls_options, name, conn, buf, sz, t));
}
static int
-tls_getx(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+tls_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tls_conn *conn = arg;
int rv;
- if ((rv = nni_stream_getx(conn->tcp, name, buf, szp, t)) !=
+ if ((rv = nni_stream_get(conn->tcp, name, buf, szp, t)) !=
NNG_ENOTSUP) {
return (rv);
}
@@ -893,8 +830,8 @@ tls_alloc(tls_conn **conn_p, nng_tls_config *cfg, nng_aio *user_aio)
conn->stream.s_free = tls_free;
conn->stream.s_send = tls_send;
conn->stream.s_recv = tls_recv;
- conn->stream.s_getx = tls_getx;
- conn->stream.s_setx = tls_setx;
+ conn->stream.s_get = tls_get;
+ conn->stream.s_set = tls_set;
nng_tls_config_hold(cfg);
*conn_p = conn;
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index e65fc24f..20adf626 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -179,8 +179,8 @@ static void ws_str_free(void *);
static void ws_str_close(void *);
static void ws_str_send(void *, nng_aio *);
static void ws_str_recv(void *, nng_aio *);
-static int ws_str_getx(void *, const char *, void *, size_t *, nni_type);
-static int ws_str_setx(void *, const char *, const void *, size_t, nni_type);
+static int ws_str_get(void *, const char *, void *, size_t *, nni_type);
+static int ws_str_set(void *, const char *, const void *, size_t, nni_type);
static void ws_listener_close(void *);
static void ws_listener_free(void *);
@@ -1438,8 +1438,8 @@ ws_init(nni_ws **wsp)
ws->ops.s_free = ws_str_free;
ws->ops.s_send = ws_str_send;
ws->ops.s_recv = ws_str_recv;
- ws->ops.s_getx = ws_str_getx;
- ws->ops.s_setx = ws_str_setx;
+ ws->ops.s_get = ws_str_get;
+ ws->ops.s_set = ws_str_set;
ws->fragsize = 1 << 20; // we won't send a frame larger than this
*wsp = ws;
@@ -2047,7 +2047,7 @@ ws_listener_set_header(nni_ws_listener *l, const char *name, const void *buf,
}
static int
-ws_listener_setx(
+ws_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
nni_ws_listener *l = arg;
@@ -2055,7 +2055,7 @@ ws_listener_setx(
rv = nni_setopt(ws_listener_options, name, l, buf, sz, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_http_server_setx(l->server, name, buf, sz, t);
+ rv = nni_http_server_set(l->server, name, buf, sz, t);
}
if (rv == NNG_ENOTSUP) {
@@ -2067,7 +2067,7 @@ ws_listener_setx(
}
static int
-ws_listener_getx(
+ws_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
nni_ws_listener *l = arg;
@@ -2075,7 +2075,7 @@ ws_listener_getx(
rv = nni_getopt(ws_listener_options, name, l, buf, szp, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_http_server_getx(l->server, name, buf, szp, t);
+ rv = nni_http_server_get(l->server, name, buf, szp, t);
}
return (rv);
}
@@ -2128,8 +2128,8 @@ nni_ws_listener_alloc(nng_stream_listener **wslp, const nng_url *url)
l->ops.sl_close = ws_listener_close;
l->ops.sl_accept = ws_listener_accept;
l->ops.sl_listen = ws_listener_listen;
- l->ops.sl_setx = ws_listener_setx;
- l->ops.sl_getx = ws_listener_getx;
+ l->ops.sl_set = ws_listener_set;
+ l->ops.sl_get = ws_listener_get;
*wslp = (void *) l;
return (0);
}
@@ -2578,7 +2578,7 @@ ws_dialer_set_header(
}
static int
-ws_dialer_setx(
+ws_dialer_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
nni_ws_dialer *d = arg;
@@ -2586,7 +2586,7 @@ ws_dialer_setx(
rv = nni_setopt(ws_dialer_options, name, d, buf, sz, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_http_client_setx(d->client, name, buf, sz, t);
+ rv = nni_http_client_set(d->client, name, buf, sz, t);
}
if (rv == NNG_ENOTSUP) {
@@ -2598,14 +2598,14 @@ ws_dialer_setx(
}
static int
-ws_dialer_getx(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+ws_dialer_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
nni_ws_dialer *d = arg;
int rv;
rv = nni_getopt(ws_dialer_options, name, d, buf, szp, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_http_client_getx(d->client, name, buf, szp, t);
+ rv = nni_http_client_get(d->client, name, buf, szp, t);
}
return (rv);
}
@@ -2641,8 +2641,8 @@ nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
d->ops.sd_free = ws_dialer_free;
d->ops.sd_close = ws_dialer_close;
d->ops.sd_dial = ws_dialer_dial;
- d->ops.sd_setx = ws_dialer_setx;
- d->ops.sd_getx = ws_dialer_getx;
+ d->ops.sd_set = ws_dialer_set;
+ d->ops.sd_get = ws_dialer_get;
*dp = (void *) d;
return (0);
}
@@ -2652,9 +2652,6 @@ nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
// the dialer does not confirm the server's response at the HTTP
// level. (It can still issue a websocket close).
-// The implementation will send periodic PINGs, and respond with
-// PONGs.
-
static void
ws_str_free(void *arg)
{
@@ -2840,7 +2837,7 @@ static const nni_option ws_options[] = {
};
static int
-ws_str_setx(void *arg, const char *nm, const void *buf, size_t sz, nni_type t)
+ws_str_set(void *arg, const char *nm, const void *buf, size_t sz, nni_type t)
{
nni_ws *ws = arg;
int rv;
@@ -2893,7 +2890,7 @@ ws_get_res_header(
}
static int
-ws_str_getx(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
+ws_str_get(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
{
nni_ws *ws = arg;
int rv;
@@ -2918,75 +2915,3 @@ ws_str_getx(void *arg, const char *nm, void *buf, size_t *szp, nni_type t)
}
return (rv);
}
-
-static int
-ws_check_size(const void *buf, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, buf, sz, 0, NNI_MAXSZ, t));
-}
-
-static int
-ws_check_bool(const void *buf, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, buf, sz, 0, NNI_MAXSZ, t));
-}
-
-static const nni_chkoption ws_chkopts[] = {
- {
- .o_name = NNG_OPT_WS_SENDMAXFRAME,
- .o_check = ws_check_size,
- },
- {
- .o_name = NNG_OPT_WS_RECVMAXFRAME,
- .o_check = ws_check_size,
- },
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = ws_check_size,
- },
- {
- .o_name = NNG_OPT_WS_PROTOCOL,
- .o_check = ws_check_string,
- },
- {
- .o_name = NNG_OPT_WS_REQUEST_HEADERS,
- .o_check = ws_check_string,
- },
- {
- .o_name = NNG_OPT_WS_RESPONSE_HEADERS,
- .o_check = ws_check_string,
- },
- {
- .o_name = NNG_OPT_WS_RECV_TEXT,
- .o_check = ws_check_bool,
- },
- {
- .o_name = NNG_OPT_WS_SEND_TEXT,
- .o_check = ws_check_bool,
- },
- {
- .o_name = NULL,
- },
-};
-
-int
-nni_ws_checkopt(const char *name, const void *data, size_t sz, nni_type t)
-{
- int rv;
-
- rv = nni_chkopt(ws_chkopts, name, data, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tcp", name, data, sz, t);
- }
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tls+tcp", name, data, sz, t);
- }
- if (rv == NNG_ENOTSUP) {
- if (startswith(name, NNG_OPT_WS_REQUEST_HEADER) ||
- startswith(name, NNG_OPT_WS_RESPONSE_HEADER)) {
- rv = ws_check_string(data, sz, t);
- }
- }
- // Potentially, add checks for header options.
- return (rv);
-}
diff --git a/src/supplemental/websocket/websocket.h b/src/supplemental/websocket/websocket.h
index 1ecb4618..ea4975ff 100644
--- a/src/supplemental/websocket/websocket.h
+++ b/src/supplemental/websocket/websocket.h
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -33,6 +33,5 @@ typedef struct nni_ws_dialer nni_ws_dialer;
// rely upon it being around.
extern int nni_ws_listener_alloc(nng_stream_listener **, const nni_url *);
extern int nni_ws_dialer_alloc(nng_stream_dialer **, const nni_url *);
-extern int nni_ws_checkopt(const char *, const void *, size_t, nni_type);
#endif // NNG_SUPPLEMENTAL_WEBSOCKET_WEBSOCKET_H
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c
index a1a2dd5d..84e2c625 100644
--- a/src/transport/inproc/inproc.c
+++ b/src/transport/inproc/inproc.c
@@ -654,36 +654,6 @@ inproc_ep_setopt(
return (nni_setopt(inproc_ep_options, name, arg, v, sz, t));
}
-static int
-inproc_check_recvmaxsz(const void *v, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t));
-}
-
-static nni_chkoption inproc_checkopts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = inproc_check_recvmaxsz,
- },
- {
- .o_name = NNG_OPT_LOCADDR,
- },
- {
- .o_name = NNG_OPT_REMADDR,
- },
- {
- .o_name = NULL,
- },
-};
-
-static int
-inproc_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(inproc_checkopts, name, buf, sz, t);
- return (rv);
-}
-
static nni_tran_dialer_ops inproc_dialer_ops = {
.d_init = inproc_dialer_init,
.d_fini = inproc_ep_fini,
@@ -713,7 +683,6 @@ struct nni_tran nni_inproc_tran = {
.tran_pipe = &inproc_pipe_ops,
.tran_init = inproc_init,
.tran_fini = inproc_fini,
- .tran_checkopt = inproc_checkopt,
};
int
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c
index ea135ad8..9e75f13a 100644
--- a/src/transport/ipc/ipc.c
+++ b/src/transport/ipc/ipc.c
@@ -1007,7 +1007,7 @@ ipc_pipe_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ipc_pipe *p = arg;
- return (nni_stream_getx(p->conn, name, buf, szp, t));
+ return (nni_stream_get(p->conn, name, buf, szp, t));
}
static nni_tran_pipe_ops ipc_tran_pipe_ops = {
@@ -1041,7 +1041,7 @@ ipc_dialer_get(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
rv = nni_getopt(ipc_ep_options, name, ep, buf, szp, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_stream_dialer_getx(ep->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(ep->dialer, name, buf, szp, t);
}
return (rv);
}
@@ -1055,7 +1055,7 @@ ipc_dialer_set(
rv = nni_setopt(ipc_ep_options, name, ep, buf, sz, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_stream_dialer_setx(ep->dialer, name, buf, sz, t);
+ rv = nni_stream_dialer_set(ep->dialer, name, buf, sz, t);
}
return (rv);
}
@@ -1069,7 +1069,7 @@ ipc_listener_get(
rv = nni_getopt(ipc_ep_options, name, ep, buf, szp, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_stream_listener_getx(ep->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(ep->listener, name, buf, szp, t);
}
return (rv);
}
@@ -1083,34 +1083,7 @@ ipc_listener_set(
rv = nni_setopt(ipc_ep_options, name, ep, buf, sz, t);
if (rv == NNG_ENOTSUP) {
- rv = nni_stream_listener_setx(ep->listener, name, buf, sz, t);
- }
- return (rv);
-}
-
-static int
-ipc_check_recv_max_sz(const void *v, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t));
-}
-
-static nni_chkoption ipc_check_opts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = ipc_check_recv_max_sz,
- },
- {
- .o_name = NULL,
- },
-};
-
-static int
-ipc_check_opt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(ipc_check_opts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("ipc", name, buf, sz, t);
+ rv = nni_stream_listener_set(ep->listener, name, buf, sz, t);
}
return (rv);
}
@@ -1142,7 +1115,6 @@ static nni_tran ipc_tran = {
.tran_pipe = &ipc_tran_pipe_ops,
.tran_init = ipc_tran_init,
.tran_fini = ipc_tran_fini,
- .tran_checkopt = ipc_check_opt,
};
#ifdef NNG_PLATFORM_POSIX
@@ -1154,7 +1126,6 @@ static nni_tran ipc_tran_unix = {
.tran_pipe = &ipc_tran_pipe_ops,
.tran_init = ipc_tran_init,
.tran_fini = ipc_tran_fini,
- .tran_checkopt = ipc_check_opt,
};
#endif
@@ -1167,7 +1138,6 @@ static nni_tran ipc_tran_abstract = {
.tran_pipe = &ipc_tran_pipe_ops,
.tran_init = ipc_tran_init,
.tran_fini = ipc_tran_fini,
- .tran_checkopt = ipc_check_opt,
};
#endif
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 02bc078e..cf0bfeb1 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -593,7 +593,7 @@ tcptran_pipe_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
tcptran_pipe *p = arg;
- return (nni_stream_getx(p->conn, name, buf, szp, t));
+ return (nni_stream_get(p->conn, name, buf, szp, t));
}
static void
@@ -863,11 +863,11 @@ tcptran_ep_init(tcptran_ep **epp, nng_url *url, nni_sock *sock)
#ifdef NNG_ENABLE_STATS
static const nni_stat_info rcv_max_info = {
- .si_name = "rcv_max",
- .si_desc = "maximum receive size",
- .si_type = NNG_STAT_LEVEL,
- .si_unit = NNG_UNIT_BYTES,
- .si_atomic = true,
+ .si_name = "rcv_max",
+ .si_desc = "maximum receive size",
+ .si_type = NNG_STAT_LEVEL,
+ .si_unit = NNG_UNIT_BYTES,
+ .si_atomic = true,
};
nni_stat_init(&ep->st_rcv_max, &rcv_max_info);
#endif
@@ -910,7 +910,7 @@ tcptran_dialer_init(void **dp, nng_url *url, nni_dialer *ndialer)
return (rv);
}
if ((srcsa.s_family != NNG_AF_UNSPEC) &&
- ((rv = nni_stream_dialer_setx(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
+ ((rv = nni_stream_dialer_set(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
sizeof(srcsa), NNI_TYPE_SOCKADDR)) != 0)) {
tcptran_ep_fini(ep);
return (rv);
@@ -1141,7 +1141,7 @@ tcptran_dialer_getopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_dialer_getx(ep->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(ep->dialer, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tcptran_ep_opts, name, ep, buf, szp, t);
}
@@ -1155,7 +1155,7 @@ tcptran_dialer_setopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_dialer_setx(ep->dialer, name, buf, sz, t);
+ rv = nni_stream_dialer_set(ep->dialer, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tcptran_ep_opts, name, ep, buf, sz, t);
}
@@ -1169,7 +1169,7 @@ tcptran_listener_getopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_listener_getx(ep->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(ep->listener, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tcptran_ep_opts, name, ep, buf, szp, t);
}
@@ -1183,40 +1183,13 @@ tcptran_listener_setopt(
tcptran_ep *ep = arg;
int rv;
- rv = nni_stream_listener_setx(ep->listener, name, buf, sz, t);
+ rv = nni_stream_listener_set(ep->listener, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tcptran_ep_opts, name, ep, buf, sz, t);
}
return (rv);
}
-static int
-tcptran_check_recvmaxsz(const void *v, size_t sz, nni_type t)
-{
- return (nni_copyin_size(NULL, v, sz, 0, NNI_MAXSZ, t));
-}
-
-static nni_chkoption tcptran_checkopts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = tcptran_check_recvmaxsz,
- },
- {
- .o_name = NULL,
- },
-};
-
-static int
-tcptran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(tcptran_checkopts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tcp", name, buf, sz, t);
- }
- return (rv);
-}
-
static nni_tran_dialer_ops tcptran_dialer_ops = {
.d_init = tcptran_dialer_init,
.d_fini = tcptran_ep_fini,
@@ -1244,7 +1217,6 @@ static nni_tran tcp_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
static nni_tran tcp4_tran = {
@@ -1255,7 +1227,6 @@ static nni_tran tcp4_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
static nni_tran tcp6_tran = {
@@ -1266,7 +1237,6 @@ static nni_tran tcp6_tran = {
.tran_pipe = &tcptran_pipe_ops,
.tran_init = tcptran_init,
.tran_fini = tcptran_fini,
- .tran_checkopt = tcptran_checkopt,
};
int
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index ae5d86ec..62393d22 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -883,7 +883,7 @@ tlstran_ep_init_dialer(void **dp, nni_url *url, nni_dialer *ndialer)
return (rv);
}
if ((srcsa.s_family != NNG_AF_UNSPEC) &&
- ((rv = nni_stream_dialer_setx(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
+ ((rv = nni_stream_dialer_set(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
sizeof(srcsa), NNI_TYPE_SOCKADDR)) != 0)) {
tlstran_ep_fini(ep);
return (rv);
@@ -952,7 +952,7 @@ tlstran_ep_init_listener(void **lp, nni_url *url, nni_listener *nlistener)
if ((rv != 0) ||
((rv = nng_stream_listener_alloc_url(&ep->listener, url)) != 0) ||
- ((rv = nni_stream_listener_setx(ep->listener,
+ ((rv = nni_stream_listener_set(ep->listener,
NNG_OPT_TLS_AUTH_MODE, &ep->authmode, sizeof(ep->authmode),
NNI_TYPE_INT32)) != 0)) {
tlstran_ep_fini(ep);
@@ -1128,19 +1128,12 @@ tlstran_pipe_getopt(
tlstran_pipe *p = arg;
int rv;
- if ((rv = nni_stream_getx(p->tls, name, buf, szp, t)) == NNG_ENOTSUP) {
+ if ((rv = nni_stream_get(p->tls, name, buf, szp, t)) == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_pipe_opts, name, p, buf, szp, t);
}
return (rv);
}
-static int
-tlstran_check_recvmaxsz(const void *v, size_t sz, nni_type t)
-{
- size_t val;
- return (nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t));
-}
-
static nni_tran_pipe_ops tlstran_pipe_ops = {
.p_init = tlstran_pipe_init,
.p_fini = tlstran_pipe_fini,
@@ -1168,16 +1161,6 @@ static nni_option tlstran_ep_options[] = {
},
};
-static nni_chkoption tlstran_checkopts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = tlstran_check_recvmaxsz,
- },
- {
- .o_name = NULL,
- },
-};
-
static int
tlstran_dialer_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
@@ -1185,7 +1168,7 @@ tlstran_dialer_getopt(
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_dialer_getx(ep->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(ep->dialer, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_ep_options, name, ep, buf, szp, t);
}
@@ -1199,7 +1182,7 @@ tlstran_dialer_setopt(
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_dialer_setx(
+ rv = nni_stream_dialer_set(
ep != NULL ? ep->dialer : NULL, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tlstran_ep_options, name, ep, buf, sz, t);
@@ -1208,13 +1191,13 @@ tlstran_dialer_setopt(
}
static int
-tlstran_listener_getopt(
+tlstran_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_listener_getx(ep->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(ep->listener, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_ep_options, name, ep, buf, szp, t);
}
@@ -1222,13 +1205,13 @@ tlstran_listener_getopt(
}
static int
-tlstran_listener_setopt(
+tlstran_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_listener_setx(
+ rv = nni_stream_listener_set(
ep != NULL ? ep->listener : NULL, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tlstran_ep_options, name, ep, buf, sz, t);
@@ -1236,17 +1219,6 @@ tlstran_listener_setopt(
return (rv);
}
-static int
-tlstran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(tlstran_checkopts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tls+tcp", name, buf, sz, t);
- }
- return (rv);
-}
-
static nni_tran_dialer_ops tlstran_dialer_ops = {
.d_init = tlstran_ep_init_dialer,
.d_fini = tlstran_ep_fini,
@@ -1262,8 +1234,8 @@ static nni_tran_listener_ops tlstran_listener_ops = {
.l_bind = tlstran_ep_bind,
.l_accept = tlstran_ep_accept,
.l_close = tlstran_ep_close,
- .l_getopt = tlstran_listener_getopt,
- .l_setopt = tlstran_listener_setopt,
+ .l_getopt = tlstran_listener_get,
+ .l_setopt = tlstran_listener_set,
};
static nni_tran tls_tran = {
@@ -1274,7 +1246,6 @@ static nni_tran tls_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
static nni_tran tls4_tran = {
@@ -1285,7 +1256,6 @@ static nni_tran tls4_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
static nni_tran tls6_tran = {
@@ -1296,7 +1266,6 @@ static nni_tran tls6_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
int
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index 03dc4139..3f73f47f 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -348,7 +348,7 @@ wstran_pipe_getopt(
ws_pipe *p = arg;
int rv;
- if ((rv = nni_stream_getx(p->ws, name, buf, szp, t)) == NNG_ENOTSUP) {
+ if ((rv = nni_stream_get(p->ws, name, buf, szp, t)) == NNG_ENOTSUP) {
rv = nni_getopt(ws_pipe_options, name, p, buf, szp, t);
}
return (rv);
@@ -573,7 +573,7 @@ wstran_dialer_getopt(
ws_dialer *d = arg;
int rv;
- rv = nni_stream_dialer_getx(d->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(d->dialer, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(wstran_ep_opts, name, d, buf, szp, t);
}
@@ -587,7 +587,7 @@ wstran_dialer_setopt(
ws_dialer *d = arg;
int rv;
- rv = nni_stream_dialer_setx(d->dialer, name, buf, sz, t);
+ rv = nni_stream_dialer_set(d->dialer, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(wstran_ep_opts, name, d, buf, sz, t);
}
@@ -595,13 +595,13 @@ wstran_dialer_setopt(
}
static int
-wstran_listener_getopt(
+wstran_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
ws_listener *l = arg;
int rv;
- rv = nni_stream_listener_getx(l->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(l->listener, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(wstran_ep_opts, name, l, buf, szp, t);
}
@@ -609,36 +609,19 @@ wstran_listener_getopt(
}
static int
-wstran_listener_setopt(
+wstran_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
ws_listener *l = arg;
int rv;
- rv = nni_stream_listener_setx(l->listener, name, buf, sz, t);
+ rv = nni_stream_listener_set(l->listener, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(wstran_ep_opts, name, l, buf, sz, t);
}
return (rv);
}
-static nni_chkoption wstran_check_opts[] = {
- {
- .o_name = NULL,
- },
-};
-
-static int
-wstran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(wstran_check_opts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("ws", name, buf, sz, t);
- }
- return (rv);
-}
-
static nni_tran_dialer_ops ws_dialer_ops = {
.d_init = wstran_dialer_init,
.d_fini = wstran_dialer_fini,
@@ -654,8 +637,8 @@ static nni_tran_listener_ops ws_listener_ops = {
.l_bind = ws_listener_bind,
.l_accept = wstran_listener_accept,
.l_close = wstran_listener_close,
- .l_setopt = wstran_listener_setopt,
- .l_getopt = wstran_listener_getopt,
+ .l_setopt = wstran_listener_set,
+ .l_getopt = wstran_listener_get,
};
static nni_tran ws_tran = {
@@ -666,7 +649,6 @@ static nni_tran ws_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
static nni_tran ws4_tran = {
@@ -677,7 +659,6 @@ static nni_tran ws4_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
static nni_tran ws6_tran = {
@@ -688,7 +669,6 @@ static nni_tran ws6_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
int
@@ -714,7 +694,6 @@ static nni_tran wss_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
static nni_tran wss4_tran = {
@@ -725,7 +704,6 @@ static nni_tran wss4_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
static nni_tran wss6_tran = {
@@ -736,7 +714,6 @@ static nni_tran wss6_tran = {
.tran_pipe = &ws_pipe_ops,
.tran_init = wstran_init,
.tran_fini = wstran_fini,
- .tran_checkopt = wstran_checkopt,
};
int
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index 2667d027..c66a4b2c 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -1664,52 +1664,6 @@ zt_check_tries(const void *v, size_t sz, nni_type t)
return (nni_copyin_int(NULL, v, sz, 0, 1000000, t));
}
-static nni_chkoption zt_tran_check_opts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = zt_check_recvmaxsz,
- },
- {
- .o_name = NNG_OPT_ZT_HOME,
- .o_check = zt_check_string,
- },
- {
- .o_name = NNG_OPT_ZT_ORBIT,
- .o_check = zt_check_orbit,
- },
- {
- .o_name = NNG_OPT_ZT_DEORBIT,
- .o_check = zt_check_deorbit,
- },
- {
- .o_name = NNG_OPT_ZT_CONN_TIME,
- .o_check = zt_check_time,
- },
- {
- .o_name = NNG_OPT_ZT_PING_TIME,
- .o_check = zt_check_time,
- },
- {
- .o_name = NNG_OPT_ZT_PING_TRIES,
- .o_check = zt_check_tries,
- },
- {
- .o_name = NNG_OPT_ZT_CONN_TRIES,
- .o_check = zt_check_tries,
- },
- {
- .o_name = NULL,
- },
-};
-
-static int
-zt_tran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(zt_tran_check_opts, name, buf, sz, t);
- return (rv);
-}
-
static void
zt_pipe_close(void *arg)
{
@@ -2647,8 +2601,7 @@ zt_ep_set_recvmaxsz(void *arg, const void *data, size_t sz, nni_type t)
size_t val;
int rv;
- if (((rv = nni_copyin_size(&val, data, sz, 0, NNI_MAXSZ, t)) == 0) &&
- (ep != NULL)) {
+ if ((rv = nni_copyin_size(&val, data, sz, 0, NNI_MAXSZ, t)) == 0) {
nni_mtx_lock(&zt_lk);
ep->ze_rcvmax = val;
nni_mtx_unlock(&zt_lk);
@@ -2673,7 +2626,7 @@ zt_ep_set_home(void *arg, const void *data, size_t sz, nni_type t)
int rv;
zt_ep *ep = arg;
- if (((rv = zt_check_string(data, sz, t)) == 0) && (ep != NULL)) {
+ if ((rv = zt_check_string(data, sz, t)) == 0) {
nni_mtx_lock(&zt_lk);
if (ep->ze_running) {
rv = NNG_ESTATE;
@@ -2740,9 +2693,6 @@ zt_ep_set_orbit(void *arg, const void *data, size_t sz, nni_type t)
} else {
return (NNG_EINVAL);
}
- if (ep == NULL) {
- return (0);
- }
nni_mtx_lock(&zt_lk);
if ((ep->ze_ztn == NULL) && ((rv = zt_node_find(ep)) != 0)) {
@@ -2762,8 +2712,7 @@ zt_ep_set_deorbit(void *arg, const void *data, size_t sz, nni_type t)
zt_ep * ep = arg;
int rv;
- if (((rv = nni_copyin_u64(&moonid, data, sz, t)) == 0) &&
- (ep != NULL)) {
+ if ((rv = nni_copyin_u64(&moonid, data, sz, t)) == 0) {
enum ZT_ResultCode zrv;
nni_mtx_lock(&zt_lk);
@@ -2810,9 +2759,6 @@ zt_ep_set_add_local_addr(void *arg, const void *data, size_t sz, nni_type t)
return (NNG_EINVAL);
}
- if (ep == NULL) {
- return (0);
- }
nni_mtx_lock(&zt_lk);
if ((ep->ze_ztn == NULL) && ((rv = zt_node_find(ep)) != 0)) {
nni_mtx_unlock(&zt_lk);
@@ -2830,22 +2776,20 @@ static int
zt_ep_set_clear_local_addrs(void *arg, const void *data, size_t sz, nni_type t)
{
zt_ep *ep = arg;
+ int rv;
NNI_ARG_UNUSED(data);
NNI_ARG_UNUSED(sz);
NNI_ARG_UNUSED(t);
- if (ep != NULL) {
- int rv;
- ZT_Node *zn;
- nni_mtx_lock(&zt_lk);
- if ((ep->ze_ztn == NULL) && ((rv = zt_node_find(ep)) != 0)) {
- nni_mtx_unlock(&zt_lk);
- return (rv);
- }
- zn = ep->ze_ztn;
- ZT_Node_clearLocalInterfaceAddresses(zn);
+ ZT_Node *zn;
+ nni_mtx_lock(&zt_lk);
+ if ((ep->ze_ztn == NULL) && ((rv = zt_node_find(ep)) != 0)) {
nni_mtx_unlock(&zt_lk);
+ return (rv);
}
+ zn = ep->ze_ztn;
+ ZT_Node_clearLocalInterfaceAddresses(zn);
+ nni_mtx_unlock(&zt_lk);
return (0);
}
@@ -2926,7 +2870,7 @@ zt_ep_set_ping_time(void *arg, const void *data, size_t sz, nni_type t)
nng_duration val;
int rv;
- if (((rv = nni_copyin_ms(&val, data, sz, t)) == 0) && (ep != NULL)) {
+ if ((rv = nni_copyin_ms(&val, data, sz, t)) == 0) {
nni_mtx_lock(&zt_lk);
ep->ze_ping_time = val;
nni_mtx_unlock(&zt_lk);
@@ -2953,8 +2897,7 @@ zt_ep_set_ping_tries(void *arg, const void *data, size_t sz, nni_type t)
int val;
int rv;
- if (((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) &&
- (ep != NULL)) {
+ if ((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) {
nni_mtx_lock(&zt_lk);
ep->ze_ping_tries = val;
nni_mtx_unlock(&zt_lk);
@@ -2981,7 +2924,7 @@ zt_ep_set_conn_time(void *arg, const void *data, size_t sz, nni_type t)
nng_duration val;
int rv;
- if (((rv = nni_copyin_ms(&val, data, sz, t)) == 0) && (ep != NULL)) {
+ if ((rv = nni_copyin_ms(&val, data, sz, t)) == 0) {
nni_mtx_lock(&zt_lk);
ep->ze_conn_time = val;
nni_mtx_unlock(&zt_lk);
@@ -3008,8 +2951,7 @@ zt_ep_set_conn_tries(void *arg, const void *data, size_t sz, nni_type t)
int val;
int rv;
- if (((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) &&
- (ep != NULL)) {
+ if ((rv = nni_copyin_int(&val, data, sz, 0, 1000000, t)) == 0) {
nni_mtx_lock(&zt_lk);
ep->ze_conn_tries = val;
nni_mtx_unlock(&zt_lk);
@@ -3288,7 +3230,6 @@ static struct nni_tran zt_tran = {
.tran_pipe = &zt_pipe_ops,
.tran_init = zt_tran_init,
.tran_fini = zt_tran_fini,
- .tran_checkopt = zt_tran_checkopt,
};
int
diff --git a/tests/sock.c b/tests/sock.c
index cf803402..7b19f378 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -92,7 +92,6 @@ test_readonly_options(void)
TEST_CHECK(nng_pair1_open(&s1) == 0);
TEST_CHECK(nng_setopt_int(s1, NNG_OPT_RECVFD, 0) == NNG_EREADONLY);
TEST_CHECK(nng_setopt_int(s1, NNG_OPT_SENDFD, 0) == NNG_EREADONLY);
- TEST_CHECK(nng_setopt(s1, NNG_OPT_LOCADDR, "a", 1) == NNG_EREADONLY);
TEST_CHECK(nng_close(s1) == 0);
}
diff --git a/tools/nngcat/nngcat.c b/tools/nngcat/nngcat.c
index 7b5146c0..9e106069 100644
--- a/tools/nngcat/nngcat.c
+++ b/tools/nngcat/nngcat.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2020 Lager Data, Inc. <support@lagerdata.com>
//
@@ -311,7 +311,7 @@ static void
loadfile(const char *path, void **datap, size_t *lenp)
{
FILE * f;
- size_t total_read = 0;
+ size_t total_read = 0;
size_t allocation_size = BUFSIZ;
char * fdata;
char * realloc_result;
@@ -320,7 +320,8 @@ loadfile(const char *path, void **datap, size_t *lenp)
f = stdin;
} else {
if ((f = fopen(path, "rb")) == NULL) {
- fatal("Cannot open file %s: %s", path, strerror(errno));
+ fatal(
+ "Cannot open file %s: %s", path, strerror(errno));
}
}
@@ -329,12 +330,14 @@ loadfile(const char *path, void **datap, size_t *lenp)
}
while (1) {
- total_read += fread(fdata + total_read, 1, allocation_size - total_read, f);
+ total_read += fread(
+ fdata + total_read, 1, allocation_size - total_read, f);
if (ferror(f)) {
if (errno == EINTR) {
continue;
}
- fatal("Read from %s failed: %s", path, strerror(errno));
+ fatal(
+ "Read from %s failed: %s", path, strerror(errno));
}
if (feof(f)) {
break;
@@ -344,7 +347,8 @@ loadfile(const char *path, void **datap, size_t *lenp)
fatal("Out of memory.");
}
allocation_size *= 2;
- if ((realloc_result = realloc(fdata, allocation_size + 1)) == NULL) {
+ if ((realloc_result = realloc(
+ fdata, allocation_size + 1)) == NULL) {
free(fdata);
fatal("Out of memory.");
}
@@ -355,8 +359,8 @@ loadfile(const char *path, void **datap, size_t *lenp)
fclose(f);
}
fdata[total_read] = '\0';
- *datap = fdata;
- *lenp = total_read;
+ *datap = fdata;
+ *lenp = total_read;
}
static void
@@ -657,7 +661,8 @@ sendrecv(nng_socket sock)
if ((recvtimeo >= 0) && (expire > recvtimeo)) {
expire = recvtimeo;
}
- rv = nng_setopt_ms(sock, NNG_OPT_RECVTIMEO, expire);
+ rv =
+ nng_socket_set_ms(sock, NNG_OPT_RECVTIMEO, expire);
if (rv != 0) {
fatal("Cannot set recv timeout: %s",
nng_strerror(rv));
@@ -887,7 +892,7 @@ main(int ac, char **av)
fatal("Option %s requires argument.", av[idx]);
break;
default:
- break;
+ break;
}
if (addrs == NULL) {
@@ -969,8 +974,8 @@ main(int ac, char **av)
}
break;
default:
- // Will be caught in next switch statement.
- break;
+ // Will be caught in next switch statement.
+ break;
}
switch (proto) {
@@ -1061,7 +1066,7 @@ main(int ac, char **av)
}
for (struct topic *t = topics; t != NULL; t = t->next) {
- rv = nng_setopt(
+ rv = nng_socket_set(
sock, NNG_OPT_SUB_SUBSCRIBE, t->val, strlen(t->val));
if (rv != 0) {
fatal("Unable to subscribe to topic %s: %s", t->val,
@@ -1070,16 +1075,18 @@ main(int ac, char **av)
}
if ((sendtimeo > 0) &&
- ((rv = nng_setopt_ms(sock, NNG_OPT_SENDTIMEO, sendtimeo)) != 0)) {
+ ((rv = nng_socket_set_ms(sock, NNG_OPT_SENDTIMEO, sendtimeo)) !=
+ 0)) {
fatal("Unable to set send timeout: %s", nng_strerror(rv));
}
if ((recvtimeo > 0) &&
- ((rv = nng_setopt_ms(sock, NNG_OPT_RECVTIMEO, recvtimeo)) != 0)) {
+ ((rv = nng_socket_set_ms(sock, NNG_OPT_RECVTIMEO, recvtimeo)) !=
+ 0)) {
fatal("Unable to set send timeout: %s", nng_strerror(rv));
}
if ((recvmaxsz >= 0) &&
- ((rv = nng_setopt_size(sock, NNG_OPT_RECVMAXSZ, recvmaxsz)) !=
+ ((rv = nng_socket_set_size(sock, NNG_OPT_RECVMAXSZ, recvmaxsz)) !=
0)) {
fatal("Unable to set max receive size: %s", nng_strerror(rv));
}
@@ -1107,7 +1114,7 @@ main(int ac, char **av)
nng_strerror(rv));
}
if (zthome != NULL) {
- rv = nng_dialer_setopt(d, NNG_OPT_ZT_HOME,
+ rv = nng_dialer_set(d, NNG_OPT_ZT_HOME,
zthome, strlen(zthome) + 1);
if ((rv != 0) && (rv != NNG_ENOTSUP)) {
fatal("Unable to set ZT home: %s",
@@ -1143,7 +1150,7 @@ main(int ac, char **av)
nng_strerror(rv));
}
if (zthome != NULL) {
- rv = nng_listener_setopt(l, NNG_OPT_ZT_HOME,
+ rv = nng_listener_set(l, NNG_OPT_ZT_HOME,
zthome, strlen(zthome) + 1);
if ((rv != 0) && (rv != NNG_ENOTSUP)) {
fatal("Unable to set ZT home: %s",