diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/aio.c | 3 | ||||
| -rw-r--r-- | src/core/device.c | 9 | ||||
| -rw-r--r-- | src/core/endpt.c | 3 | ||||
| -rw-r--r-- | src/core/options.c | 80 | ||||
| -rw-r--r-- | src/core/socket.c | 84 |
5 files changed, 75 insertions, 104 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 5b8c7970..ee5724a6 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -171,7 +171,8 @@ nni_aio_finish_impl( { nni_mtx_lock(&nni_aio_lk); - NNI_ASSERT(aio->a_pend == 0); // provider only calls us *once* + // provider only calls us *once*, but expiration may be in flight + NNI_ASSERT(aio->a_expiring || aio->a_pend == 0); nni_list_node_remove(&aio->a_expire_node); aio->a_pend = 1; diff --git a/src/core/device.c b/src/core/device.c index bdfcf0a6..e7140664 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore <garrett@damore.org> +// Copyright 2017 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 @@ -90,10 +91,10 @@ nni_device(nni_sock *sock1, nni_sock *sock2) // No timeouts. sz = sizeof(never); - if ((nni_sock_setopt(sock1, NNG_OPT_RCVTIMEO, &never, sz) != 0) || - (nni_sock_setopt(sock2, NNG_OPT_RCVTIMEO, &never, sz) != 0) || - (nni_sock_setopt(sock1, NNG_OPT_SNDTIMEO, &never, sz) != 0) || - (nni_sock_setopt(sock2, NNG_OPT_SNDTIMEO, &never, sz) != 0)) { + if ((nni_sock_setopt(sock1, nng_optid_recvtimeo, &never, sz) != 0) || + (nni_sock_setopt(sock2, nng_optid_recvtimeo, &never, sz) != 0) || + (nni_sock_setopt(sock1, nng_optid_sendtimeo, &never, sz) != 0) || + (nni_sock_setopt(sock2, nng_optid_sendtimeo, &never, sz) != 0)) { // This should never happen. rv = NNG_EINVAL; goto out; diff --git a/src/core/endpt.c b/src/core/endpt.c index 5b56b784..10608575 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -320,7 +320,8 @@ nni_ep_tmo_start(nni_ep *ep) // have a statistically perfect distribution with the modulo of // the random number, but this really doesn't matter. - ep->ep_tmo_aio.a_expire = nni_clock() + (nni_random() % backoff); + ep->ep_tmo_aio.a_expire = + nni_clock() + (backoff ? nni_random() % backoff : 0); nni_aio_start(&ep->ep_tmo_aio, nni_ep_tmo_cancel, ep); } diff --git a/src/core/options.c b/src/core/options.c index bdbcaaba..7a5de33d 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -340,6 +340,20 @@ nni_option_register(const char *name, int *idp) return (0); } +void +nni_option_sys_fini(void) +{ + if (nni_option_nextid != 0) { + nni_option *opt; + while ((opt = nni_list_first(&nni_options)) != NULL) { + nni_list_remove(&nni_options, opt); + nni_free(opt->o_name, strlen(opt->o_name) + 1); + NNI_FREE_STRUCT(opt); + } + } + nni_option_nextid = 0; +} + int nni_option_sys_init(void) { @@ -348,52 +362,32 @@ nni_option_sys_init(void) nni_option_nextid = 0x10000; int rv; +#define OPT_REGISTER(o) nni_option_register(nng_opt_##o, &nng_optid_##o) // Register our well-known options. - if (((rv = nni_option_set_id("raw", NNG_OPT_RAW)) != 0) || - ((rv = nni_option_set_id("linger", NNG_OPT_LINGER)) != 0) || - ((rv = nni_option_set_id("recv-buf", NNG_OPT_RCVBUF)) != 0) || - ((rv = nni_option_set_id("send-buf", NNG_OPT_SNDBUF)) != 0) || - ((rv = nni_option_set_id("recv-timeout", NNG_OPT_RCVTIMEO)) != - 0) || - ((rv = nni_option_set_id("send-timeout", NNG_OPT_SNDTIMEO)) != - 0) || - ((rv = nni_option_set_id("reconnect-time", NNG_OPT_RECONN_TIME)) != - 0) || - ((rv = nni_option_set_id( - "reconnect-max-time", NNG_OPT_RECONN_MAXTIME)) != 0) || - ((rv = nni_option_set_id("recv-max-size", NNG_OPT_RCVMAXSZ)) != - 0) || - ((rv = nni_option_set_id("max-ttl", NNG_OPT_MAXTTL)) != 0) || - ((rv = nni_option_set_id("protocol", NNG_OPT_PROTOCOL)) != 0) || - ((rv = nni_option_set_id("subscribe", NNG_OPT_SUBSCRIBE)) != 0) || - ((rv = nni_option_set_id("unsubscribe", NNG_OPT_UNSUBSCRIBE)) != - 0) || - ((rv = nni_option_set_id("survey-time", NNG_OPT_SURVEYTIME)) != - 0) || - ((rv = nni_option_set_id("resend-time", NNG_OPT_RESENDTIME)) != - 0) || - ((rv = nni_option_set_id("transport", NNG_OPT_TRANSPORT)) != 0) || - ((rv = nni_option_set_id("local-addr", NNG_OPT_LOCALADDR)) != 0) || - ((rv = nni_option_set_id("remote-addr", NNG_OPT_REMOTEADDR)) != - 0) || - ((rv = nni_option_set_id("recv-fd", NNG_OPT_RCVFD)) != 0) || - ((rv = nni_option_set_id("send-fd", NNG_OPT_SNDFD)) != 0)) { + if (((rv = OPT_REGISTER(raw)) != 0) || + ((rv = OPT_REGISTER(linger)) != 0) || + ((rv = OPT_REGISTER(recvbuf)) != 0) || + ((rv = OPT_REGISTER(sendbuf)) != 0) || + ((rv = OPT_REGISTER(recvtimeo)) != 0) || + ((rv = OPT_REGISTER(sendtimeo)) != 0) || + ((rv = OPT_REGISTER(reconnmint)) != 0) || + ((rv = OPT_REGISTER(reconnmaxt)) != 0) || + ((rv = OPT_REGISTER(recvmaxsz)) != 0) || + ((rv = OPT_REGISTER(maxttl)) != 0) || + ((rv = OPT_REGISTER(protocol)) != 0) || + ((rv = OPT_REGISTER(transport)) != 0) || + ((rv = OPT_REGISTER(locaddr)) != 0) || + ((rv = OPT_REGISTER(remaddr)) != 0) || + ((rv = OPT_REGISTER(recvfd)) != 0) || + ((rv = OPT_REGISTER(sendfd)) != 0) || + ((rv = OPT_REGISTER(req_resendtime)) != 0) || + ((rv = OPT_REGISTER(sub_subscribe)) != 0) || + ((rv = OPT_REGISTER(sub_unsubscribe)) != 0) || + ((rv = OPT_REGISTER(surveyor_surveytime)) != 0)) { nni_option_sys_fini(); return (rv); } +#undef OPT_REGISTER + return (0); } - -void -nni_option_sys_fini(void) -{ - if (nni_option_nextid != 0) { - nni_option *opt; - while ((opt = nni_list_first(&nni_options)) != NULL) { - nni_list_remove(&nni_options, opt); - nni_free(opt->o_name, strlen(opt->o_name) + 1); - NNI_FREE_STRUCT(opt); - } - } - nni_option_nextid = 0; -}
\ No newline at end of file diff --git a/src/core/socket.c b/src/core/socket.c index 765a6d0c..be1c2d96 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -362,17 +362,17 @@ nni_sock_create(nni_sock **sp, const nni_proto *proto) if (((rv = nni_msgq_init(&s->s_uwq, 0)) != 0) || ((rv = nni_msgq_init(&s->s_urq, 0)) != 0) || ((rv = s->s_sock_ops.sock_init(&s->s_data, s)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_LINGER, &s->s_linger, + ((rv = nni_sock_setopt(s, nng_optid_linger, &s->s_linger, sizeof(nni_duration))) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_SNDTIMEO, &s->s_sndtimeo, + ((rv = nni_sock_setopt(s, nng_optid_sendtimeo, &s->s_sndtimeo, sizeof(nni_duration))) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RCVTIMEO, &s->s_rcvtimeo, + ((rv = nni_sock_setopt(s, nng_optid_recvtimeo, &s->s_rcvtimeo, sizeof(nni_duration))) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECONN_TIME, &s->s_reconn, + ((rv = nni_sock_setopt(s, nng_optid_reconnmint, &s->s_reconn, sizeof(nni_duration))) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECONN_MAXTIME, &s->s_reconnmax, + ((rv = nni_sock_setopt(s, nng_optid_reconnmaxt, &s->s_reconnmax, sizeof(nni_duration))) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RCVMAXSZ, &s->s_rcvmaxsz, + ((rv = nni_sock_setopt(s, nng_optid_recvmaxsz, &s->s_rcvmaxsz, sizeof(size_t))) != 0)) { nni_sock_destroy(s); return (rv); @@ -807,26 +807,18 @@ nni_sock_setopt(nni_sock *s, int opt, const void *val, size_t size) // Some options do not go down to transports. Handle them // directly. - switch (opt) { - case NNG_OPT_RECONN_TIME: + if (opt == nng_optid_reconnmint) { rv = nni_setopt_usec(&s->s_reconn, val, size); - break; - case NNG_OPT_RECONN_MAXTIME: + } else if (opt == nng_optid_reconnmaxt) { rv = nni_setopt_usec(&s->s_reconnmax, val, size); - break; - case NNG_OPT_SNDBUF: + } else if (opt == nng_optid_sendbuf) { rv = nni_setopt_buf(s->s_uwq, val, size); - break; - case NNG_OPT_RCVBUF: + } else if (opt == nng_optid_recvbuf) { rv = nni_setopt_buf(s->s_urq, val, size); - break; - case NNG_OPT_SNDFD: - case NNG_OPT_RCVFD: - case NNG_OPT_LOCALADDR: - case NNG_OPT_REMOTEADDR: + } else if ((opt == nng_optid_sendfd) || (opt == nng_optid_recvfd) || + (opt == nng_optid_locaddr) || (opt == nng_optid_remaddr)) { // these options can be read, but cannot be set rv = NNG_EINVAL; - break; } nni_mtx_unlock(&s->s_mx); @@ -845,21 +837,14 @@ nni_sock_setopt(nni_sock *s, int opt, const void *val, size_t size) // check was found, or even if a transport rejected one of the // settings. if ((rv == NNG_ENOTSUP) || (rv == 0)) { - switch (opt) { - case NNG_OPT_LINGER: - rv = nni_chkopt_usec(val, size); - break; - case NNG_OPT_SNDTIMEO: + if ((opt == nng_optid_linger) || + (opt == nng_optid_sendtimeo) || + (opt == nng_optid_recvtimeo)) { rv = nni_chkopt_usec(val, size); - break; - case NNG_OPT_RCVTIMEO: - rv = nni_chkopt_usec(val, size); - break; - case NNG_OPT_RCVMAXSZ: + } else if (opt == nng_optid_recvmaxsz) { // just a sanity test on the size; it also ensures that // a size can be set even with no transport configured. rv = nni_chkopt_size(val, size, 0, NNI_MAXSZ); - break; } } @@ -913,16 +898,13 @@ nni_sock_setopt(nni_sock *s, int opt, const void *val, size_t size) // For some options, which also have an impact on the socket // behavior, we save a local value. Note that the transport // will already have had a chance to veto this. - switch (opt) { - case NNG_OPT_LINGER: + + if (opt == nng_optid_linger) { rv = nni_setopt_usec(&s->s_linger, val, size); - break; - case NNG_OPT_SNDTIMEO: + } else if (opt == nng_optid_sendtimeo) { rv = nni_setopt_usec(&s->s_sndtimeo, val, size); - break; - case NNG_OPT_RCVTIMEO: + } else if (opt == nng_optid_recvtimeo) { rv = nni_setopt_usec(&s->s_rcvtimeo, val, size); - break; } if (rv == 0) { @@ -965,26 +947,19 @@ nni_sock_getopt(nni_sock *s, int opt, void *val, size_t *szp) // Options that are handled by socket core, and never // passed down. - switch (opt) { - case NNG_OPT_RECONN_TIME: - rv = nni_getopt_usec(&s->s_reconn, val, szp); - break; - case NNG_OPT_RECONN_MAXTIME: - rv = nni_getopt_usec(&s->s_reconnmax, val, szp); - break; - case NNG_OPT_SNDBUF: + if (opt == nng_optid_sendbuf) { rv = nni_getopt_buf(s->s_uwq, val, szp); - break; - case NNG_OPT_RCVBUF: + } else if (opt == nng_optid_recvbuf) { rv = nni_getopt_buf(s->s_urq, val, szp); - break; - case NNG_OPT_SNDFD: + } else if (opt == nng_optid_sendfd) { rv = nni_getopt_fd(s, &s->s_send_fd, NNG_EV_CAN_SND, val, szp); - break; - case NNG_OPT_RCVFD: + } else if (opt == nng_optid_recvfd) { rv = nni_getopt_fd(s, &s->s_recv_fd, NNG_EV_CAN_RCV, val, szp); - break; - default: + } else if (opt == nng_optid_reconnmint) { + rv = nni_getopt_usec(&s->s_reconn, val, szp); + } else if (opt == nng_optid_reconnmaxt) { + rv = nni_getopt_usec(&s->s_reconnmax, val, szp); + } else { NNI_LIST_FOREACH (&s->s_options, sopt) { if (sopt->opt == opt) { size_t sz = sopt->sz; @@ -997,7 +972,6 @@ nni_sock_getopt(nni_sock *s, int opt, void *val, size_t *szp) break; } } - break; } nni_mtx_unlock(&s->s_mx); return (rv); |
