diff options
Diffstat (limited to 'src')
32 files changed, 165 insertions, 217 deletions
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 }, }; |
