diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-15 17:47:54 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-15 17:47:54 -0800 |
| commit | 249932f3a208260f6b9c99d778b22d51cfabe87b (patch) | |
| tree | 4fd4826127e9c225d5232c39d4ae1db89b539689 /src/core/options.c | |
| parent | eb328da56c3fc7167b536dcb206df0abb0f4a9b9 (diff) | |
| download | nng-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.
Diffstat (limited to 'src/core/options.c')
| -rw-r--r-- | src/core/options.c | 34 |
1 files changed, 7 insertions, 27 deletions
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 |
