aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-09 13:08:33 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-09 13:08:33 -0800
commit1cfa242ceb8c8c987e3406700e95874fda107793 (patch)
tree0c4fe2b7d84f37c29fc9d5f14be8de2dceb7dc77
parent2da5acde4acaf523a89d012b1bb87a4e5862e7c5 (diff)
downloadnng-1cfa242ceb8c8c987e3406700e95874fda107793.tar.gz
nng-1cfa242ceb8c8c987e3406700e95874fda107793.tar.bz2
nng-1cfa242ceb8c8c987e3406700e95874fda107793.zip
fixes #196 surveyor pattern hangs after second survey
-rw-r--r--src/core/timer.c8
-rw-r--r--src/protocol/survey0/survey.c13
2 files changed, 12 insertions, 9 deletions
diff --git a/src/core/timer.c b/src/core/timer.c
index 7608f7d5..8db2e9d8 100644
--- a/src/core/timer.c
+++ b/src/core/timer.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
@@ -105,7 +105,6 @@ nni_timer_schedule(nni_timer_node *node, nni_time when)
{
nni_timer * timer = &nni_global_timer;
nni_timer_node *srch;
- int wake = 1;
nni_mtx_lock(&timer->t_mx);
node->t_expire = when;
@@ -117,14 +116,13 @@ nni_timer_schedule(nni_timer_node *node, nni_time when)
srch = nni_list_first(&timer->t_entries);
while ((srch != NULL) && (srch->t_expire < node->t_expire)) {
srch = nni_list_next(&timer->t_entries, srch);
- wake = 0;
}
if (srch != NULL) {
nni_list_insert_before(&timer->t_entries, node, srch);
} else {
nni_list_append(&timer->t_entries, node);
}
- if (wake) {
+ if (nni_list_first(&timer->t_entries) == node) {
nni_cv_wake1(&timer->t_sched_cv);
}
nni_mtx_unlock(&timer->t_mx);
diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c
index b3ea0323..3944a105 100644
--- a/src/protocol/survey0/survey.c
+++ b/src/protocol/survey0/survey.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
@@ -94,7 +94,7 @@ surv0_sock_init(void **sp, nni_sock *nsock)
s->nextid = nni_random();
s->raw = 0;
- s->survtime = NNI_SECOND * 60;
+ s->survtime = NNI_SECOND;
s->expire = NNI_TIME_ZERO;
s->uwq = nni_sock_sendq(nsock);
s->urq = nni_sock_recvq(nsock);
@@ -222,7 +222,7 @@ surv0_send_cb(void *arg)
return;
}
- nni_msgq_aio_get(p->psock->uwq, p->aio_getq);
+ nni_msgq_aio_get(p->sendq, p->aio_getq);
}
static void
@@ -354,6 +354,8 @@ surv0_sock_getq_cb(void *arg)
nni_msg_free(dup);
}
}
+
+ nni_msgq_aio_get(s->uwq, s->aio_getq);
nni_mtx_unlock(&s->mtx);
if (last == NULL) {
@@ -370,6 +372,7 @@ surv0_timeout(void *arg)
nni_mtx_lock(&s->mtx);
s->survid = 0;
nni_mtx_unlock(&s->mtx);
+
nni_msgq_set_get_error(s->urq, NNG_ETIMEDOUT);
}
@@ -420,6 +423,7 @@ surv0_sock_send(void *arg, nni_aio *aio)
// If another message is there, this cancels it. We move the
// survey expiration out. The timeout thread will wake up in
// the wake below, and reschedule itself appropriately.
+ nni_msgq_set_get_error(s->urq, 0);
s->expire = nni_clock() + s->survtime;
nni_timer_schedule(&s->timer, s->expire);
@@ -443,6 +447,7 @@ surv0_sock_filter(void *arg, nni_msg *msg)
if ((nni_msg_header_len(msg) < sizeof(uint32_t)) ||
(nni_msg_header_trim_u32(msg) != s->survid)) {
// Wrong request id
+ nni_mtx_unlock(&s->mtx);
nni_msg_free(msg);
return (NULL);
}