diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-24 08:45:53 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-24 08:45:53 -0800 |
| commit | 4c496d8182b5f3a5db6ca8fd763bab444e39f48a (patch) | |
| tree | 1ec220c70d08951ce0f37d58255bd49d485c7701 /src/core | |
| parent | 7df0822d3ed58ee73918cac576c0b07363e84425 (diff) | |
| download | nng-4c496d8182b5f3a5db6ca8fd763bab444e39f48a.tar.gz nng-4c496d8182b5f3a5db6ca8fd763bab444e39f48a.tar.bz2 nng-4c496d8182b5f3a5db6ca8fd763bab444e39f48a.zip | |
Implement reconnect timer including backoff.
This allows us to enable the last test case for compat_reqrep.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/endpt.c | 35 | ||||
| -rw-r--r-- | src/core/socket.c | 2 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c index 5a642a2f..9aae89eb 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -161,11 +161,31 @@ nni_dialer(void *arg) nni_ep *ep = arg; int rv; nni_time cooldown; + nni_duration maxrtime; + nni_duration defrtime; + nni_duration rtime; nni_mtx *mx = &ep->ep_sock->s_mx; + nni_mtx_lock(mx); + defrtime = ep->ep_sock->s_reconn; + if ((maxrtime = ep->ep_sock->s_reconnmax) == 0) { + maxrtime = defrtime; + } + nni_mtx_unlock(mx); + for (;;) { nni_mtx_lock(mx); + if ((defrtime != ep->ep_sock->s_reconn) || + (maxrtime != ep->ep_sock->s_reconnmax)) { + // Times changed, so reset them. + defrtime = ep->ep_sock->s_reconn; + if ((maxrtime = ep->ep_sock->s_reconnmax) == 0) { + maxrtime = defrtime; + } + rtime = defrtime; + } while ((!ep->ep_close) && (ep->ep_pipe != NULL)) { + rtime = defrtime; nni_cv_wait(&ep->ep_cv); } if (ep->ep_close) { @@ -179,22 +199,19 @@ nni_dialer(void *arg) case 0: // good connection continue; - case NNG_ENOMEM: - cooldown = 1000000; - break; case NNG_ECLOSED: return; default: - // XXX: THIS NEEDS TO BE A PROPER BACKOFF. - cooldown = 1000000; + cooldown = nni_clock() + rtime; + rtime *= 2; + if ((maxrtime >= defrtime) && (rtime > maxrtime)) { + rtime = maxrtime; + } break; } // we inject a delay so we don't just spin hard on - // errors like connection refused. For NNG_ENOMEM, we - // wait even longer, since the system needs time to - // release resources. - cooldown += nni_clock(); + // errors like connection refused. nni_mtx_lock(mx); while (!ep->ep_close) { // We need a different condvar... diff --git a/src/core/socket.c b/src/core/socket.c index 24078941..b0ce172f 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -274,7 +274,7 @@ nni_sock_open(nni_sock **sockp, uint16_t pnum) sock->s_rcvtimeo = -1; sock->s_closing = 0; sock->s_reconn = NNI_SECOND; - sock->s_reconnmax = NNI_SECOND; + sock->s_reconnmax = 0; sock->s_reapexit = 0; NNI_LIST_INIT(&sock->s_pipes, nni_pipe, p_node); NNI_LIST_INIT(&sock->s_reaps, nni_pipe, p_node); |
