summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-04-14 15:09:27 -0700
committerGarrett D'Amore <garrett@damore.org>2018-04-14 20:18:02 -0700
commite3b8f31b044e4fe7d47439467fc1622266b5335c (patch)
treedeee625b2d01daa5558137f664c5b49d0a0e9e48
parent0467702bf1e5b4777c254d4116d8f8972b5a44a2 (diff)
downloadnng-e3b8f31b044e4fe7d47439467fc1622266b5335c.tar.gz
nng-e3b8f31b044e4fe7d47439467fc1622266b5335c.tar.bz2
nng-e3b8f31b044e4fe7d47439467fc1622266b5335c.zip
fixes #350 Incorrect compat error code from nn_setsockopt
-rw-r--r--src/compat/nanomsg/nn.c3
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/compat_options.c57
3 files changed, 63 insertions, 1 deletions
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. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+//
+// 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 <string.h>
+
+#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);
+ });
+ });
+})