From 2e5f47aed81992a8dba4b27823894507794fc0ad Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 24 Aug 2017 16:27:53 -0700 Subject: Fix a few warnings and subtle test races. --- src/core/idhash.c | 2 +- src/core/options.c | 2 +- src/core/socket.c | 6 +++++- src/transport/inproc/inproc.c | 3 +-- tests/pair1.c | 1 - tests/pipeline.c | 2 ++ tests/pubsub.c | 5 +++-- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/idhash.c b/src/core/idhash.c index 6d8c8163..c0030f76 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -174,7 +174,7 @@ nni_hash_resize(nni_idhash *h) h->ih_maxload = 5; } for (i = 0; i < oldsize; i++) { - uint32_t index; + size_t index; if (oldents[i].ihe_val == NULL) { continue; } diff --git a/src/core/options.c b/src/core/options.c index 7a5de33d..03002d6c 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -263,7 +263,7 @@ static int nni_option_set_id(const char *name, int id) { nni_option *opt; - int len; + size_t len; nni_mtx_lock(&nni_option_lk); NNI_LIST_FOREACH (&nni_options, opt) { if (strcmp(name, opt->o_name) == 0) { diff --git a/src/core/socket.c b/src/core/socket.c index be1c2d96..6a242558 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -307,6 +307,10 @@ nni_sock_destroy(nni_sock *s) nni_free_opt(sopt); } + // This exists to silence a false positive in helgrind. + nni_mtx_lock(&s->s_mx); + nni_mtx_unlock(&s->s_mx); + nni_ev_fini(&s->s_send_ev); nni_ev_fini(&s->s_recv_ev); nni_msgq_fini(s->s_urq); @@ -764,7 +768,7 @@ nni_sock_ep_remove(nni_sock *sock, nni_ep *ep) nni_mtx_lock(&sock->s_mx); if (nni_list_active(&sock->s_eps, ep)) { nni_list_remove(&sock->s_eps, ep); - if ((sock->s_closed) && (nni_list_empty(&sock->s_eps))) { + if ((sock->s_closing) && (nni_list_empty(&sock->s_eps))) { nni_cv_wake(&sock->s_cv); } } diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 23a74998..e3cc5143 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -179,10 +179,9 @@ nni_inproc_pipe_peer(void *arg) static int nni_inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp) { +#if 0 nni_inproc_pipe *pipe = arg; - size_t len; -#if 0 switch (option) { case NNG_OPT_LOCALADDR: case NNG_OPT_REMOTEADDR: diff --git a/tests/pair1.c b/tests/pair1.c index 6e7a22cb..7b26702b 100644 --- a/tests/pair1.c +++ b/tests/pair1.c @@ -172,7 +172,6 @@ TestMain("PAIRv1 protocol", { }); Convey("Cannot set polyamorous mode after connect", { - int poly; So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); nng_usleep(100000); diff --git a/tests/pipeline.c b/tests/pipeline.c index 78002fc6..618b7227 100644 --- a/tests/pipeline.c +++ b/tests/pipeline.c @@ -79,6 +79,8 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { So(nng_dial(what, addr, NULL, 0) == 0); So(nng_shutdown(what) == 0); + nng_usleep(20000); + Convey("Push can send messages, and pull can recv", { nng_msg *msg; diff --git a/tests/pubsub.c b/tests/pubsub.c index de2fcfc5..3bdd8f8c 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -77,11 +77,12 @@ TestMain("PUB/SUB pattern", { // and the sub dial. However, this creates a problem // for our tests, since we can wind up trying to push // data before the pipe is fully registered (the accept - // runs asynchronously.) Doing the reverse here - // ensures that we won't lose data. + // runs asynchronously.) So(nng_listen(sub, addr, NULL, 0) == 0); So(nng_dial(pub, addr, NULL, 0) == 0); + nng_usleep(20000); // give time for connecting threads + Convey("Sub can subscribe", { So(nng_setopt( sub, nng_optid_sub_subscribe, "ABC", 3) == 0); -- cgit v1.2.3-70-g09d2