From e3b8f31b044e4fe7d47439467fc1622266b5335c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 14 Apr 2018 15:09:27 -0700 Subject: fixes #350 Incorrect compat error code from nn_setsockopt --- src/compat/nanomsg/nn.c | 3 ++- tests/CMakeLists.txt | 4 ++++ tests/compat_options.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/compat_options.c diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c index 5c6bbd7d..cbb88a27 100644 --- a/src/compat/nanomsg/nn.c +++ b/src/compat/nanomsg/nn.c @@ -835,7 +835,8 @@ nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz) } if (name == NULL) { - return (ENOPROTOOPT); + errno = ENOPROTOOPT; + return (-1); } if ((rv = nng_setopt((nng_socket) s, name, valp, sz)) != 0) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 46236423..d6283dbc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -187,5 +187,9 @@ add_nng_compat_test(compat_survey 5) add_nng_compat_test(compat_reqttl 5) add_nng_compat_test(compat_shutdown 5) +# These are special tests for compat mode, not inherited from the +# legacy libnanomsg suite. +add_nng_test(compat_options 5 NNG_PROTO_REP0) + # c++ tests add_nng_cpp_test(cplusplus_pair 5) diff --git a/tests/compat_options.c b/tests/compat_options.c new file mode 100644 index 00000000..1cf147f5 --- /dev/null +++ b/tests/compat_options.c @@ -0,0 +1,57 @@ +// +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV +// +// 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. +// + +#include "convey.h" + +#include "compat/nanomsg/nn.h" + +#include "compat_testutil.h" + +#include + +#define SECONDS(x) ((x) *1000) + +TestMain("Compatible Options", { + + atexit(nn_term); + + Convey("Given a compat NN_REP socket", { + int repsock; + + So((repsock = nn_socket(AF_SP, NN_REP)) != -1); + Reset({ nn_close(repsock); }); + + Convey("NN_DOMAIN works", { + int dom = 4321; + size_t sz; + sz = sizeof(dom); + So(nn_getsockopt(repsock, NN_SOL_SOCKET, NN_DOMAIN, + &dom, &sz) == 0); + So(sz == sizeof(dom)); + So(dom == AF_SP); + + So(nn_setsockopt(repsock, NN_SOL_SOCKET, NN_DOMAIN, + &dom, sz) == -1); + So(nn_errno() == ENOPROTOOPT); + }); + Convey("NN_LINGER has no effect", { + int l = 4321; + size_t sz; + sz = sizeof(l); + So(nn_setsockopt(repsock, NN_SOL_SOCKET, NN_LINGER, &l, + sz) == 0); + + So(nn_getsockopt(repsock, NN_SOL_SOCKET, NN_LINGER, &l, + &sz) == 0); + So(sz == sizeof(l)); + So(l == 0); + }); + }); +}) -- cgit v1.2.3-70-g09d2