aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-02-14 14:50:04 -0800
committerGarrett D'Amore <garrett@damore.org>2018-02-14 18:28:36 -0800
commit45bc175ef9278c175d2fc3a0678b49b18e74c449 (patch)
treeb1838778ee898112f28b35178364068c6f48c9b4
parent8f93750ed2a6aaa1749eb689ddf119280f9aac7a (diff)
downloadnng-45bc175ef9278c175d2fc3a0678b49b18e74c449.tar.gz
nng-45bc175ef9278c175d2fc3a0678b49b18e74c449.tar.bz2
nng-45bc175ef9278c175d2fc3a0678b49b18e74c449.zip
fixes #234 Investigate enabling more verbose compiler warnings
We enabled verbose compiler warnings, and found a lot of issues. Some of these were even real bugs. As a bonus, we actually save some initialization steps in the compat layer, and avoid passing some variables we don't need.
-rw-r--r--CMakeLists.txt22
-rw-r--r--README.adoc1
-rw-r--r--demo/http_client/http_client.c26
-rw-r--r--perf/perf.c25
-rw-r--r--src/core/aio.c26
-rw-r--r--src/core/aio.h14
-rw-r--r--src/core/defs.h2
-rw-r--r--src/core/endpt.c1
-rw-r--r--src/core/url.c12
-rw-r--r--src/nng_compat.c134
-rw-r--r--src/platform/posix/posix_aio.h4
-rw-r--r--src/platform/posix/posix_epdesc.c8
-rw-r--r--src/platform/posix/posix_file.c3
-rw-r--r--src/platform/posix/posix_impl.h4
-rw-r--r--src/platform/posix/posix_ipc.c1
-rw-r--r--src/platform/posix/posix_pollq_poll.c5
-rw-r--r--src/platform/posix/posix_rand.c5
-rw-r--r--src/platform/posix/posix_sockaddr.c12
-rw-r--r--src/platform/posix/posix_thread.c7
-rw-r--r--src/platform/posix/posix_udp.c7
-rw-r--r--src/platform/windows/win_ipc.c1
-rw-r--r--src/platform/windows/win_tcp.c6
-rw-r--r--src/platform/windows/win_thread.c1
-rw-r--r--src/protocol/pipeline0/pull.c1
-rw-r--r--src/protocol/pipeline0/push.c1
-rw-r--r--src/protocol/pubsub0/pub.c1
-rw-r--r--src/protocol/pubsub0/sub.c1
-rw-r--r--src/protocol/survey0/survey.c5
-rw-r--r--src/supplemental/base64/base64.c2
-rw-r--r--src/supplemental/http/http_client.c4
-rw-r--r--src/supplemental/http/http_conn.c16
-rw-r--r--src/supplemental/http/http_server.c4
-rw-r--r--src/supplemental/tls/mbedtls/tls.c2
-rw-r--r--src/supplemental/websocket/websocket.c4
-rw-r--r--src/transport/ws/websocket.c2
-rw-r--r--src/transport/zerotier/zerotier.c86
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/base64.c8
-rw-r--r--tests/compat_bug777.c2
-rw-r--r--tests/compat_testutil.c229
-rw-r--r--tests/compat_testutil.h213
-rw-r--r--tests/convey.c24
-rw-r--r--tests/convey.h3
-rw-r--r--tests/convey_test.c4
-rw-r--r--tests/cplusplus_pair.cc4
-rw-r--r--tests/files.c3
-rw-r--r--tests/httpserver.c4
-rw-r--r--tests/idhash.c7
-rw-r--r--tests/scalability.c5
-rw-r--r--tests/sock.c20
-rw-r--r--tests/stubs.h7
-rw-r--r--tests/synch.c5
-rw-r--r--tests/tcp.c2
-rw-r--r--tests/tcp6.c4
-rw-r--r--tests/tls.c18
-rw-r--r--tests/trantest.h26
-rw-r--r--tests/ws.c2
-rw-r--r--tests/wss.c6
-rw-r--r--tests/wssfile.c19
-rw-r--r--tests/zt.c64
60 files changed, 556 insertions, 581 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70d7b29f..3a6ea442 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -240,24 +240,32 @@ endif()
# Platform checks.
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ set(NNG_WARN_FLAGS "-Wall -Wextra")
+elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ set(NNG_WARN_FLAGS "-Wall -Wextra")
+elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
+ set(NNG_WARN_FLAGS "-Wall -Wextra")
+endif()
+
if (NNG_ENABLE_COVERAGE)
# NB: This only works for GCC and Clang 3.0 and newer. If your stuff
# is older than that, you will need to find something newer. For
# correct reporting, we always turn off all optimizations.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- set(CMAKE_C_FLAGS "-g -O0 --coverage")
- set(CMAKE_CXX_FLAGS "-g -O0 --coverage")
+ set(NNG_COVERAGE_FLAGS "-g -O0 --coverage")
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
- set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
- set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
- elseif (CMAKE_COMPILER_ID STREQUAL "AppleClang")
- set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
- set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
+ set(NNG_COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
+ set(NNG_COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Unable to enable coverage for your compiler.")
endif()
endif()
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NNG_WARN_FLAGS} ${NNG_COVERAGE_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NNG_WARN_FLAGS} ${NNG_COVERAGE_FLAGS}")
+
find_package (Threads REQUIRED)
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
diff --git a/README.adoc b/README.adoc
index 8912d879..d1696801 100644
--- a/README.adoc
+++ b/README.adoc
@@ -4,6 +4,7 @@ image:https://img.shields.io/badge/license-MIT-blue.svg[MIT License]
image:https://img.shields.io/circleci/project/github/nanomsg/nng.svg?label=[Linux Status,link="https://circleci.com/gh/nanomsg/nng"]
image:https://img.shields.io/appveyor/ci/nanomsg/nng/master.svg?label=windows[Windows Status,link="https://ci.appveyor.com/project/nanomsg/nng"]
image:https://codecov.io/gh/nanomsg/nng/branch/master/graph/badge.svg?label=coverage[Coverage,link="https://codecov.io/gh/nanomsg/nng"]
+image:https://api.codacy.com/project/badge/Grade/f241cba192974787b66f7e4368777ebf["Codacy code quality", link="https://www.codacy.com/app/gdamore/nng?utm_source=github.com&utm_medium=referral&utm_content=nanomsg/nng&utm_campaign=Badge_Grade"]
This repository represents a work in progress rewrite of the SP protocol
library called "libnanomsg". This is pre-release, but at this point you
diff --git a/demo/http_client/http_client.c b/demo/http_client/http_client.c
index e3353ef8..522c1cd1 100644
--- a/demo/http_client/http_client.c
+++ b/demo/http_client/http_client.c
@@ -31,11 +31,11 @@
// % export CC="cc"
// % ${CC} ${CPPFLAGS} http_client.c -o http_client ${LDFLAGS}
// % ./http_client http://httpbin.org/ip
-//
+//
+#include <nng/nng.h>
#include <stdio.h>
#include <stdlib.h>
-#include <nng/nng.h>
void
fatal(int rv)
@@ -48,16 +48,16 @@ int
main(int argc, char **argv)
{
nng_http_client *client;
- nng_http_conn *conn;
- nng_url *url;
- nng_aio *aio;
- nng_http_req *req;
- nng_http_res *res;
- const char *hdr;
- int rv;
- int len;
- void *data;
- nng_iov iov;
+ nng_http_conn * conn;
+ nng_url * url;
+ nng_aio * aio;
+ nng_http_req * req;
+ nng_http_res * res;
+ const char * hdr;
+ int rv;
+ int len;
+ void * data;
+ nng_iov iov;
if (argc < 2) {
fprintf(stderr, "No URL supplied!\n");
@@ -116,12 +116,12 @@ main(int argc, char **argv)
exit(1);
}
+ len = atoi(hdr);
if (len == 0) {
return (0);
}
// Allocate a buffer to receive the body data.
- len = atoi(hdr);
data = malloc(len);
// Set up a single iov to point to the buffer.
diff --git a/perf/perf.c b/perf/perf.c
index 1d89fc61..84a1c66f 100644
--- a/perf/perf.c
+++ b/perf/perf.c
@@ -33,17 +33,18 @@
static void die(const char *, ...);
static int
-nng_pair_open(nng_socket *rv)
+nng_pair_open(nng_socket *arg)
{
+ (void) arg;
die("No pair protocol enabled in this build!");
return (NNG_ENOTSUP);
}
#endif // NNG_ENABLE_PAIR
-static void latency_client(const char *, int, int);
-static void latency_server(const char *, int, int);
-static void throughput_client(const char *, int, int);
-static void throughput_server(const char *, int, int);
+static void latency_client(const char *, size_t, int);
+static void latency_server(const char *, size_t, int);
+static void throughput_client(const char *, size_t, int);
+static void throughput_server(const char *, size_t, int);
static void do_remote_lat(int argc, char **argv);
static void do_local_lat(int argc, char **argv);
static void do_remote_thr(int argc, char **argv);
@@ -209,7 +210,7 @@ struct inproc_args {
int count;
int msgsize;
const char *addr;
- void (*func)(const char *, int, int);
+ void (*func)(const char *, size_t, int);
};
static void
@@ -275,7 +276,7 @@ do_inproc_thr(int argc, char **argv)
}
void
-latency_client(const char *addr, int msgsize, int trips)
+latency_client(const char *addr, size_t msgsize, int trips)
{
nng_socket s;
nng_msg * msg;
@@ -318,13 +319,13 @@ latency_client(const char *addr, int msgsize, int trips)
total = (float) ((end - start)) / 1000;
latency = ((float) ((total * 1000000)) / (trips * 2));
printf("total time: %.3f [s]\n", total);
- printf("message size: %d [B]\n", msgsize);
+ printf("message size: %d [B]\n", (int) msgsize);
printf("round trip count: %d\n", trips);
printf("average latency: %.3f [us]\n", latency);
}
void
-latency_server(const char *addr, int msgsize, int trips)
+latency_server(const char *addr, size_t msgsize, int trips)
{
nng_socket s;
nng_msg * msg;
@@ -366,7 +367,7 @@ latency_server(const char *addr, int msgsize, int trips)
// API somewhere.
void
-throughput_server(const char *addr, int msgsize, int count)
+throughput_server(const char *addr, size_t msgsize, int count)
{
nng_socket s;
nng_msg * msg;
@@ -413,14 +414,14 @@ throughput_server(const char *addr, int msgsize, int count)
msgpersec = (float) (count) / total;
mbps = (float) (msgpersec * 8 * msgsize) / (1024 * 1024);
printf("total time: %.3f [s]\n", total);
- printf("message size: %d [B]\n", msgsize);
+ printf("message size: %d [B]\n", (int) msgsize);
printf("message count: %d\n", count);
printf("throughput: %.f [msg/s]\n", msgpersec);
printf("throughput: %.3f [Mb/s]\n", mbps);
}
void
-throughput_client(const char *addr, int msgsize, int count)
+throughput_client(const char *addr, size_t msgsize, int count)
{
nng_socket s;
nng_msg * msg;
diff --git a/src/core/aio.c b/src/core/aio.c
index 1c293020..dd5edf0e 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -215,51 +215,51 @@ nni_aio_get_msg(nni_aio *aio)
}
void
-nni_aio_set_data(nni_aio *aio, int index, void *data)
+nni_aio_set_data(nni_aio *aio, unsigned index, void *data)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_user_data))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) {
aio->a_user_data[index] = data;
}
}
void *
-nni_aio_get_data(nni_aio *aio, int index)
+nni_aio_get_data(nni_aio *aio, unsigned index)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_user_data))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_user_data)) {
return (aio->a_user_data[index]);
}
return (NULL);
}
void
-nni_aio_set_input(nni_aio *aio, int index, void *data)
+nni_aio_set_input(nni_aio *aio, unsigned index, void *data)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_inputs))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_inputs)) {
aio->a_inputs[index] = data;
}
}
void *
-nni_aio_get_input(nni_aio *aio, int index)
+nni_aio_get_input(nni_aio *aio, unsigned index)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_inputs))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_inputs)) {
return (aio->a_inputs[index]);
}
return (NULL);
}
void
-nni_aio_set_output(nni_aio *aio, int index, void *data)
+nni_aio_set_output(nni_aio *aio, unsigned index, void *data)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_outputs))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_outputs)) {
aio->a_outputs[index] = data;
}
}
void *
-nni_aio_get_output(nni_aio *aio, int index)
+nni_aio_get_output(nni_aio *aio, unsigned index)
{
- if ((index >= 0) && (index < NNI_NUM_ELEMENTS(aio->a_outputs))) {
+ if (index < NNI_NUM_ELEMENTS(aio->a_outputs)) {
return (aio->a_outputs[index]);
}
return (NULL);
@@ -315,7 +315,7 @@ nni_aio_start(nni_aio *aio, nni_aio_cancelfn cancelfn, void *data)
aio->a_prov_cancel = cancelfn;
aio->a_prov_data = data;
aio->a_active = 1;
- for (int i = 0; i < NNI_NUM_ELEMENTS(aio->a_outputs); i++) {
+ for (unsigned i = 0; i < NNI_NUM_ELEMENTS(aio->a_outputs); i++) {
aio->a_outputs[i] = NULL;
}
diff --git a/src/core/aio.h b/src/core/aio.h
index 718eeb91..141248b8 100644
--- a/src/core/aio.h
+++ b/src/core/aio.h
@@ -52,28 +52,28 @@ extern void nni_aio_stop(nni_aio *);
// consumer, initiating the I/O. The intention is to be able to store
// additional data for use when the operation callback is executed.
// The index represents the "index" at which to store the data. A maximum
-// of 4 elements can be stored with the (index >= 0 && index < 4).
-extern void nni_aio_set_data(nni_aio *, int, void *);
+// of 4 elements can be stored with the (index < 4).
+extern void nni_aio_set_data(nni_aio *, unsigned, void *);
// nni_aio_get_data returns the user data that was previously stored
// with nni_aio_set_data.
-extern void *nni_aio_get_data(nni_aio *, int);
+extern void *nni_aio_get_data(nni_aio *, unsigned);
// nni_set_input sets input parameters on the AIO. The semantic details
// of this will be determined by the specific AIO operation. AIOs can
// carry up to 4 input parameters.
-extern void nni_aio_set_input(nni_aio *, int, void *);
+extern void nni_aio_set_input(nni_aio *, unsigned, void *);
// nni_get_input returns the input value stored by nni_aio_set_input.
-extern void *nni_aio_get_input(nni_aio *, int);
+extern void *nni_aio_get_input(nni_aio *, unsigned);
// nni_set_output sets output results on the AIO, allowing providers to
// return results to consumers. The semantic details are determined by
// the AIO operation. Up to 4 outputs can be carried on an AIO.
-extern void nni_aio_set_output(nni_aio *, int, void *);
+extern void nni_aio_set_output(nni_aio *, unsigned, void *);
// nni_get_output returns an output previously stored on the AIO.
-extern void *nni_aio_get_output(nni_aio *, int);
+extern void *nni_aio_get_output(nni_aio *, unsigned);
// XXX: These should be refactored in terms of generic inputs and outputs.
extern void nni_aio_set_msg(nni_aio *, nni_msg *);
diff --git a/src/core/defs.h b/src/core/defs.h
index dbbccf58..b08ce838 100644
--- a/src/core/defs.h
+++ b/src/core/defs.h
@@ -27,7 +27,7 @@
#endif
// Returns the size of an array in elements. (Convenience.)
-#define NNI_NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0]))
+#define NNI_NUM_ELEMENTS(x) ((unsigned) (sizeof(x) / sizeof((x)[0])))
// These types are common but have names shared with user space.
// Internal code should use these names when possible.
diff --git a/src/core/endpt.c b/src/core/endpt.c
index b7167ad7..4d3727bc 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -510,6 +510,7 @@ int
nni_ep_listen(nni_ep *ep, int flags)
{
int rv = 0;
+ NNI_ARG_UNUSED(flags);
nni_sock_reconntimes(ep->ep_sock, &ep->ep_inirtime, &ep->ep_maxrtime);
ep->ep_currtime = ep->ep_inirtime;
diff --git a/src/core/url.c b/src/core/url.c
index 2cdb43c2..93f1298e 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -127,8 +127,8 @@ url_canonify_uri(char **outp, const char *in)
out[dst++] = (char) c;
} else {
out[dst++] = '%';
- out[dst++] = toupper(out[src + 1]);
- out[dst++] = toupper(out[src + 2]);
+ out[dst++] = (char) toupper(out[src + 1]);
+ out[dst++] = (char) toupper(out[src + 2]);
}
src += 3;
continue;
@@ -152,7 +152,7 @@ url_canonify_uri(char **outp, const char *in)
if ((c == '?') || (c == '#')) {
skip = true;
}
- out[dst++] = c;
+ out[dst++] = (char) c;
src++;
}
out[dst] = 0;
@@ -186,7 +186,7 @@ url_canonify_uri(char **outp, const char *in)
if ((c == '?') || (c == '#')) {
skip = true;
}
- out[dst++] = c;
+ out[dst++] = (char) c;
src++;
}
}
@@ -285,7 +285,7 @@ nni_url_parse(nni_url **urlp, const char *raw)
goto error;
}
for (size_t i = 0; i < len; i++) {
- url->u_scheme[i] = tolower(s[i]);
+ url->u_scheme[i] = (char) tolower(s[i]);
}
url->u_scheme[len] = '\0';
@@ -335,7 +335,7 @@ nni_url_parse(nni_url **urlp, const char *raw)
// Copy the host portion, but make it lower case (hostnames are
// case insensitive).
for (size_t i = 0; i < len; i++) {
- url->u_host[i] = tolower(s[i]);
+ url->u_host[i] = (char) tolower(s[i]);
}
url->u_host[len] = '\0';
s += len;
diff --git a/src/nng_compat.c b/src/nng_compat.c
index 482834a1..35bacb6f 100644
--- a/src/nng_compat.c
+++ b/src/nng_compat.c
@@ -27,7 +27,7 @@
// This file supplies the legacy compatibility API. Applications should
// avoid using these if at all possible, and instead use the new style APIs.
-static struct {
+static const struct {
int nerr;
int perr;
} nn_errnos[] = {
@@ -216,6 +216,7 @@ int
nn_shutdown(int s, int ep)
{
int rv;
+ (void) s; // Unused
// Socket is wired into the endpoint... so passing a bad endpoint
// ID can result in affecting the wrong socket. But this requires
@@ -596,127 +597,38 @@ nn_sendmsg(int s, const struct nn_msghdr *mh, int flags)
}
// options which we convert -- most of the array is initialized at run time.
-static struct {
+static const struct {
int nnlevel;
int nnopt;
const char *opt;
} options[] = {
- // clang-format off
- { NN_SOL_SOCKET, NN_LINGER }, // review
- { NN_SOL_SOCKET, NN_SNDBUF },
- { NN_SOL_SOCKET, NN_RCVBUF } ,
- { NN_SOL_SOCKET, NN_RECONNECT_IVL },
- { NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX },
- { NN_SOL_SOCKET, NN_SNDFD },
- { NN_SOL_SOCKET, NN_RCVFD },
- { NN_SOL_SOCKET, NN_RCVMAXSIZE },
- { NN_SOL_SOCKET, NN_MAXTTL },
- { NN_SOL_SOCKET, NN_RCVTIMEO },
- { NN_SOL_SOCKET, NN_SNDTIMEO },
- { NN_SOL_SOCKET, NN_DOMAIN },
- { NN_SOL_SOCKET, NN_SOCKET_NAME },
- { NN_REQ, NN_REQ_RESEND_IVL },
- { NN_SUB, NN_SUB_SUBSCRIBE },
- { NN_SUB, NN_SUB_UNSUBSCRIBE },
- { NN_SURVEYOR, NN_SURVEYOR_DEADLINE },
+ { NN_SOL_SOCKET, NN_LINGER, NNG_OPT_LINGER }, // review
+ { NN_SOL_SOCKET, NN_SNDBUF, NNG_OPT_SENDBUF },
+ { NN_SOL_SOCKET, NN_RCVBUF, NNG_OPT_RECVBUF },
+ { NN_SOL_SOCKET, NN_RECONNECT_IVL, NNG_OPT_RECONNMINT },
+ { NN_SOL_SOCKET, NN_RECONNECT_IVL_MAX, NNG_OPT_RECONNMAXT },
+ { NN_SOL_SOCKET, NN_SNDFD, NNG_OPT_SENDFD },
+ { NN_SOL_SOCKET, NN_RCVFD, NNG_OPT_RECVFD },
+ { NN_SOL_SOCKET, NN_RCVMAXSIZE, NNG_OPT_RECVMAXSZ },
+ { NN_SOL_SOCKET, NN_MAXTTL, NNG_OPT_MAXTTL },
+ { NN_SOL_SOCKET, NN_RCVTIMEO, NNG_OPT_RECVTIMEO },
+ { NN_SOL_SOCKET, NN_SNDTIMEO, NNG_OPT_SENDTIMEO },
+ { NN_SOL_SOCKET, NN_DOMAIN, NNG_OPT_DOMAIN },
+ { NN_SOL_SOCKET, NN_SOCKET_NAME, NNG_OPT_SOCKNAME },
+ { NN_REQ, NN_REQ_RESEND_IVL, NNG_OPT_REQ_RESENDTIME },
+ { NN_SUB, NN_SUB_SUBSCRIBE, NNG_OPT_SUB_SUBSCRIBE },
+ { NN_SUB, NN_SUB_UNSUBSCRIBE, NNG_OPT_SUB_UNSUBSCRIBE },
+ { NN_SURVEYOR, NN_SURVEYOR_DEADLINE, NNG_OPT_SURVEYOR_SURVEYTIME },
// XXX: IPV4ONLY, SNDPRIO, RCVPRIO
- // clang-format on
};
-static void
-init_opts(void)
-{
- static int optsinited = 0;
- if (optsinited) {
- return;
- }
- for (int i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
- if (options[i].opt > 0) {
- continue;
- }
-#define SETOPT(n) options[i].opt = n;
-
- switch (options[i].nnlevel) {
- case NN_SOL_SOCKET:
- switch (options[i].nnopt) {
- case NN_LINGER:
- SETOPT(NNG_OPT_LINGER);
- break;
- case NN_SNDBUF:
- SETOPT(NNG_OPT_SENDBUF);
- break;
- case NN_RCVBUF:
- SETOPT(NNG_OPT_RECVBUF);
- break;
- case NN_RECONNECT_IVL:
- SETOPT(NNG_OPT_RECONNMINT);
- break;
- case NN_RECONNECT_IVL_MAX:
- SETOPT(NNG_OPT_RECONNMAXT);
- break;
- case NN_SNDFD:
- SETOPT(NNG_OPT_SENDFD);
- break;
- case NN_RCVFD:
- SETOPT(NNG_OPT_RECVFD);
- break;
- case NN_RCVMAXSIZE:
- SETOPT(NNG_OPT_RECVMAXSZ);
- break;
- case NN_MAXTTL:
- SETOPT(NNG_OPT_MAXTTL);
- break;
- case NN_RCVTIMEO:
- SETOPT(NNG_OPT_RECVTIMEO);
- break;
- case NN_SNDTIMEO:
- SETOPT(NNG_OPT_SENDTIMEO);
- break;
- case NN_SOCKET_NAME:
- SETOPT(NNG_OPT_SOCKNAME);
- break;
- case NN_DOMAIN:
- SETOPT(NNG_OPT_DOMAIN);
- break;
- }
- break;
- case NN_REQ:
- switch (options[i].nnopt) {
- case NN_REQ_RESEND_IVL:
- SETOPT(NNG_OPT_REQ_RESENDTIME);
- break;
- }
- break;
- case NN_SUB:
- switch (options[i].nnopt) {
- case NN_SUB_SUBSCRIBE:
- SETOPT(NNG_OPT_SUB_SUBSCRIBE);
- break;
- case NN_SUB_UNSUBSCRIBE:
- SETOPT(NNG_OPT_SUB_UNSUBSCRIBE);
- break;
- }
- case NN_SURVEYOR:
- switch (options[i].nnopt) {
- case NN_SURVEYOR_DEADLINE:
- SETOPT(NNG_OPT_SURVEYOR_SURVEYTIME);
- break;
- }
- break;
- }
- }
- optsinited = 1;
-}
-
int
nn_getsockopt(int s, int nnlevel, int nnopt, void *valp, size_t *szp)
{
const char *name = NULL;
int rv;
- init_opts();
-
- for (int i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
+ for (unsigned i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
if ((options[i].nnlevel == nnlevel) &&
(options[i].nnopt == nnopt)) {
name = options[i].opt;
@@ -743,9 +655,7 @@ nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz)
const char *name = NULL;
int rv;
- init_opts();
-
- for (int i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
+ for (unsigned i = 0; i < sizeof(options) / sizeof(options[0]); i++) {
if ((options[i].nnlevel == nnlevel) &&
(options[i].nnopt == nnopt)) {
name = options[i].opt;
diff --git a/src/platform/posix/posix_aio.h b/src/platform/posix/posix_aio.h
index ebc2eb99..71656391 100644
--- a/src/platform/posix/posix_aio.h
+++ b/src/platform/posix/posix_aio.h
@@ -33,8 +33,8 @@ extern int nni_posix_pipedesc_peername(nni_posix_pipedesc *, nni_sockaddr *);
extern int nni_posix_pipedesc_sockname(nni_posix_pipedesc *, nni_sockaddr *);
extern int nni_posix_epdesc_init(nni_posix_epdesc **);
-extern void nni_posix_epdesc_set_local(nni_posix_epdesc *, void *, int);
-extern void nni_posix_epdesc_set_remote(nni_posix_epdesc *, void *, int);
+extern void nni_posix_epdesc_set_local(nni_posix_epdesc *, void *, size_t);
+extern void nni_posix_epdesc_set_remote(nni_posix_epdesc *, void *, size_t);
extern void nni_posix_epdesc_fini(nni_posix_epdesc *);
extern void nni_posix_epdesc_close(nni_posix_epdesc *);
extern void nni_posix_epdesc_connect(nni_posix_epdesc *, nni_aio *);
diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c
index b5e65826..75383f4f 100644
--- a/src/platform/posix/posix_epdesc.c
+++ b/src/platform/posix/posix_epdesc.c
@@ -434,9 +434,9 @@ nni_posix_epdesc_init(nni_posix_epdesc **edp)
}
void
-nni_posix_epdesc_set_local(nni_posix_epdesc *ed, void *sa, int len)
+nni_posix_epdesc_set_local(nni_posix_epdesc *ed, void *sa, size_t len)
{
- if ((len < 0) || (len > sizeof(struct sockaddr_storage))) {
+ if ((len < 1) || (len > sizeof(struct sockaddr_storage))) {
return;
}
nni_mtx_lock(&ed->mtx);
@@ -446,9 +446,9 @@ nni_posix_epdesc_set_local(nni_posix_epdesc *ed, void *sa, int len)
}
void
-nni_posix_epdesc_set_remote(nni_posix_epdesc *ed, void *sa, int len)
+nni_posix_epdesc_set_remote(nni_posix_epdesc *ed, void *sa, size_t len)
{
- if ((len < 0) || (len > sizeof(struct sockaddr_storage))) {
+ if ((len < 1) || (len > sizeof(struct sockaddr_storage))) {
return;
}
nni_mtx_lock(&ed->mtx);
diff --git a/src/platform/posix/posix_file.c b/src/platform/posix/posix_file.c
index 23a714cd..7863fdee 100644
--- a/src/platform/posix/posix_file.c
+++ b/src/platform/posix/posix_file.c
@@ -96,7 +96,7 @@ nni_plat_file_get(const char *name, void **datap, size_t *lenp)
FILE * f;
struct stat st;
int rv = 0;
- int len;
+ size_t len;
void * data;
if ((f = fopen(name, "rb")) == NULL) {
@@ -146,7 +146,6 @@ int
nni_plat_file_type(const char *name, int *typep)
{
struct stat sbuf;
- int rv;
if (stat(name, &sbuf) != 0) {
return (nni_plat_errno(errno));
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index bf79a449..0b2a09f0 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -37,8 +37,8 @@
#ifdef NNG_PLATFORM_POSIX_SOCKADDR
#include <sys/socket.h>
-extern int nni_posix_sockaddr2nn(nni_sockaddr *, const void *);
-extern int nni_posix_nn2sockaddr(void *, const nni_sockaddr *);
+extern int nni_posix_sockaddr2nn(nni_sockaddr *, const void *);
+extern size_t nni_posix_nn2sockaddr(void *, const nni_sockaddr *);
#endif
#ifdef NNG_PLATFORM_POSIX_DEBUG
diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c
index fc312736..cd9da243 100644
--- a/src/platform/posix/posix_ipc.c
+++ b/src/platform/posix/posix_ipc.c
@@ -97,7 +97,6 @@ static int
nni_plat_ipc_remove_stale(const char *path)
{
int fd;
- int rv;
struct sockaddr_un sun;
size_t sz;
diff --git a/src/platform/posix/posix_pollq_poll.c b/src/platform/posix/posix_pollq_poll.c
index 80bb81ee..9081c0d9 100644
--- a/src/platform/posix/posix_pollq_poll.c
+++ b/src/platform/posix/posix_pollq_poll.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -353,6 +353,7 @@ static nni_posix_pollq nni_posix_global_pollq;
nni_posix_pollq *
nni_posix_pollq_get(int fd)
{
+ NNI_ARG_UNUSED(fd);
// This is the point where we could choose a pollq based on FD.
return (&nni_posix_global_pollq);
}
diff --git a/src/platform/posix/posix_rand.c b/src/platform/posix/posix_rand.c
index 3f353a74..2b704e2f 100644
--- a/src/platform/posix/posix_rand.c
+++ b/src/platform/posix/posix_rand.c
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// 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
@@ -42,7 +43,7 @@ void
nni_plat_seed_prng(void *buf, size_t bufsz)
{
struct nni_plat_prng_x x;
- int i;
+ size_t i;
memset(buf, 0, bufsz);
diff --git a/src/platform/posix/posix_sockaddr.c b/src/platform/posix/posix_sockaddr.c
index 25953f50..e9691d91 100644
--- a/src/platform/posix/posix_sockaddr.c
+++ b/src/platform/posix/posix_sockaddr.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <sys/un.h>
-int
+size_t
nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
{
struct sockaddr_in * sin;
@@ -34,7 +34,7 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
size_t sz;
if ((sa == NULL) || (na == NULL)) {
- return (-1);
+ return (0);
}
switch (na->s_un.s_family) {
case NNG_AF_INET:
@@ -65,12 +65,12 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na)
// Make sure that the path fits!
sz = sizeof(spath->sun_path);
if (nni_strlcpy(spath->sun_path, nspath->sa_path, sz) >= sz) {
- return (-1);
+ return (0);
}
spath->sun_family = PF_UNIX;
return (sizeof(*spath));
}
- return (-1);
+ return (0);
}
int
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index d3817d91..cca8165c 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -265,8 +265,6 @@ nni_plat_cv_until_fallback(nni_cv *cv, struct timespec *ts)
void
nni_plat_mtx_lock(nni_plat_mtx *mtx)
{
- int rv;
-
if (!mtx->fallback) {
nni_pthread_mutex_lock(&mtx->mtx);
@@ -328,7 +326,6 @@ nni_plat_cv_wake(nni_plat_cv *cv)
void
nni_plat_cv_wake1(nni_plat_cv *cv)
{
- int rv;
if (cv->fallback) {
nni_plat_cv_wake1_fallback(cv);
} else {
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c
index cd7b0561..cde58e7c 100644
--- a/src/platform/posix/posix_udp.c
+++ b/src/platform/posix/posix_udp.c
@@ -108,7 +108,6 @@ nni_posix_udp_dosend(nni_plat_udp *udp)
{
nni_aio * aio;
nni_list *q = &udp->udp_sendq;
- int x = 0;
// While we're able to send, do so.
while ((aio = nni_list_first(q)) != NULL) {
@@ -119,7 +118,7 @@ nni_posix_udp_dosend(nni_plat_udp *udp)
int cnt = 0;
len = nni_posix_nn2sockaddr(&ss, nni_aio_get_input(aio, 0));
- if (len < 0) {
+ if (len < 1) {
rv = NNG_EADDRINVAL;
} else {
struct msghdr hdr;
@@ -211,7 +210,7 @@ nni_plat_udp_open(nni_plat_udp **upp, nni_sockaddr *bindaddr)
struct sockaddr_storage sa;
int rv;
- if ((salen = nni_posix_nn2sockaddr(&sa, bindaddr)) < 0) {
+ if ((salen = nni_posix_nn2sockaddr(&sa, bindaddr)) < 1) {
return (NNG_EADDRINVAL);
}
@@ -261,8 +260,6 @@ nni_plat_udp_open(nni_plat_udp **upp, nni_sockaddr *bindaddr)
void
nni_plat_udp_close(nni_plat_udp *udp)
{
- nni_aio *aio;
-
// We're no longer interested in events.
nni_posix_pollq_remove(&udp->udp_pitem);
diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c
index afa1804e..f967a054 100644
--- a/src/platform/windows/win_ipc.c
+++ b/src/platform/windows/win_ipc.c
@@ -330,6 +330,7 @@ static int
nni_win_ipc_acc_start(nni_win_event *evt, nni_aio *aio)
{
nni_plat_ipc_ep *ep = evt->ptr;
+ NNI_ARG_UNUSED(aio);
if (!ConnectNamedPipe(ep->p, &evt->olpd)) {
int rv = GetLastError();
diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c
index 6d58d495..20f324b3 100644
--- a/src/platform/windows/win_tcp.c
+++ b/src/platform/windows/win_tcp.c
@@ -265,6 +265,8 @@ nni_plat_tcp_ep_init(nni_plat_tcp_ep **epp, const nni_sockaddr *lsa,
GUID guid2 = WSAID_ACCEPTEX;
GUID guid3 = WSAID_GETACCEPTEXSOCKADDRS;
+ NNI_ARG_UNUSED(mode);
+
if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) {
return (NNG_ENOMEM);
}
@@ -481,6 +483,8 @@ nni_win_tcp_acc_start(nni_win_event *evt, nni_aio *aio)
SOCKET acc_s;
DWORD cnt;
+ NNI_ARG_UNUSED(aio);
+
acc_s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (acc_s == INVALID_SOCKET) {
evt->status = nni_win_error(GetLastError());
@@ -576,6 +580,8 @@ nni_win_tcp_con_start(nni_win_event *evt, nni_aio *aio)
int rv;
int family;
+ NNI_ARG_UNUSED(aio);
+
if (ep->loclen > 0) {
family = ep->locaddr.ss_family;
} else {
diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c
index 971c7c37..a2ae72fe 100644
--- a/src/platform/windows/win_thread.c
+++ b/src/platform/windows/win_thread.c
@@ -100,6 +100,7 @@ nni_plat_cv_until(nni_plat_cv *cv, nni_time until)
void
nni_plat_cv_fini(nni_plat_cv *cv)
{
+ NNI_ARG_UNUSED(cv);
}
static unsigned int __stdcall nni_plat_thr_main(void *arg)
diff --git a/src/protocol/pipeline0/pull.c b/src/protocol/pipeline0/pull.c
index 44eb87f9..76c680c1 100644
--- a/src/protocol/pipeline0/pull.c
+++ b/src/protocol/pipeline0/pull.c
@@ -196,6 +196,7 @@ pull0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
static void
pull0_sock_send(void *arg, nni_aio *aio)
{
+ NNI_ARG_UNUSED(arg);
nni_aio_finish_error(aio, NNG_ENOTSUP);
}
diff --git a/src/protocol/pipeline0/push.c b/src/protocol/pipeline0/push.c
index 2829e2aa..1e6cf30e 100644
--- a/src/protocol/pipeline0/push.c
+++ b/src/protocol/pipeline0/push.c
@@ -221,6 +221,7 @@ push0_sock_send(void *arg, nni_aio *aio)
static void
push0_sock_recv(void *arg, nni_aio *aio)
{
+ NNI_ARG_UNUSED(arg);
nni_aio_finish_error(aio, NNG_ENOTSUP);
}
diff --git a/src/protocol/pubsub0/pub.c b/src/protocol/pubsub0/pub.c
index 285f40ca..33ecb5ba 100644
--- a/src/protocol/pubsub0/pub.c
+++ b/src/protocol/pubsub0/pub.c
@@ -290,6 +290,7 @@ pub0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
static void
pub0_sock_recv(void *arg, nni_aio *aio)
{
+ NNI_ARG_UNUSED(arg);
nni_aio_finish_error(aio, NNG_ENOTSUP);
}
diff --git a/src/protocol/pubsub0/sub.c b/src/protocol/pubsub0/sub.c
index a756e326..8803ab19 100644
--- a/src/protocol/pubsub0/sub.c
+++ b/src/protocol/pubsub0/sub.c
@@ -292,6 +292,7 @@ sub0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
static void
sub0_sock_send(void *arg, nni_aio *aio)
{
+ NNI_ARG_UNUSED(arg);
nni_aio_finish_error(aio, NNG_ENOTSUP);
}
diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c
index b8f10f0e..637ce2e2 100644
--- a/src/protocol/survey0/survey.c
+++ b/src/protocol/survey0/survey.c
@@ -474,6 +474,11 @@ static nni_proto_sock_option surv0_sock_options[] = {
.pso_getopt = surv0_sock_getopt_surveytime,
.pso_setopt = surv0_sock_setopt_surveytime,
},
+ {
+ .pso_name = NNG_OPT_MAXTTL,
+ .pso_getopt = surv0_sock_getopt_maxttl,
+ .pso_setopt = surv0_sock_setopt_maxttl,
+ },
// terminate list
{ NULL, NULL, NULL },
};
diff --git a/src/supplemental/base64/base64.c b/src/supplemental/base64/base64.c
index 2f6b4da2..afb50e1a 100644
--- a/src/supplemental/base64/base64.c
+++ b/src/supplemental/base64/base64.c
@@ -107,7 +107,7 @@ nni_base64_encode(const uint8_t *in, size_t in_len, char *out, size_t out_len)
uint32_t v;
uint8_t ch;
- const uint8_t ENCODEMAP[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ const uint8_t ENCODEMAP[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c
index 9058b6e2..5cab15c9 100644
--- a/src/supplemental/http/http_client.c
+++ b/src/supplemental/http/http_client.c
@@ -197,6 +197,8 @@ nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls)
}
return (0);
#else
+ NNI_ARG_UNUSED(c);
+ NNI_ARG_UNUSED(tls);
return (NNG_EINVAL);
#endif
}
@@ -214,6 +216,8 @@ nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp)
nni_mtx_unlock(&c->mtx);
return (0);
#else
+ NNI_ARG_UNUSED(c);
+ NNI_ARG_UNUSED(tlsp);
return (NNG_ENOTSUP);
#endif
}
diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c
index 726f3ea3..525bd6b5 100644
--- a/src/supplemental/http/http_conn.c
+++ b/src/supplemental/http/http_conn.c
@@ -200,10 +200,10 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio)
conn->rd_get = conn->rd_put = 0;
}
if (rv == NNG_EAGAIN) {
- nni_iov iov;
- iov.iov_buf = conn->rd_buf + conn->rd_put;
- iov.iov_len = conn->rd_bufsz - conn->rd_put;
- nni_aio_set_iov(conn->rd_aio, 1, &iov);
+ nni_iov iov1;
+ iov1.iov_buf = conn->rd_buf + conn->rd_put;
+ iov1.iov_len = conn->rd_bufsz - conn->rd_put;
+ nni_aio_set_iov(conn->rd_aio, 1, &iov1);
nni_aio_set_data(conn->rd_aio, 1, aio);
conn->rd(conn->sock, conn->rd_aio);
}
@@ -217,10 +217,10 @@ http_rd_buf(nni_http_conn *conn, nni_aio *aio)
conn->rd_get = conn->rd_put = 0;
}
if (rv == NNG_EAGAIN) {
- nni_iov iov;
- iov.iov_buf = conn->rd_buf + conn->rd_put;
- iov.iov_len = conn->rd_bufsz - conn->rd_put;
- nni_aio_set_iov(conn->rd_aio, 1, &iov);
+ nni_iov iov1;
+ iov1.iov_buf = conn->rd_buf + conn->rd_put;
+ iov1.iov_len = conn->rd_bufsz - conn->rd_put;
+ nni_aio_set_iov(conn->rd_aio, 1, &iov1);
nni_aio_set_data(conn->rd_aio, 1, aio);
conn->rd(conn->sock, conn->rd_aio);
}
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index 4c89708d..69774bd5 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -1494,6 +1494,8 @@ nni_http_server_set_tls(nni_http_server *s, nng_tls_config *tcfg)
}
return (0);
#else
+ NNI_ARG_UNUSED(s);
+ NNI_ARG_UNUSED(tcfg);
return (NNG_ENOTSUP);
#endif
}
@@ -1511,6 +1513,8 @@ nni_http_server_get_tls(nni_http_server *s, nng_tls_config **tp)
nni_mtx_unlock(&s->mtx);
return (0);
#else
+ NNI_ARG_UNUSED(s);
+ NNI_ARG_UNUSED(tp);
return (NNG_ENOTSUP);
#endif
}
diff --git a/src/supplemental/tls/mbedtls/tls.c b/src/supplemental/tls/mbedtls/tls.c
index ca6c716c..8d934d61 100644
--- a/src/supplemental/tls/mbedtls/tls.c
+++ b/src/supplemental/tls/mbedtls/tls.c
@@ -112,6 +112,8 @@ static void
nni_tls_dbg(void *ctx, int level, const char *file, int line, const char *s)
{
char buf[128];
+ NNI_ARG_UNUSED(ctx);
+ NNI_ARG_UNUSED(level);
snprintf(buf, sizeof(buf), "%s:%04d: %s", file, line, s);
nni_plat_println(buf);
}
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index 05a2c62c..cf3fa8dc 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -660,7 +660,7 @@ ws_send_control(nni_ws *ws, uint8_t op, uint8_t *buf, size_t len)
nni_mtx_lock(&ws->mtx);
if ((ws->closed) ||
- (ws_msg_init_control(&wm, ws, op, buf, sizeof(buf)) != 0)) {
+ (ws_msg_init_control(&wm, ws, op, buf, len) != 0)) {
nni_mtx_unlock(&ws->mtx);
return;
}
@@ -1768,7 +1768,7 @@ ws_conn_cb(void *arg)
}
for (int i = 0; i < 16; i++) {
- raw[i] = nni_random();
+ raw[i] = (uint8_t) nni_random();
}
nni_base64_encode(raw, 16, wskey, 24);
wskey[24] = '\0';
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index 9740cdde..07300a6d 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -244,6 +244,8 @@ ws_hook(void *arg, nni_http_req *req, nni_http_res *res)
{
ws_ep * ep = arg;
ws_hdr *h;
+ NNI_ARG_UNUSED(req);
+
// Eventually we'll want user customizable hooks.
// For now we just set the headers we want.
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index 6dddbb9a..f8ed4626 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -89,16 +89,16 @@ static const uint32_t zt_port_shift = 24;
// These are compile time tunables for now.
enum zt_tunables {
- zt_listenq = 128, // backlog queue length
- zt_listen_expire = 60000, // maximum time in backlog (msec)
- zt_rcv_bufsize = ZT_MAX_PHYSMTU, // max UDP recv
- zt_conn_attempts = 12, // connection attempts (default)
- zt_conn_interval = 5000, // between attempts (msec)
- zt_udp_sendq = 16, // outgoing UDP queue length
- zt_recvq = 2, // max pending recv (per pipe)
- zt_recv_stale = 1000, // frags older than are stale (msec)
- zt_ping_time = 60000, // keepalive time (msec)
- zt_ping_count = 5, // keepalive attempts
+ zt_listenq = 128, // backlog queue length
+ zt_listen_expire = 60000, // maximum time in backlog (msec)
+ zt_rcv_bufsize = 4096, // max UDP recv
+ zt_conn_attempts = 12, // connection attempts (default)
+ zt_conn_interval = 5000, // between attempts (msec)
+ zt_udp_sendq = 16, // outgoing UDP queue length
+ zt_recvq = 2, // max pending recv (per pipe)
+ zt_recv_stale = 1000, // frags older than are stale (msec)
+ zt_ping_time = 60000, // keepalive time (msec)
+ zt_ping_count = 5, // keepalive attempts
};
enum zt_op_codes {
@@ -174,7 +174,7 @@ struct zt_node {
uint8_t * zn_rcv6_buf;
nng_sockaddr zn_rcv6_addr;
nni_thr zn_bgthr;
- nni_time zn_bgtime;
+ uint64_t zn_bgtime;
nni_cv zn_bgcv;
nni_cv zn_snd6_cv;
};
@@ -290,18 +290,18 @@ static void zt_virtual_recv(ZT_Node *, void *, void *, uint64_t, void **,
uint64_t, uint64_t, unsigned int, unsigned int, const void *,
unsigned int);
-static int64_t
+static uint64_t
zt_now(void)
{
// We return msec
- return ((int64_t) nni_clock());
+ return ((uint64_t) nni_clock());
}
static void
zt_bgthr(void *arg)
{
zt_node *ztn = arg;
- int64_t now;
+ uint64_t now;
nni_mtx_lock(&zt_lk);
for (;;) {
@@ -312,7 +312,7 @@ zt_bgthr(void *arg)
}
if (now < ztn->zn_bgtime) {
- nni_cv_until(&ztn->zn_bgcv, ztn->zn_bgtime);
+ nni_cv_until(&ztn->zn_bgcv, (nni_time) ztn->zn_bgtime);
continue;
}
@@ -325,7 +325,7 @@ zt_bgthr(void *arg)
}
static void
-zt_node_resched(zt_node *ztn, int64_t msec)
+zt_node_resched(zt_node *ztn, uint64_t msec)
{
if (msec > ztn->zn_bgtime && ztn->zn_bgtime != 0) {
return;
@@ -342,7 +342,7 @@ zt_node_rcv4_cb(void *arg)
struct sockaddr_storage sa;
struct sockaddr_in * sin;
nng_sockaddr_in * nsin;
- int64_t now;
+ uint64_t now;
if (nni_aio_result(aio) != 0) {
// Outside of memory exhaustion, we can't really think
@@ -394,7 +394,7 @@ zt_node_rcv6_cb(void *arg)
struct sockaddr_storage sa;
struct sockaddr_in6 * sin6;
struct nng_sockaddr_in6 *nsin6;
- int64_t now;
+ uint64_t now;
if (nni_aio_result(aio) != 0) {
// Outside of memory exhaustion, we can't really think
@@ -412,7 +412,7 @@ zt_node_rcv6_cb(void *arg)
memcpy(&sin6->sin6_addr, nsin6->sa_addr, 16);
nni_mtx_lock(&zt_lk);
- now = zt_now(); // msec
+ now = (uint64_t) zt_now(); // msec
// We are not going to perform any validation of the data; we
// just pass this straight into the ZeroTier core.
@@ -560,7 +560,7 @@ zt_send(zt_node *ztn, uint64_t nwid, uint8_t op, uint64_t raddr,
{
uint64_t srcmac = zt_node_to_mac(laddr >> 24, nwid);
uint64_t dstmac = zt_node_to_mac(raddr >> 24, nwid);
- int64_t now = zt_now();
+ uint64_t now = zt_now();
NNI_ASSERT(len >= zt_size_headers);
data[zt_offset_op] = op;
@@ -746,10 +746,9 @@ zt_ep_recv_conn_req(zt_ep *ep, uint64_t raddr, const uint8_t *data, size_t len)
}
static void
-zt_ep_recv_error(zt_ep *ep, uint64_t raddr, const uint8_t *data, size_t len)
+zt_ep_recv_error(zt_ep *ep, const uint8_t *data, size_t len)
{
- nni_aio *aio;
- int code;
+ int code;
// Most of the time we don't care about errors. The exception here
// is that when we have an outstanding CON_REQ, we would like to
@@ -803,7 +802,7 @@ zt_ep_virtual_recv(
zt_ep_recv_conn_ack(ep, raddr, data, len);
return;
case zt_op_error:
- zt_ep_recv_error(ep, raddr, data, len);
+ zt_ep_recv_error(ep, data, len);
return;
default:
zt_send_err(ep->ze_ztn, ep->ze_nwid, raddr, ep->ze_laddr,
@@ -832,7 +831,6 @@ zt_pipe_close_err(zt_pipe *p, int err, uint8_t code, const char *msg)
static void
zt_pipe_recv_data(zt_pipe *p, const uint8_t *data, size_t len)
{
- nni_aio * aio;
uint16_t msgid;
uint16_t fragno;
uint16_t nfrags;
@@ -982,6 +980,9 @@ static void
zt_pipe_recv_disc_req(zt_pipe *p, const uint8_t *data, size_t len)
{
nni_aio *aio;
+ NNI_ARG_UNUSED(data);
+ NNI_ARG_UNUSED(len);
+
// NB: lock held already.
// Don't bother to check the length, going to disconnect anyway.
if ((aio = p->zp_user_rxaio) != NULL) {
@@ -995,6 +996,8 @@ static void
zt_pipe_recv_error(zt_pipe *p, const uint8_t *data, size_t len)
{
nni_aio *aio;
+ NNI_ARG_UNUSED(data);
+ NNI_ARG_UNUSED(len);
// Perhaps we should log an error message, but at the end of
// the day, the details are just not that interesting.
@@ -1044,7 +1047,6 @@ zt_virtual_recv(ZT_Node *node, void *userptr, void *thr, uint64_t nwid,
zt_node * ztn = userptr;
uint8_t op;
const uint8_t *data = payload;
- uint16_t proto;
uint16_t version;
uint32_t rport;
uint32_t lport;
@@ -1053,6 +1055,10 @@ zt_virtual_recv(ZT_Node *node, void *userptr, void *thr, uint64_t nwid,
uint64_t raddr;
uint64_t laddr;
+ NNI_ARG_UNUSED(node);
+ NNI_ARG_UNUSED(thr);
+ NNI_ARG_UNUSED(netptr);
+
if ((ethertype != zt_ethertype) || (len < zt_size_headers) ||
(data[zt_offset_flags] != 0) || (data[zt_offset_zero1] != 0) ||
(data[zt_offset_zero2] != 0)) {
@@ -1062,6 +1068,9 @@ zt_virtual_recv(ZT_Node *node, void *userptr, void *thr, uint64_t nwid,
if (version != zt_version) {
return;
}
+ if (vlanid != 0) { // for now we only use vlan 0.
+ return;
+ }
op = data[zt_offset_op];
@@ -1138,6 +1147,7 @@ zt_event_cb(ZT_Node *node, void *userptr, void *thr, enum ZT_Event event,
NNI_ARG_UNUSED(node);
NNI_ARG_UNUSED(userptr);
NNI_ARG_UNUSED(thr);
+ NNI_ARG_UNUSED(payload);
switch (event) {
case ZT_EVENT_ONLINE: // Connected to the virtual net.
@@ -1180,6 +1190,8 @@ zt_state_put(ZT_Node *node, void *userptr, void *thr,
const char *template;
char fname[32];
+ NNI_ARG_UNUSED(node);
+ NNI_ARG_UNUSED(thr);
NNI_ARG_UNUSED(objid); // only use global files
if ((objtype > ZT_STATE_OBJECT_NETWORK_CONFIG) ||
@@ -1237,6 +1249,8 @@ zt_state_get(ZT_Node *node, void *userptr, void *thr,
size_t sz;
void * buf;
+ NNI_ARG_UNUSED(node);
+ NNI_ARG_UNUSED(thr);
NNI_ARG_UNUSED(objid); // we only use global files
if ((objtype > ZT_STATE_OBJECT_NETWORK_CONFIG) ||
@@ -1313,6 +1327,7 @@ zt_wire_packet_send(ZT_Node *node, void *userptr, void *thr, int64_t socket,
zt_send_hdr * hdr;
nni_iov iov;
+ NNI_ARG_UNUSED(node);
NNI_ARG_UNUSED(thr);
NNI_ARG_UNUSED(socket);
NNI_ARG_UNUSED(ttl);
@@ -1530,7 +1545,6 @@ zt_node_find(zt_ep *ep)
{
zt_node * ztn;
int rv;
- nng_sockaddr sa;
ZT_VirtualNetworkConfig *cf;
NNI_LIST_FOREACH (&zt_nodes, ztn) {
@@ -1990,8 +2004,8 @@ zt_pipe_ping_cb(void *arg)
p->zp_ping_active = 0;
if (p->zp_closed || aio == NULL || (p->zp_ping_count == 0) ||
- (p->zp_ping_time == NNI_TIME_NEVER) ||
- (p->zp_ping_time == NNI_TIME_ZERO)) {
+ (p->zp_ping_time == NNG_DURATION_INFINITE) ||
+ (p->zp_ping_time == NNG_DURATION_ZERO)) {
nni_mtx_unlock(&zt_lk);
return;
}
@@ -2031,8 +2045,9 @@ zt_pipe_start(void *arg, nni_aio *aio)
nni_mtx_lock(&zt_lk);
p->zp_ping_active = 0;
// send a gratuitous ping, and start the ping interval timer.
- if ((p->zp_ping_count > 0) && (p->zp_ping_time != NNI_TIME_ZERO) &&
- (p->zp_ping_time != NNI_TIME_NEVER) && (p->zp_ping_aio != NULL)) {
+ if ((p->zp_ping_count > 0) && (p->zp_ping_time != NNG_DURATION_ZERO) &&
+ (p->zp_ping_time != NNG_DURATION_INFINITE) &&
+ (p->zp_ping_aio != NULL)) {
p->zp_ping_try = 0;
nni_aio_set_timeout(aio, p->zp_ping_time);
if (nni_aio_start(p->zp_ping_aio, zt_pipe_cancel_ping, p) ==
@@ -2104,13 +2119,9 @@ static int
zt_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
{
zt_ep * ep;
- size_t sz;
- uint64_t nwid;
uint64_t node;
uint64_t port;
- int n;
int rv;
- char c;
const char *h;
if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) {
@@ -2514,7 +2525,7 @@ zt_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp)
static int
zt_ep_setopt_home(void *arg, const void *data, size_t sz)
{
- int len;
+ size_t len;
int rv;
zt_ep *ep = arg;
@@ -2690,6 +2701,9 @@ static nni_tran_pipe_option zt_pipe_options[] = {
{ NNG_OPT_LOCADDR, zt_pipe_getopt_locaddr },
{ NNG_OPT_REMADDR, zt_pipe_getopt_remaddr },
{ NNG_OPT_ZT_MTU, zt_pipe_getopt_mtu },
+ { NNG_OPT_ZT_NWID, zt_pipe_get_nwid },
+ { NNG_OPT_ZT_NODE, zt_pipe_get_node },
+ { NNG_OPT_RECVMAXSZ, zt_pipe_get_recvmaxsz },
// terminate list
{ NULL, NULL },
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 358e9d00..6ae41ffe 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -77,7 +77,7 @@ if (NNG_TESTS)
macro (add_nng_compat_test NAME TIMEOUT)
list (APPEND all_tests ${NAME})
- add_executable (${NAME} ${NAME}.c)
+ add_executable (${NAME} ${NAME}.c compat_testutil.c)
target_link_libraries (${NAME} ${PROJECT_NAME}_static)
target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB)
diff --git a/tests/base64.c b/tests/base64.c
index 714bd4b2..eac84df2 100644
--- a/tests/base64.c
+++ b/tests/base64.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -45,7 +45,7 @@ TestMain("Base64 Verification", {
for (i = 0; (dec = cases[i].decoded) != NULL; i++) {
rv = nni_base64_encode(dec, strlen(dec), buf, 1024);
So(rv >= 0);
- So(rv == strlen(cases[i].encoded));
+ So(rv == (int) strlen(cases[i].encoded));
buf[rv] = 0;
So(strcmp(buf, cases[i].encoded) == 0);
}
@@ -61,7 +61,7 @@ TestMain("Base64 Verification", {
rv = nni_base64_decode(
enc, strlen(enc), (void *) buf, 1024);
So(rv >= 0);
- So(rv == strlen(cases[i].decoded));
+ So(rv == (int) strlen(cases[i].decoded));
buf[rv] = 0;
So(strcmp(buf, cases[i].decoded) == 0);
}
diff --git a/tests/compat_bug777.c b/tests/compat_bug777.c
index 686b8181..ba4a8b02 100644
--- a/tests/compat_bug777.c
+++ b/tests/compat_bug777.c
@@ -25,7 +25,7 @@
#include "nng.h"
#include "compat_testutil.h"
-int main (int argc, const char *argv[])
+int main (NN_UNUSED int argc, NN_UNUSED const char *argv[])
{
int sb;
int sc1;
diff --git a/tests/compat_testutil.c b/tests/compat_testutil.c
new file mode 100644
index 00000000..e24f31fc
--- /dev/null
+++ b/tests/compat_testutil.c
@@ -0,0 +1,229 @@
+/*
+ Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved.
+ Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
+ Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+ Copyright 2018 Capitar IT Group BV <info@capitar.com>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+// Note: This file started life in nanomsg. We have copied it, and adjusted
+// it for validating the compatibility features of nanomsg. As much as
+// possible we want to run tests from the nanomsg test suite unmodified.
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "compat_testutil.h"
+#include "nng_compat.h"
+
+int test_socket_impl(char *file, int line, int family, int protocol);
+int test_connect_impl(char *file, int line, int sock, char *address);
+int test_bind_impl(char *file, int line, int sock, char *address);
+void test_close_impl(char *file, int line, int sock);
+void test_send_impl(char *file, int line, int sock, char *data);
+void test_recv_impl(char *file, int line, int sock, char *data);
+void test_drop_impl(char *file, int line, int sock, int err);
+int test_setsockopt_impl(char *file, int line, int sock, int level, int option,
+ const void *optval, size_t optlen);
+
+int
+test_socket_impl(char *file, int line, int family, int protocol)
+{
+ int sock;
+
+ sock = nn_socket(family, protocol);
+ if (sock == -1) {
+ fprintf(stderr, "Failed create socket: %s [%d] (%s:%d)\n",
+ nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+
+ return (sock);
+}
+
+int
+test_connect_impl(char *file, int line, int sock, char *address)
+{
+ int rc;
+
+ rc = nn_connect(sock, address);
+ if (rc < 0) {
+ fprintf(stderr, "Failed connect to \"%s\": %s [%d] (%s:%d)\n",
+ address, nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+ return (rc);
+}
+
+int
+test_bind_impl(char *file, int line, int sock, char *address)
+{
+ int rc;
+
+ rc = nn_bind(sock, address);
+ if (rc < 0) {
+ fprintf(stderr, "Failed bind to \"%s\": %s [%d] (%s:%d)\n",
+ address, nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+ return (rc);
+}
+
+int
+test_setsockopt_impl(char *file, int line, int sock, int level, int option,
+ const void *optval, size_t optlen)
+{
+ int rc;
+
+ rc = nn_setsockopt(sock, level, option, optval, optlen);
+ if (rc < 0) {
+ fprintf(stderr, "Failed set option \"%d\": %s [%d] (%s:%d)\n",
+ option, nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+ return rc;
+}
+
+void
+test_close_impl(char *file, int line, int sock)
+{
+ int rc;
+
+ rc = nn_close(sock);
+ if ((rc != 0) && (errno != EBADF && errno != ETERM)) {
+ fprintf(stderr, "Failed to close socket: %s [%d] (%s:%d)\n",
+ nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+}
+
+void
+test_send_impl(char *file, int line, int sock, char *data)
+{
+ size_t data_len;
+ int rc;
+
+ data_len = strlen(data);
+
+ rc = nn_send(sock, data, data_len, 0);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to send: %s [%d] (%s:%d)\n",
+ nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+ if (rc != (int) data_len) {
+ fprintf(stderr,
+ "Data to send is truncated: %d != %d (%s:%d)\n", rc,
+ (int) data_len, file, line);
+ nn_err_abort();
+ }
+}
+
+void
+test_recv_impl(char *file, int line, int sock, char *data)
+{
+ size_t data_len;
+ int rc;
+ char * buf;
+
+ data_len = strlen(data);
+ /* We allocate plus one byte so that we are sure that message received
+ has correct length and not truncated */
+ buf = malloc(data_len + 1);
+ alloc_assert(buf);
+
+ rc = nn_recv(sock, buf, data_len + 1, 0);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to recv: %s [%d] (%s:%d)\n",
+ nn_err_strerror(errno), (int) errno, file, line);
+ nn_err_abort();
+ }
+ if (rc != (int) data_len) {
+ fprintf(stderr,
+ "Received data has wrong length: %d != %d (%s:%d)\n", rc,
+ (int) data_len, file, line);
+ nn_err_abort();
+ }
+ if (memcmp(data, buf, data_len) != 0) {
+ /* We don't print the data as it may have binary garbage */
+ fprintf(
+ stderr, "Received data is wrong (%s:%d)\n", file, line);
+ nn_err_abort();
+ }
+
+ free(buf);
+}
+
+void
+test_drop_impl(char *file, int line, int sock, int err)
+{
+ int rc;
+ char buf[1024];
+
+ rc = nn_recv(sock, buf, sizeof(buf), 0);
+ if (rc < 0 && err != errno) {
+ fprintf(stderr,
+ "Got wrong err to recv: %s [%d != %d] (%s:%d)\n",
+ nn_err_strerror(errno), (int) errno, err, file, line);
+ nn_err_abort();
+ } else if (rc >= 0) {
+ fprintf(stderr, "Did not drop message: [%d bytes] (%s:%d)\n",
+ rc, file, line);
+ nn_err_abort();
+ }
+}
+
+int
+get_test_port(int argc, const char *argv[])
+{
+ return (atoi(argc < 2 ? "5555" : argv[1]));
+}
+
+void
+test_addr_from(char *out, const char *proto, const char *ip, int port)
+{
+ sprintf(out, "%s://%s:%d", proto, ip, port);
+}
+
+extern int nng_thread_create(void **, void (*)(void *), void *);
+
+int
+nn_thread_init(struct nn_thread *thr, void (*func)(void *), void *arg)
+{
+ return (nng_thread_create(&thr->thr, func, arg));
+}
+
+extern void nng_thread_destroy(void *);
+
+void
+nn_thread_term(struct nn_thread *thr)
+{
+ nng_thread_destroy(thr->thr);
+}
+
+extern void nng_msleep(int32_t);
+
+void
+nn_sleep(int ms)
+{
+ nng_msleep(ms);
+} \ No newline at end of file
diff --git a/tests/compat_testutil.h b/tests/compat_testutil.h
index 00e7cb0b..745f5621 100644
--- a/tests/compat_testutil.h
+++ b/tests/compat_testutil.h
@@ -2,6 +2,8 @@
Copyright (c) 2013 Insollo Entertainment, LLC. All rights reserved.
Copyright 2017 Garrett D'Amore <garrett@damore.org>
Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
+ Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+ Copyright 2018 Capitar IT Group BV <info@capitar.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -40,15 +42,25 @@
#define errno_assert assert
#define alloc_assert(x) assert(x != NULL)
-static int test_socket_impl(char *file, int line, int family, int protocol);
-static int test_connect_impl(char *file, int line, int sock, char *address);
-static int test_bind_impl(char *file, int line, int sock, char *address);
-static void test_close_impl(char *file, int line, int sock);
-static void test_send_impl(char *file, int line, int sock, char *data);
-static void test_recv_impl(char *file, int line, int sock, char *data);
-static void test_drop_impl(char *file, int line, int sock, int err);
-static int test_setsockopt_impl(char *file, int line, int sock, int level,
- int option, const void *optval, size_t optlen);
+#if defined __GNUC__ || defined __llvm__ || defined __clang__
+#define NN_UNUSED __attribute__((unused))
+#else
+#define NN_UNUSED
+#endif
+
+extern int test_socket_impl(char *file, int line, int family, int protocol);
+extern int test_connect_impl(char *file, int line, int sock, char *address);
+extern int test_bind_impl(char *file, int line, int sock, char *address);
+extern void test_close_impl(char *file, int line, int sock);
+extern void test_send_impl(char *file, int line, int sock, char *data);
+extern void test_recv_impl(char *file, int line, int sock, char *data);
+extern void test_drop_impl(char *file, int line, int sock, int err);
+extern int test_setsockopt_impl(char *file, int line, int sock, int level,
+ int option, const void *optval, size_t optlen);
+extern int get_test_port(int argc, const char *argv[]);
+extern void test_addr_from(char *out, const char *proto, const char *ip,
+ int port);
+extern void nn_sleep(int);
#define test_socket(f, p) test_socket_impl(__FILE__, __LINE__, (f), (p))
#define test_connect(s, a) test_connect_impl(__FILE__, __LINE__, (s), (a))
@@ -60,190 +72,11 @@ static int test_setsockopt_impl(char *file, int line, int sock, int level,
#define test_setsockopt(s, l, o, v, z) \
test_setsockopt_impl(__FILE__, __LINE__, (s), (l), (o), (v), (z))
-#define NN_UNUSED
-
-static int
-test_socket_impl(char *file, int line, int family, int protocol)
-{
- int sock;
-
- sock = nn_socket(family, protocol);
- if (sock == -1) {
- fprintf(stderr, "Failed create socket: %s [%d] (%s:%d)\n",
- nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
-
- return sock;
-}
-
-static int
-test_connect_impl(char *file, int line, int sock, char *address)
-{
- int rc;
-
- rc = nn_connect(sock, address);
- if (rc < 0) {
- fprintf(stderr, "Failed connect to \"%s\": %s [%d] (%s:%d)\n",
- address, nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
- return rc;
-}
-
-static int
-test_bind_impl(char *file, int line, int sock, char *address)
-{
- int rc;
-
- rc = nn_bind(sock, address);
- if (rc < 0) {
- fprintf(stderr, "Failed bind to \"%s\": %s [%d] (%s:%d)\n",
- address, nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
- return rc;
-}
-
-static int
-test_setsockopt_impl(char *file, int line, int sock, int level, int option,
- const void *optval, size_t optlen)
-{
- int rc;
-
- rc = nn_setsockopt(sock, level, option, optval, optlen);
- if (rc < 0) {
- fprintf(stderr, "Failed set option \"%d\": %s [%d] (%s:%d)\n",
- option, nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
- return rc;
-}
-
-static void
-test_close_impl(char *file, int line, int sock)
-{
- int rc;
-
- rc = nn_close(sock);
- if ((rc != 0) && (errno != EBADF && errno != ETERM)) {
- fprintf(stderr, "Failed to close socket: %s [%d] (%s:%d)\n",
- nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
-}
-
-static void
-test_send_impl(char *file, int line, int sock, char *data)
-{
- size_t data_len;
- int rc;
-
- data_len = strlen(data);
-
- rc = nn_send(sock, data, data_len, 0);
- if (rc < 0) {
- fprintf(stderr, "Failed to send: %s [%d] (%s:%d)\n",
- nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
- if (rc != (int) data_len) {
- fprintf(stderr,
- "Data to send is truncated: %d != %d (%s:%d)\n", rc,
- (int) data_len, file, line);
- nn_err_abort();
- }
-}
-
-static void
-test_recv_impl(char *file, int line, int sock, char *data)
-{
- size_t data_len;
- int rc;
- char * buf;
-
- data_len = strlen(data);
- /* We allocate plus one byte so that we are sure that message received
- has correct length and not truncated */
- buf = malloc(data_len + 1);
- alloc_assert(buf);
-
- rc = nn_recv(sock, buf, data_len + 1, 0);
- if (rc < 0) {
- fprintf(stderr, "Failed to recv: %s [%d] (%s:%d)\n",
- nn_err_strerror(errno), (int) errno, file, line);
- nn_err_abort();
- }
- if (rc != (int) data_len) {
- fprintf(stderr,
- "Received data has wrong length: %d != %d (%s:%d)\n", rc,
- (int) data_len, file, line);
- nn_err_abort();
- }
- if (memcmp(data, buf, data_len) != 0) {
- /* We don't print the data as it may have binary garbage */
- fprintf(
- stderr, "Received data is wrong (%s:%d)\n", file, line);
- nn_err_abort();
- }
-
- free(buf);
-}
-
-static void
-test_drop_impl(char *file, int line, int sock, int err)
-{
- int rc;
- char buf[1024];
-
- rc = nn_recv(sock, buf, sizeof(buf), 0);
- if (rc < 0 && err != errno) {
- fprintf(stderr,
- "Got wrong err to recv: %s [%d != %d] (%s:%d)\n",
- nn_err_strerror(errno), (int) errno, err, file, line);
- nn_err_abort();
- } else if (rc >= 0) {
- fprintf(stderr, "Did not drop message: [%d bytes] (%s:%d)\n",
- rc, file, line);
- nn_err_abort();
- }
-}
-
-static int
-get_test_port(int argc, const char *argv[])
-{
- return atoi(argc < 2 ? "5555" : argv[1]);
-}
-
-static void
-test_addr_from(char *out, const char *proto, const char *ip, int port)
-{
- sprintf(out, "%s://%s:%d", proto, ip, port);
-}
-
-void
-nn_sleep(int32_t msec)
-{
- void nng_msleep(int32_t);
- nng_msleep(msec);
-}
-
struct nn_thread {
void *thr;
};
-int
-nn_thread_init(struct nn_thread *thr, void (*func)(void *), void *arg)
-{
- int nng_thread_create(void **, void (*)(void *), void *);
- return (nng_thread_create(&thr->thr, func, arg));
-}
-
-void
-nn_thread_term(struct nn_thread *thr)
-{
- void nng_thread_destroy(void *);
- nng_thread_destroy(thr->thr);
-}
+extern int nn_thread_init(struct nn_thread *, void (*)(void *), void *);
+extern void nn_thread_term(struct nn_thread *);
#endif // TESTUTIL_H_INCLUDED
diff --git a/tests/convey.c b/tests/convey.c
index 5e87779f..2dd4c323 100644
--- a/tests/convey.c
+++ b/tests/convey.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Garrett D'Amore <garrett@damore.org>
+ * Copyright 2018 Garrett D'Amore <garrett@damore.org>
*
* This software is supplied under the terms of the MIT License, a
* copy of which should be located in the distribution where this
@@ -96,7 +96,6 @@ static HANDLE convey_console;
#endif
#define CONVEY_EXIT_OK 0
-#define CONVEY_EXIT_USAGE 1
#define CONVEY_EXIT_FAIL 2
#define CONVEY_EXIT_FATAL 3
#define CONVEY_EXIT_NOMEM 4
@@ -507,19 +506,18 @@ convey_start_timer(struct convey_timer *pc)
pc->timer_base = pcnt.QuadPart;
pc->timer_rate = pfreq.QuadPart;
#elif defined(CLOCK_MONOTONIC) && !defined(CONVEY_USE_GETTIMEOFDAY)
- uint64_t usecs;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- pc->timer_base = ts.tv_sec * 1000000000;
- pc->timer_base += ts.tv_nsec;
+ pc->timer_base = (uint64_t) ts.tv_sec * 1000000000;
+ pc->timer_base += (uint64_t) ts.tv_nsec;
pc->timer_rate = 1000000000;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
- pc->timer_base = tv.tv_sec * 1000000;
- pc->timer_base += tv.tv_usec;
+ pc->timer_base = (uint64_t) tv.tv_sec * 1000000;
+ pc->timer_base += (uint64_t) tv.tv_usec;
pc->timer_rate = 1000000;
#endif
pc->timer_running = 1;
@@ -542,7 +540,7 @@ convey_stop_timer(struct convey_timer *pc)
clock_gettime(CLOCK_MONOTONIC, &ts);
ns = (ts.tv_sec * 1000000000);
- ns += ts.tv_nsec;
+ ns += (uint64_t) ts.tv_nsec;
pc->timer_count += (ns - pc->timer_base);
#else
uint64_t us;
@@ -639,7 +637,7 @@ convey_tls_get(void)
#else
-pthread_key_t convey_tls_key;
+static pthread_key_t convey_tls_key;
static int
convey_tls_init(void)
@@ -851,8 +849,6 @@ conveyPrintf(const char *file, int line, const char *fmt, ...)
va_end(ap);
}
-extern int conveyMainImpl(void);
-
static void
convey_init_term(void)
{
@@ -885,9 +881,9 @@ convey_init_term(void)
// Values probably don't matter, just need to be
// different!
convey_nocolor = "\033[0m";
- convey_green = "\033[32m";
- convey_yellow = "\033[33m";
- convey_red = "\033[31m";
+ convey_green = "\033[32m";
+ convey_yellow = "\033[33m";
+ convey_red = "\033[31m";
}
term = getenv("TERM");
#endif
diff --git a/tests/convey.h b/tests/convey.h
index 9d9be0fa..299e0611 100644
--- a/tests/convey.h
+++ b/tests/convey.h
@@ -71,8 +71,8 @@
* framework creates a context automatically for each convey scope.
*/
typedef struct {
- jmp_buf cs_jmp;
void * cs_data;
+ jmp_buf cs_jmp;
} conveyScope;
/* These functions are not for use by tests -- they are used internally. */
@@ -90,6 +90,7 @@ extern void conveySkip(const char *, int, const char *, ...);
extern void conveyFail(const char *, int, const char *, ...);
extern void conveyError(const char *, int, const char *, ...);
extern void conveyPrintf(const char *, int, const char *, ...);
+extern int conveyMainImpl(void);
/*
* conveyRun is a helper macro not to be called directly by user
diff --git a/tests/convey_test.c b/tests/convey_test.c
index 0970e664..53ea2954 100644
--- a/tests/convey_test.c
+++ b/tests/convey_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Garrett D'Amore <garrett@damore.org>
+ * Copyright 2018 Garrett D'Amore <garrett@damore.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
@@ -84,7 +84,9 @@ Main({
Test("Skipping works", {
int skipped = 0;
SkipConvey("ConveySkip works.", { So(skipped = 0); });
+ So(skipped == 0);
Convey("Assertion skipping works.", { SkipSo(skipped == 1); });
+ So(skipped == 0);
});
Test("Reset", {
diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc
index 11ce1912..02f57eaa 100644
--- a/tests/cplusplus_pair.cc
+++ b/tests/cplusplus_pair.cc
@@ -26,6 +26,8 @@ main(int argc, char **argv)
int rv;
size_t sz;
char buf[8];
+ (void) argc;
+ (void) argv;
if ((rv = nng_pair1_open(&s1)) != 0) {
throw nng_strerror(rv);
@@ -68,6 +70,8 @@ main(int argc, char **argv)
std::cout << "Pass." << std::endl;
#else
+ (void) argc;
+ (void) argv;
std::cout << "Skipped (protocol unconfigured)." << std::endl;
#endif
diff --git a/tests/files.c b/tests/files.c
index 3b21ac65..9983d7d3 100644
--- a/tests/files.c
+++ b/tests/files.c
@@ -181,9 +181,10 @@ TestMain("Platform File Support", {
});
Convey("Directory walk works", {
- struct walkarg wa = { 0 };
+ struct walkarg wa;
int rv;
+ memset(&wa, 0, sizeof(wa));
rv = nni_file_walk(mydir, walker, &wa, 0);
So(rv == 0);
So(wa.a == 1);
diff --git a/tests/httpserver.c b/tests/httpserver.c
index bbdd8423..e3d7ab25 100644
--- a/tests/httpserver.c
+++ b/tests/httpserver.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Garrett D'Amore <garrett@damore.org>
+// 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
@@ -247,7 +247,7 @@ TestMain("HTTP Server", {
ptr = nng_http_res_get_header(
res, "Content-Length");
So(ptr != NULL);
- So(atoi(ptr) == strlen(doc1));
+ So(atoi(ptr) == (int) strlen(doc1));
iov.iov_len = strlen(doc1);
iov.iov_buf = chunk;
diff --git a/tests/idhash.c b/tests/idhash.c
index e4183e98..32751334 100644
--- a/tests/idhash.c
+++ b/tests/idhash.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -145,13 +145,12 @@ Main({
nni_idhash *h;
int expect[5];
uint64_t id;
- int i;
So(nni_idhash_init(&h) == 0);
Reset({ nni_idhash_fini(h); });
nni_idhash_set_limits(h, 10, 13, 10);
So(1);
Convey("We can fill the table", {
- for (i = 0; i < 4; i++) {
+ for (uint64_t i = 0; i < 4; i++) {
So(nni_idhash_alloc(
h, &id, &expect[i]) == 0);
So(id == (i + 10));
diff --git a/tests/scalability.c b/tests/scalability.c
index d869d5fc..9695c53c 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -27,6 +27,7 @@ void
serve(void *arg)
{
nng_msg *msg;
+ (void) arg; // unused
for (;;) {
msg = NULL;
diff --git a/tests/sock.c b/tests/sock.c
index d3af414a..404e160b 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -75,8 +75,6 @@ TestMain("Socket Operations", {
Convey("We can set and get options", {
nng_duration to = 1234;
- int64_t v = 0;
- size_t sz;
So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0);
@@ -99,7 +97,7 @@ TestMain("Socket Operations", {
s1, NNG_OPT_SOCKNAME, name, &sz) == 0);
So(sz > 0 && sz < 64);
So(sz == nni_strnlen(name, 64) + 1);
- So(atoi(name) == (unsigned) s1);
+ So(atoi(name) == (int) s1);
So(nng_setopt(
s1, NNG_OPT_SOCKNAME, "hello", 6) == 0);
@@ -164,6 +162,8 @@ TestMain("Socket Operations", {
Convey("We can apply options before endpoint", {
nng_listener l;
char addr[NNG_MAXADDRLEN];
+ size_t sz;
+
trantest_next_address(
addr, "ipc:///tmp/lopt_%u");
@@ -194,8 +194,8 @@ TestMain("Socket Operations", {
});
});
Convey("Short size is not copied", {
- sz = 0;
- to = 0;
+ size_t sz = 0;
+ to = 0;
So(nng_getopt(
s1, NNG_OPT_SENDTIMEO, &to, &sz) == 0);
So(sz == sizeof(to));
@@ -212,7 +212,7 @@ TestMain("Socket Operations", {
});
Convey("Correct size is copied", {
- sz = sizeof(to);
+ size_t sz = sizeof(to);
So(nng_getopt(
s1, NNG_OPT_SENDTIMEO, &to, &sz) == 0);
So(sz == sizeof(to));
@@ -220,8 +220,8 @@ TestMain("Socket Operations", {
});
Convey("Short size buf is not copied", {
- int l = 5;
- sz = 0;
+ int l = 5;
+ size_t sz = 0;
So(nng_getopt(s1, NNG_OPT_RECVBUF, &l, &sz) ==
0);
So(sz == sizeof(l));
@@ -241,8 +241,8 @@ TestMain("Socket Operations", {
});
Convey("Short timeout fails", {
- to = 0;
- sz = sizeof(to) - 1;
+ size_t sz = sizeof(to) - 1;
+ to = 0;
So(nng_setopt(s1, NNG_OPT_RECVTIMEO, &to,
sz) == NNG_EINVAL);
So(nng_setopt(s1, NNG_OPT_RECONNMINT, &to,
diff --git a/tests/stubs.h b/tests/stubs.h
index 0641c970..99f92f7d 100644
--- a/tests/stubs.h
+++ b/tests/stubs.h
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// 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
@@ -40,13 +41,15 @@ getms(void)
return (0);
}
tv.tv_sec -= epoch;
- return (((uint64_t)(tv.tv_sec) * 1000) + (tv.tv_usec / 1000));
+ return (
+ ((uint64_t)(tv.tv_sec) * 1000) + (uint64_t)(tv.tv_usec / 1000));
#endif
}
int
nosocket(nng_socket *s)
{
+ (void) s; // not used
ConveySkip("Protocol unconfigured");
return (NNG_ENOTSUP);
}
diff --git a/tests/synch.c b/tests/synch.c
index b1d0d66a..c9de3deb 100644
--- a/tests/synch.c
+++ b/tests/synch.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// 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
@@ -158,7 +158,6 @@ test_sync_fallback(void)
nni_plat_sync_fallback = 1;
Convey("Mutexes work", {
nni_mtx mx;
- int rv;
nni_mtx_init(&mx);
diff --git a/tests/tcp.c b/tests/tcp.c
index 5860eb03..ef572c9d 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -21,7 +21,7 @@
#endif
static int
-check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props_v4(nng_msg *msg)
{
nng_pipe p;
size_t z;
diff --git a/tests/tcp6.c b/tests/tcp6.c
index a3e55d18..c00f00f2 100644
--- a/tests/tcp6.c
+++ b/tests/tcp6.c
@@ -37,7 +37,7 @@ has_v6(void)
}
static int
-check_props_v6(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props_v6(nng_msg *msg)
{
nng_pipe p;
size_t z;
@@ -68,8 +68,6 @@ check_props_v6(nng_msg *msg, nng_listener l, nng_dialer d)
So(ra.s_un.s_family == NNG_AF_INET6);
So(ra.s_un.s_in6.sa_port != 0);
So(memcmp(ra.s_un.s_in6.sa_addr, loopback, 16) == 0);
-
- So(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0);
});
Convey("Malformed TCPv6 addresses do not panic", {
diff --git a/tests/tls.c b/tests/tls.c
index c977d57f..02a89f97 100644
--- a/tests/tls.c
+++ b/tests/tls.c
@@ -103,7 +103,7 @@ static const char key[] =
"-----END RSA PRIVATE KEY-----\n";
static int
-check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props_v4(nng_msg *msg)
{
nng_pipe p;
size_t z;
@@ -132,7 +132,7 @@ check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
}
static int
-init_dialer_tls(trantest *tt, nng_dialer d)
+init_dialer_tls(nng_dialer d)
{
nng_tls_config *cfg;
int rv;
@@ -157,7 +157,7 @@ out:
}
static int
-init_listener_tls(trantest *tt, nng_listener l)
+init_listener_tls(nng_listener l)
{
nng_tls_config *cfg;
int rv;
@@ -177,7 +177,7 @@ out:
}
static int
-init_dialer_tls_file(trantest *tt, nng_dialer d)
+init_dialer_tls_file(nng_dialer d)
{
int rv;
char *tmpdir;
@@ -205,7 +205,7 @@ init_dialer_tls_file(trantest *tt, nng_dialer d)
}
static int
-init_listener_tls_file(trantest *tt, nng_listener l)
+init_listener_tls_file(nng_listener l)
{
int rv;
char *tmpdir;
@@ -368,7 +368,7 @@ TestMain("TLS Transport", {
});
trantest_next_address(addr, "tls+tcp://*:%u");
So(nng_listener_create(&l, s1, addr) == 0);
- So(init_listener_tls_file(NULL, l) == 0);
+ So(init_listener_tls_file(l) == 0);
So(nng_listener_start(l, 0) == 0);
nng_msleep(100);
@@ -376,7 +376,7 @@ TestMain("TLS Transport", {
trantest_prev_address(addr, "tls+tcp://127.0.0.1:%u");
So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0);
So(nng_dialer_create(&d, s2, addr) == 0);
- So(init_dialer_tls_file(NULL, d) == 0);
+ So(init_dialer_tls_file(d) == 0);
So(nng_dialer_setopt_int(d, NNG_OPT_TLS_AUTH_MODE,
NNG_TLS_AUTH_MODE_OPTIONAL) == 0);
So(nng_dialer_setopt_string(
@@ -413,14 +413,14 @@ TestMain("TLS Transport", {
});
trantest_next_address(addr, "tls+tcp://*:%u");
So(nng_listener_create(&l, s1, addr) == 0);
- So(init_listener_tls_file(NULL, l) == 0);
+ So(init_listener_tls_file(l) == 0);
So(nng_listener_start(l, 0) == 0);
nng_msleep(100);
// reset port back one
trantest_prev_address(addr, "tls+tcp://localhost:%u");
So(nng_dialer_create(&d, s2, addr) == 0);
- So(init_dialer_tls_file(NULL, d) == 0);
+ So(init_dialer_tls_file(d) == 0);
So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0);
So(nng_dialer_start(d, 0) == 0);
nng_msleep(100);
diff --git a/tests/trantest.h b/tests/trantest.h
index 771b761e..13445eaf 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -20,7 +20,7 @@
// we can avoid rewriting the same tests for each new transport. Include this
// file once in your test code. The test framework uses the REQ/REP protocol
// for messaging.
-typedef int (*trantest_proptest_t)(nng_msg *, nng_listener, nng_dialer);
+typedef int (*trantest_proptest_t)(nng_msg *);
typedef struct trantest trantest;
@@ -32,14 +32,26 @@ struct trantest {
nni_tran * tran;
int (*init)(struct trantest *);
void (*fini)(struct trantest *);
- int (*dialer_init)(struct trantest *, nng_dialer);
- int (*listener_init)(struct trantest *, nng_listener);
- int (*proptest)(nng_msg *, nng_listener, nng_dialer);
+ int (*dialer_init)(nng_dialer);
+ int (*listener_init)(nng_listener);
+ int (*proptest)(nng_msg *);
void *private; // transport specific private data
};
unsigned trantest_port = 0;
+extern int notransport(void);
+extern void trantest_checktran(const char *url);
+extern void trantest_next_address(char *out, const char *template);
+extern void trantest_prev_address(char *out, const char *template);
+extern void trantest_init(trantest *tt, const char *addr);
+extern int trantest_dial(trantest *tt, nng_dialer *dp);
+extern int trantest_listen(trantest *tt, nng_listener *lp);
+extern void trantest_scheme(trantest *tt);
+extern void trantest_test(trantest *tt);
+extern void trantest_test_extended(const char *addr, trantest_proptest_t f);
+extern void trantest_test_all(const char *addr);
+
#ifndef NNG_TRANSPORT_ZEROTIER
#define nng_zt_register notransport
#endif
@@ -166,7 +178,7 @@ trantest_dial(trantest *tt, nng_dialer *dp)
return (rv);
}
if (tt->dialer_init != NULL) {
- if ((rv = tt->dialer_init(tt, d)) != 0) {
+ if ((rv = tt->dialer_init(d)) != 0) {
nng_dialer_close(d);
return (rv);
}
@@ -191,7 +203,7 @@ trantest_listen(trantest *tt, nng_listener *lp)
return (rv);
}
if (tt->listener_init != NULL) {
- if ((rv = tt->listener_init(tt, l)) != 0) {
+ if ((rv = tt->listener_init(l)) != 0) {
nng_listener_close(l);
return (rv);
}
@@ -393,7 +405,7 @@ trantest_check_properties(trantest *tt, trantest_proptest_t f)
So(recv != NULL);
So(nng_msg_len(recv) == 5);
So(strcmp(nng_msg_body(recv), "props") == 0);
- rv = f(recv, l, d);
+ rv = f(recv);
nng_msg_free(recv);
So(rv == 0);
});
diff --git a/tests/ws.c b/tests/ws.c
index 0527337e..4a8bd7a7 100644
--- a/tests/ws.c
+++ b/tests/ws.c
@@ -22,7 +22,7 @@
#endif
static int
-check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props_v4(nng_msg *msg)
{
nng_pipe p;
size_t z;
diff --git a/tests/wss.c b/tests/wss.c
index aee982c8..ebb2e310 100644
--- a/tests/wss.c
+++ b/tests/wss.c
@@ -130,7 +130,7 @@ validloopback(nng_sockaddr *sa)
}
static int
-check_props(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props(nng_msg *msg)
{
nng_pipe p;
size_t z;
@@ -180,7 +180,7 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
}
static int
-init_dialer_wss(trantest *tt, nng_dialer d)
+init_dialer_wss(nng_dialer d)
{
nng_tls_config *cfg;
int rv;
@@ -206,7 +206,7 @@ out:
}
static int
-init_listener_wss(trantest *tt, nng_listener l)
+init_listener_wss(nng_listener l)
{
nng_tls_config *cfg;
int rv;
diff --git a/tests/wssfile.c b/tests/wssfile.c
index 73bc1cdb..82c519e1 100644
--- a/tests/wssfile.c
+++ b/tests/wssfile.c
@@ -130,7 +130,7 @@ validloopback(nng_sockaddr *sa)
}
static int
-check_props(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props(nng_msg *msg)
{
nng_pipe p;
size_t z;
@@ -138,7 +138,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
nng_sockaddr ra;
char * buf;
size_t len;
- int v;
p = nng_msg_get_pipe(msg);
So(p > 0);
@@ -181,7 +180,7 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
}
static int
-init_dialer_wss_file(trantest *tt, nng_dialer d)
+init_dialer_wss_file(nng_dialer d)
{
int rv;
char *tmpdir;
@@ -209,7 +208,7 @@ init_dialer_wss_file(trantest *tt, nng_dialer d)
}
static int
-init_listener_wss_file(trantest *tt, nng_listener l)
+init_listener_wss_file(nng_listener l)
{
int rv;
char *tmpdir;
@@ -267,8 +266,6 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
nng_socket s1;
nng_socket s2;
nng_listener l;
- char * buf;
- size_t sz;
char addr[NNG_MAXADDRLEN];
So(nng_pair_open(&s1) == 0);
@@ -279,7 +276,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
});
trantest_next_address(addr, "wss://:%u/test");
So(nng_listener_create(&l, s1, addr) == 0);
- So(init_listener_wss_file(NULL, l) == 0);
+ So(init_listener_wss_file(l) == 0);
So(nng_listener_start(l, 0) == 0);
nng_msleep(100);
@@ -309,7 +306,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
});
trantest_next_address(addr, "wss://:%u/test");
So(nng_listener_create(&l, s1, addr) == 0);
- So(init_listener_wss_file(NULL, l) == 0);
+ So(init_listener_wss_file(l) == 0);
So(nng_listener_start(l, 0) == 0);
nng_msleep(100);
@@ -317,7 +314,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
trantest_prev_address(addr, "wss://127.0.0.1:%u/test");
So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0);
So(nng_dialer_create(&d, s2, addr) == 0);
- So(init_dialer_wss_file(NULL, d) == 0);
+ So(init_dialer_wss_file(d) == 0);
So(nng_dialer_setopt_int(d, NNG_OPT_TLS_AUTH_MODE,
NNG_TLS_AUTH_MODE_OPTIONAL) == 0);
So(nng_dialer_setopt_string(
@@ -361,14 +358,14 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", {
});
trantest_next_address(addr, "wss://:%u/test");
So(nng_listener_create(&l, s1, addr) == 0);
- So(init_listener_wss_file(NULL, l) == 0);
+ So(init_listener_wss_file(l) == 0);
So(nng_listener_start(l, 0) == 0);
nng_msleep(100);
// reset port back one
trantest_prev_address(addr, "wss://localhost:%u/test");
So(nng_dialer_create(&d, s2, addr) == 0);
- So(init_dialer_wss_file(NULL, d) == 0);
+ So(init_dialer_wss_file(d) == 0);
So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0);
So(nng_dialer_start(d, 0) == 0);
nng_msleep(100);
diff --git a/tests/zt.c b/tests/zt.c
index 02e098fa..c8b7563c 100644
--- a/tests/zt.c
+++ b/tests/zt.c
@@ -44,7 +44,7 @@ mkdir(const char *path, int mode)
#endif
static int
-check_props(nng_msg *msg, nng_listener l, nng_dialer d)
+check_props(nng_msg *msg)
{
nng_sockaddr la, ra;
nng_pipe p;
@@ -78,8 +78,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
So(nng_pipe_getopt(p, NNG_OPT_ZT_NODE, &mynode, &z) == 0);
So(mynode != 0);
So(ra.s_un.s_zt.sa_nodeid == mynode);
-
- So(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0);
});
Convey("NWID property works", {
@@ -89,16 +87,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
nwid = 0;
So(nng_pipe_getopt(p, NNG_OPT_ZT_NWID, &nwid, &z) == 0);
So(nwid = 0xa09acf02337b057bull);
-
- z = sizeof(nwid);
- nwid = 0;
- So(nng_dialer_getopt(d, NNG_OPT_ZT_NWID, &nwid, &z) == 0);
- So(nwid = 0xa09acf02337b057bull);
-
- z = sizeof(nwid);
- nwid = 0;
- So(nng_listener_getopt(l, NNG_OPT_ZT_NWID, &nwid, &z) == 0);
- So(nwid = 0xa09acf02337b057bull);
});
Convey("Network status property works", {
@@ -107,23 +95,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
s = 0;
So(nng_pipe_getopt(p, NNG_OPT_ZT_NETWORK_STATUS, &s, &z) == 0);
So(s == nng_zt_network_status_ok);
-
- z = sizeof(s);
- s = 0;
- So(nng_dialer_getopt(d, NNG_OPT_ZT_NETWORK_STATUS, &s, &z) ==
- 0);
- So(s == nng_zt_network_status_ok);
-
- z = sizeof(s);
- s = 0;
- So(nng_listener_getopt(l, NNG_OPT_ZT_NETWORK_STATUS, &s, &z) ==
- 0);
- So(s == nng_zt_network_status_ok);
-
- So(nng_dialer_setopt(d, NNG_OPT_ZT_NETWORK_STATUS, &s, z) ==
- NNG_EREADONLY);
- So(nng_listener_setopt(l, NNG_OPT_ZT_NETWORK_STATUS, &s, z) ==
- NNG_EREADONLY);
});
Convey("Ping properties work", {
@@ -138,20 +109,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
t = 0;
So(nng_pipe_getopt_ms(p, NNG_OPT_ZT_PING_TIME, &t) == 0);
So(t > 1000 && t < 3600000); // 1 sec - 1 hour
-
- c = 0;
- So(nng_dialer_getopt_int(d, NNG_OPT_ZT_PING_COUNT, &c) == 0);
- So(c > 0 && c < 10); // actually 5...
-
- t = 0;
- So(nng_dialer_getopt_ms(d, NNG_OPT_ZT_PING_TIME, &t) == 0);
- So(t > 1000 && t < 3600000); // 1 sec - 1 hour
-
- So(nng_dialer_setopt_int(d, NNG_OPT_ZT_PING_COUNT, 20) == 0);
- So(nng_dialer_setopt_int(d, NNG_OPT_ZT_PING_COUNT, 20) == 0);
- So(nng_dialer_setopt_ms(d, NNG_OPT_ZT_PING_TIME, 2000) == 0);
- So(nng_listener_setopt_int(l, NNG_OPT_ZT_PING_COUNT, 0) == 0);
- So(nng_listener_setopt_ms(l, NNG_OPT_ZT_PING_TIME, 0) == 0);
});
Convey("Home property works", {
@@ -159,20 +116,6 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
z = sizeof(v);
So(nng_pipe_getopt(p, NNG_OPT_ZT_HOME, v, &z) == 0);
So(strlen(v) < sizeof(v));
-
- z = sizeof(v);
- So(nng_dialer_getopt(d, NNG_OPT_ZT_HOME, v, &z) == 0);
- So(strlen(v) < sizeof(v));
-
- z = sizeof(v);
- So(nng_listener_getopt(l, NNG_OPT_ZT_HOME, v, &z) == 0);
- So(strlen(v) < sizeof(v));
-
- z = strlen("/tmp/bogus") + 1;
- So(nng_dialer_setopt(d, NNG_OPT_ZT_HOME, "/tmp/bogus", z) ==
- NNG_ESTATE);
- So(nng_listener_setopt(l, NNG_OPT_ZT_HOME, "/tmp/bogus", z) ==
- NNG_ESTATE);
});
Convey("MTU property works", {
@@ -187,11 +130,10 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d)
Convey("Network name property works", {
char name[NNG_MAXADDRLEN];
size_t namesz;
- int status;
namesz = sizeof(name);
- So(nng_listener_getopt(
- l, NNG_OPT_ZT_NETWORK_NAME, name, &namesz) == 0);
+ So(nng_pipe_getopt(
+ p, NNG_OPT_ZT_NETWORK_NAME, name, &namesz) == 0);
So(strcmp(name, "nng_test_open") == 0);
});