diff options
31 files changed, 108 insertions, 86 deletions
diff --git a/perf/CMakeLists.txt b/perf/CMakeLists.txt index c5fc1c3a..babf17e8 100644 --- a/perf/CMakeLists.txt +++ b/perf/CMakeLists.txt @@ -31,7 +31,12 @@ include_directories(AFTER SYSTEM ${PROJECT_SOURCE_DIR}/src) if (NNG_TESTS) macro (add_nng_perf NAME) add_executable (${NAME} perf.c) - target_link_libraries (${NAME} ${PROJECT_NAME}) + target_link_libraries (${NAME} ${PROJECT_NAME}_static) + target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES}) + target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB) + if (CMAKE_THREAD_LIBS_INIT) + target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}") + endif() endmacro (add_nng_perf) else () diff --git a/perf/perf.c b/perf/perf.c index 7f0349f6..202a3712 100644 --- a/perf/perf.c +++ b/perf/perf.c @@ -20,6 +20,17 @@ // API, so don't be lazy like this! All nni_ symbols are subject to // change without notice, and not part of the stable API or ABI. #include "core/nng_impl.h" +#include "core/thread.c" +#include "core/clock.c" +#include "platform/posix/posix_impl.h" +#include "platform/posix/posix_alloc.c" +#include "platform/posix/posix_clock.c" +#include "platform/posix/posix_debug.c" +#include "platform/posix/posix_thread.c" +#include "platform/windows/win_impl.h" +#include "platform/windows/win_clock.c" +#include "platform/windows/win_debug.c" +#include "platform/windows/win_thread.c" static void latency_client(const char *, int, int); static void latency_server(const char *, int, int); @@ -90,6 +101,17 @@ main(int argc, char **argv) } } +int +nop(void) +{ + return (0); +} + +int +nni_init(void) +{ + return (nni_plat_init(nop)); +} static void die(const char *fmt, ...) @@ -298,7 +320,7 @@ latency_client(const char *addr, int msgsize, int trips) nni_msg_free(msg); nng_close(s); - total = (end - start) / 1.0; + total = (float)(end - start); latency = (total / (trips * 2)); printf("total time: %.3f [s]\n", total / 1000000.0); printf("message size: %d [B]\n", msgsize); diff --git a/src/core/endpt.c b/src/core/endpt.c index c4673376..09ef0884 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -139,7 +139,6 @@ static void nni_dialer(void *arg) { nni_ep *ep = arg; - nni_pipe *pipe; int rv; nni_time cooldown; nni_mtx *mx = &ep->ep_sock->s_mx; diff --git a/src/core/idhash.c b/src/core/idhash.c index 58b68bbf..d816ddf4 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -91,7 +91,7 @@ nni_hash_resize(nni_idhash *h) uint32_t oldsize; nni_idhash_entry *newents; nni_idhash_entry *oldents; - int i; + uint32_t i; if ((h->ih_load < h->ih_maxload) && (h->ih_load >= h->ih_minload)) { // No resize needed. @@ -231,7 +231,7 @@ nni_idhash_count(nni_idhash *h, uint32_t *countp) int nni_idhash_walk(nni_idhash *h, nni_idhash_walkfn fn, void *arg) { - int i, rv; + uint32_t i, rv; for (i = 0; i < h->ih_cap; i++) { nni_idhash_entry *ent = &h->ih_entries[i]; diff --git a/src/core/message.c b/src/core/message.c index 4c666955..778e7dfc 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -41,7 +41,7 @@ typedef struct { static void nni_chunk_dump(const nni_chunk *chunk, char *prefix) { - int i, j; + size_t i, j; uint8_t x; char buf[128]; @@ -59,7 +59,7 @@ nni_chunk_dump(const nni_chunk *chunk, char *prefix) nni_println(buf); j = 0; } - snprintf(buf, sizeof (buf), " %4x: ", i); + snprintf(buf, sizeof (buf), " %4x: ", (unsigned) i); j += strlen(buf); } buf[j++] = ' '; @@ -413,7 +413,7 @@ nni_msg_getopt(nni_msg *m, int opt, void *val, size_t *szp) NNI_LIST_FOREACH (&m->m_options, mo) { if (mo->mo_num == opt) { - int sz = *szp; + size_t sz = *szp; if (sz > mo->mo_sz) { sz = mo->mo_sz; memcpy(val, mo->mo_val, sz); diff --git a/src/core/options.c b/src/core/options.c index 24d7a9eb..32b65ebf 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -103,7 +103,7 @@ nni_getopt_buf(nni_msgq *mq, void *val, size_t *sizep) { int len = nni_msgq_cap(mq); - int sz = *sizep; + size_t sz = *sizep; if (sz > sizeof (len)) { sz = sizeof (len); diff --git a/src/core/socket.c b/src/core/socket.c index c6b0408e..ae7cbc13 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -567,8 +567,6 @@ nni_sock_senderr(nni_sock *sock, int err) int nni_sock_setopt(nni_sock *sock, int opt, const void *val, size_t size) { - size_t rsz; - void *ptr; int rv = ENOTSUP; nni_mtx_lock(&sock->s_mx); @@ -612,8 +610,6 @@ nni_sock_setopt(nni_sock *sock, int opt, const void *val, size_t size) int nni_sock_getopt(nni_sock *sock, int opt, void *val, size_t *sizep) { - size_t rsz; - void *ptr; int rv = ENOTSUP; nni_mtx_lock(&sock->s_mx); diff --git a/src/platform/windows/win_clock.c b/src/platform/windows/win_clock.c index 9a2546ae..d0d2e7ca 100644 --- a/src/platform/windows/win_clock.c +++ b/src/platform/windows/win_clock.c @@ -22,7 +22,7 @@ nni_plat_clock(void) void nni_plat_usleep(nni_duration usec) { - Sleep((usec + 999) / 1000); + Sleep((DWORD)((usec + 999) / 1000)); } diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c index 42590ee9..86a4be03 100644 --- a/src/platform/windows/win_ipc.c +++ b/src/platform/windows/win_ipc.c @@ -11,6 +11,8 @@ #ifdef PLATFORM_WINDOWS +#include <stdio.h> + // Windows has infinite numbers of error codes it seems. We only bother // with the ones that are relevant to us (we think). static struct { @@ -73,7 +75,7 @@ nni_plat_ipc_send(nni_plat_ipcsock *s, nni_iov *iovs, int cnt) OVERLAPPED *olp = &s->send_olpd; NNI_ASSERT(cnt <= 4); - for (i = 0, resid = 0; i < cnt; resid += iov[i].iov_len, i++) { + for (i = 0, resid = 0; i < cnt; resid += (DWORD) iov[i].iov_len, i++) { iov[i].iov_len = iovs[i].iov_len; iov[i].iov_buf = iovs[i].iov_buf; } @@ -84,7 +86,8 @@ nni_plat_ipc_send(nni_plat_ipcsock *s, nni_iov *iovs, int cnt) nsent = 0; // We limit ourselves to writing 16MB at a time. Named Pipes // on Windows have limits of between 31 and 64MB. - len = iov[i].iov_len > 0x1000000 ? 0x1000000 : iov[i].iov_len; + len = iov[i].iov_len > 0x1000000 ? 0x1000000 : + (DWORD) iov[i].iov_len; buf = iov[i].iov_buf; if (!WriteFile(s->p, buf, len, NULL, olp)) { @@ -123,7 +126,7 @@ nni_plat_ipc_recv(nni_plat_ipcsock *s, nni_iov *iovs, int cnt) OVERLAPPED *olp = &s->recv_olpd; NNI_ASSERT(cnt <= 4); - for (i = 0, resid = 0; i < cnt; resid += iov[i].iov_len, i++) { + for (i = 0, resid = 0; i < cnt; resid += (DWORD) iov[i].iov_len, i++) { iov[i].iov_len = iovs[i].iov_len; iov[i].iov_buf = iovs[i].iov_buf; } @@ -134,7 +137,8 @@ nni_plat_ipc_recv(nni_plat_ipcsock *s, nni_iov *iovs, int cnt) nrecv = 0; // We limit ourselves to writing 16MB at a time. Named Pipes // on Windows have limits of between 31 and 64MB. - len = iov[i].iov_len > 0x1000000 ? 0x1000000 : iov[i].iov_len; + len = iov[i].iov_len > 0x1000000 ? 0x1000000 : + (DWORD) iov[i].iov_len; buf = iov[i].iov_buf; if (!ReadFile(s->p, buf, len, NULL, olp)) { @@ -262,7 +266,6 @@ nni_plat_ipc_accept(nni_plat_ipcsock *s, nni_plat_ipcsock *server) { int rv; OVERLAPPED *olp = &s->conn_olpd; - HANDLE newp; DWORD nbytes; s->server = 1; diff --git a/src/platform/windows/win_net.c b/src/platform/windows/win_net.c index 48be1781..060324eb 100644 --- a/src/platform/windows/win_net.c +++ b/src/platform/windows/win_net.c @@ -190,7 +190,6 @@ nni_plat_tcp_send(nni_plat_tcpsock *s, nni_iov *iovs, int cnt) WSABUF iov[4]; // We never have more than 3 at present int i; int rv; - DWORD offset; DWORD nsent; DWORD resid; DWORD flags; @@ -202,7 +201,7 @@ nni_plat_tcp_send(nni_plat_tcpsock *s, nni_iov *iovs, int cnt) for (i = 0, resid = 0; i < cnt; resid += iov[i].len, i++) { iov[i].buf = iovs[i].iov_buf; - iov[i].len = iovs[i].iov_len; + iov[i].len = (DWORD)iovs[i].iov_len; } i = 0; @@ -247,7 +246,6 @@ nni_plat_tcp_recv(nni_plat_tcpsock *s, nni_iov *iovs, int cnt) WSABUF iov[4]; // We never have more than 3 at present int i; int rv; - DWORD offset; DWORD resid; DWORD nrecv; DWORD flags; @@ -259,7 +257,7 @@ nni_plat_tcp_recv(nni_plat_tcpsock *s, nni_iov *iovs, int cnt) for (i = 0, resid = 0; i < cnt; resid += iov[i].len, i++) { iov[i].buf = iovs[i].iov_buf; - iov[i].len = iovs[i].iov_len; + iov[i].len = (DWORD)iovs[i].iov_len; } i = 0; @@ -352,8 +350,7 @@ nni_plat_tcp_open(nni_plat_tcpsock *s) GUID guid1 = WSAID_CONNECTEX; GUID guid2 = WSAID_ACCEPTEX; - s->s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_NO_HANDLE_INHERIT|WSA_FLAG_OVERLAPPED); + s->s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s->s == INVALID_SOCKET) { rv = WSAGetLastError(); return (nni_winsock_error(rv)); @@ -478,7 +475,6 @@ nni_plat_tcp_connect(nni_plat_tcpsock *s, const nni_sockaddr *addr, SOCKADDR_STORAGE ss; SOCKADDR_STORAGE bss; WSAOVERLAPPED *olp = &s->conn_olpd; - BOOL ok; DWORD nbytes; DWORD flags; int rv; diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index 2dcb62fe..ef4859d6 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -95,7 +95,7 @@ nni_plat_cv_until(nni_plat_cv *cv, nni_time until) msec = 0; } else { // times are in usec, but win32 wants millis - msec = ((until - now) + 999)/1000; + msec = (DWORD)(((until - now) + 999)/1000); } ok = SleepConditionVariableCS(&cv->cv, cv->cs, msec); diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c index 3c9d0674..0d57f1db 100644 --- a/src/protocol/bus/bus.c +++ b/src/protocol/bus/bus.c @@ -41,7 +41,6 @@ static int nni_bus_sock_init(void **sp, nni_sock *nsock) { nni_bus_sock *psock; - int rv; if ((psock = NNI_ALLOC_STRUCT(psock)) == NULL) { return (NNG_ENOMEM); diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c index ff02c2d1..0d8b32fe 100644 --- a/src/protocol/pair/pair.c +++ b/src/protocol/pair/pair.c @@ -45,7 +45,6 @@ static int nni_pair_sock_init(void **sp, nni_sock *nsock) { nni_pair_sock *psock; - int rv; if ((psock = NNI_ALLOC_STRUCT(psock)) == NULL) { return (NNG_ENOMEM); diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c index dc37e72b..20beb873 100644 --- a/src/protocol/pipeline/pull.c +++ b/src/protocol/pipeline/pull.c @@ -33,7 +33,6 @@ static int nni_pull_sock_init(void **pullp, nni_sock *sock) { nni_pull_sock *pull; - int rv; if ((pull = NNI_ALLOC_STRUCT(pull)) == NULL) { return (NNG_ENOMEM); @@ -59,7 +58,6 @@ static int nni_pull_pipe_init(void **ppp, nni_pipe *pipe, void *psock) { nni_pull_pipe *pp; - int rv; if ((pp = NNI_ALLOC_STRUCT(pp)) == NULL) { return (NNG_ENOMEM); diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c index e3b9ace8..4704a323 100644 --- a/src/protocol/pipeline/push.c +++ b/src/protocol/pipeline/push.c @@ -240,7 +240,6 @@ nni_push_sock_send(void *arg) nni_msgq *uwq = push->uwq; nni_msg *msg = NULL; nni_mtx *mx = nni_sock_mtx(push->sock); - int rv; int i; for (;;) { diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c index c9b0ce09..a167d523 100644 --- a/src/protocol/pubsub/pub.c +++ b/src/protocol/pubsub/pub.c @@ -41,7 +41,6 @@ static int nni_pub_sock_init(void **pubp, nni_sock *sock) { nni_pub_sock *pub; - int rv; if ((pub = NNI_ALLOC_STRUCT(pub)) == NULL) { return (NNG_ENOMEM); diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c index 0a6ce5fd..9390b0d2 100644 --- a/src/protocol/pubsub/sub.c +++ b/src/protocol/pubsub/sub.c @@ -44,7 +44,6 @@ static int nni_sub_sock_init(void **subp, nni_sock *sock) { nni_sub_sock *sub; - int rv; if ((sub = NNI_ALLOC_STRUCT(sub)) == NULL) { return (NNG_ENOMEM); @@ -79,7 +78,6 @@ static int nni_sub_pipe_init(void **spp, nni_pipe *pipe, void *ssock) { nni_sub_pipe *sp; - int rv; if ((sp = NNI_ALLOC_STRUCT(sp)) == NULL) { return (NNG_ENOMEM); diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c index 485fd4bc..90346236 100644 --- a/src/protocol/reqrep/rep.c +++ b/src/protocol/reqrep/rep.c @@ -224,7 +224,6 @@ nni_rep_pipe_recv(void *arg) NNI_PUT32(idbuf, id); for (;;) { - size_t len; uint8_t *body; int hops; @@ -323,7 +322,6 @@ static nni_msg * nni_rep_sock_sfilter(void *arg, nni_msg *msg) { nni_rep_sock *rep = arg; - size_t len; if (rep->raw) { return (msg); diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c index 2359fef1..0cef5a68 100644 --- a/src/protocol/survey/respond.c +++ b/src/protocol/survey/respond.c @@ -219,7 +219,6 @@ nni_resp_pipe_recv(void *arg) NNI_PUT32(idbuf, id); for (;;) { - size_t len; uint8_t *body; int hops; @@ -326,7 +325,6 @@ static nni_msg * nni_resp_sock_sfilter(void *arg, nni_msg *msg) { nni_resp_sock *psock = arg; - size_t len; if (psock->raw) { return (msg); diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 3f645d13..d6b1ac74 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -269,7 +269,6 @@ nni_inproc_ep_connect(void *arg, void **pipep) nni_mtx_lock(&nni_inproc.mx); for (;;) { nni_inproc_ep *server; - nni_list *list; if (ep->closed) { nni_mtx_unlock(&nni_inproc.mx); diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 2ddc74b7..4f1a5afa 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -227,7 +227,6 @@ nni_ipc_negotiate(nni_ipc_pipe *pipe) int rv; nni_iov iov; uint8_t buf[8]; - uint16_t peer; // First send our header.. buf[0] = 0; diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 8fcf07e5..6c085388 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -270,7 +270,6 @@ nni_tcp_negotiate(nni_tcp_pipe *pipe) int rv; nni_iov iov; uint8_t buf[8]; - uint16_t peer; // First send our header.. buf[0] = 0; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 066865e3..9c711408 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,6 +40,7 @@ if (NNG_TESTS) add_executable (${NAME} ${NAME}.c convey.c) target_link_libraries (${NAME} ${PROJECT_NAME}_static) target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES}) + target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB) if (CMAKE_THREAD_LIBS_INIT) target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}") endif() @@ -49,20 +50,9 @@ if (NNG_TESTS) math (EXPR TEST_PORT "${TEST_PORT}+10") endmacro (add_nng_test) - macro (add_nng_perf NAME) - add_executable (${NAME} perf/${NAME}.c) - target_link_libraries (${NAME} ${PROJECT_NAME}_static) - target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES}) - if (CMAKE_THREAD_LIBS_INIT) - target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}") - endif() - endmacro (add_nng_perf) - else () macro (add_nng_test NAME TIMEOUT) endmacro (add_nng_test) - macro (add_nng_perf NAME) - endmacro (add_nng_perf) endif () add_nng_test(bus 5) diff --git a/tests/convey.c b/tests/convey.c index e74e150a..9a56cf82 100644 --- a/tests/convey.c +++ b/tests/convey.c @@ -619,7 +619,7 @@ convey_vlogf(struct convey_log *log, const char *fmt, va_list va, int addnl) { /* Grow the log buffer if we need to */ while ((log->log_size - log->log_length) < 256) { - int newsz = log->log_size + 2000; + size_t newsz = log->log_size + 2000; char *ptr = malloc(newsz); if (ptr == NULL) { return; diff --git a/tests/idhash.c b/tests/idhash.c index 6ecff47b..fb240078 100644 --- a/tests/idhash.c +++ b/tests/idhash.c @@ -9,6 +9,7 @@ #include "core/idhash.c" #include "convey.h" +#include "stubs.h" Main({ Test("General ID Hash", { @@ -93,7 +94,6 @@ Main({ Test("Resize ID Hash", { int expect[1024]; - int actual[1024]; int rv; int i; diff --git a/tests/list.c b/tests/list.c index 10668b50..b0da1196 100644 --- a/tests/list.c +++ b/tests/list.c @@ -9,6 +9,7 @@ #include "core/list.c" #include "convey.h" +#include "stubs.h" typedef struct { int pad[2]; diff --git a/tests/pipeline.c b/tests/pipeline.c index d6af728f..a8200900 100644 --- a/tests/pipeline.c +++ b/tests/pipeline.c @@ -17,7 +17,6 @@ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0) Main({ - int rv; const char *addr = "inproc://test"; Test("PIPELINE (PUSH/PULL) pattern", { diff --git a/tests/platform.c b/tests/platform.c index 0ac881d6..fb8ee2a7 100644 --- a/tests/platform.c +++ b/tests/platform.c @@ -66,9 +66,16 @@ notifyafter(void *arg) nni_mtx_unlock(&na->mx); } +int +nop(void) +{ + return (0); +} + TestMain("Platform Operations", { - int rv = nni_init(); // This is required for anything else to work + // This is required for anything else to work + int rv = nni_plat_init(nop); Convey("Platform init worked", { So(rv == 0); }) diff --git a/tests/reqrep.c b/tests/reqrep.c index 53091928..c3ff9315 100644 --- a/tests/reqrep.c +++ b/tests/reqrep.c @@ -118,7 +118,6 @@ Main({ nng_msg *abc; nng_msg *def; nng_msg *cmd; - nng_msg *nvm; uint64_t retry = 100000; // 100 ms size_t len; diff --git a/tests/sock.c b/tests/sock.c index 8863023c..7d1d226b 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -8,38 +8,11 @@ // #include "convey.h" +#include "stubs.h" #include "nng.h" #include <string.h> -#ifndef _WIN32 -#include <sys/time.h> -#endif - -uint64_t -getms(void) -{ -#ifdef _WIN32 - return (GetTickCount64()) ; -#else - static time_t epoch; - struct timeval tv; - - if (epoch == 0) { - epoch = time(NULL); - } - gettimeofday(&tv, NULL); - - if (tv.tv_sec < epoch) { - // Broken clock. - // This will force all other timing tests to fail - return (0); - } - tv.tv_sec -= epoch; - return (((uint64_t)(tv.tv_sec ) * 1000) + (tv.tv_usec / 1000)); -#endif -} - TestMain("Socket Operations", { Convey("We are able to open a PAIR socket", { int rv; diff --git a/tests/stubs.h b/tests/stubs.h new file mode 100644 index 00000000..9bd9c279 --- /dev/null +++ b/tests/stubs.h @@ -0,0 +1,47 @@ +// +// Copyright 2017 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 +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "convey.h" +#include "nng.h" +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#ifdef _WIN32 +#include <windows.h> +#else +#include <sys/time.h> +#endif + +// Stub handlers for some common things. + +uint64_t +getms(void) +{ +#ifdef _WIN32 + return (GetTickCount64()) ; +#else + static time_t epoch; + struct timeval tv; + + if (epoch == 0) { + epoch = time(NULL); + } + gettimeofday(&tv, NULL); + + if (tv.tv_sec < epoch) { + // Broken clock. + // This will force all other timing tests to fail + return (0); + } + tv.tv_sec -= epoch; + return (((uint64_t)(tv.tv_sec ) * 1000) + (tv.tv_usec / 1000)); +#endif +} |
