diff options
| author | Garrett D'Amore <garrett@damore.org> | 2021-12-25 18:01:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2021-12-25 18:05:56 -0800 |
| commit | 7b02ddc2d7077439992a10bb69553f89b5ee5903 (patch) | |
| tree | c3c6467330be2b38491f0df061d7016e713b1892 /src/sp/protocol/survey0 | |
| parent | 6237d268514e1f8aec562052954db22c4540eec3 (diff) | |
| download | nng-7b02ddc2d7077439992a10bb69553f89b5ee5903.tar.gz nng-7b02ddc2d7077439992a10bb69553f89b5ee5903.tar.bz2 nng-7b02ddc2d7077439992a10bb69553f89b5ee5903.zip | |
Socket and context initialization never fails.
This makes these functions entirely bullet proof, and eliminates
yet more error handling cases.
Diffstat (limited to 'src/sp/protocol/survey0')
| -rw-r--r-- | src/sp/protocol/survey0/respond.c | 13 | ||||
| -rw-r--r-- | src/sp/protocol/survey0/survey.c | 15 | ||||
| -rw-r--r-- | src/sp/protocol/survey0/xrespond.c | 12 | ||||
| -rw-r--r-- | src/sp/protocol/survey0/xsurvey.c | 6 |
4 files changed, 16 insertions, 30 deletions
diff --git a/src/sp/protocol/survey0/respond.c b/src/sp/protocol/survey0/respond.c index ad551c8f..d29eab97 100644 --- a/src/sp/protocol/survey0/respond.c +++ b/src/sp/protocol/survey0/respond.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2021 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 @@ -104,7 +104,7 @@ resp0_ctx_fini(void *arg) resp0_ctx_close(ctx); } -static int +static void resp0_ctx_init(void *carg, void *sarg) { resp0_sock *s = sarg; @@ -115,8 +115,6 @@ resp0_ctx_init(void *carg, void *sarg) ctx->btrace_len = 0; ctx->sock = s; ctx->pipe_id = 0; - - return (0); } static void @@ -220,7 +218,7 @@ resp0_sock_fini(void *arg) nni_mtx_fini(&s->mtx); } -static int +static void resp0_sock_init(void *arg, nni_sock *nsock) { resp0_sock *s = arg; @@ -236,13 +234,12 @@ resp0_sock_init(void *arg, nni_sock *nsock) nni_atomic_init(&s->ttl); nni_atomic_set(&s->ttl, 8); // Per RFC - (void) resp0_ctx_init(&s->ctx, s); + resp0_ctx_init(&s->ctx, s); // We start off without being either readable or writable. // Readability comes when there is something on the socket. nni_pollable_init(&s->writable); nni_pollable_init(&s->readable); - return (0); } static void @@ -492,7 +489,7 @@ resp0_pipe_recv_cb(void *arg) // Move backtrace from body to header hops = 1; for (;;) { - bool end = 0; + bool end; uint8_t *body; if (hops > ttl) { diff --git a/src/sp/protocol/survey0/survey.c b/src/sp/protocol/survey0/survey.c index 3287138d..5c52d8f8 100644 --- a/src/sp/protocol/survey0/survey.c +++ b/src/sp/protocol/survey0/survey.c @@ -103,7 +103,7 @@ surv0_ctx_fini(void *arg) nni_lmq_fini(&ctx->recv_lmq); } -static int +static void surv0_ctx_init(void *c, void *s) { surv0_ctx * ctx = c; @@ -130,7 +130,6 @@ surv0_ctx_init(void *c, void *s) nni_lmq_init(&ctx->recv_lmq, len); nni_timer_init(&ctx->timer, surv0_ctx_timeout, ctx); - return (0); } static void @@ -280,11 +279,10 @@ surv0_sock_fini(void *arg) nni_mtx_fini(&sock->mtx); } -static int +static void surv0_sock_init(void *arg, nni_sock *s) { surv0_sock *sock = arg; - int rv; NNI_ARG_UNUSED(s); @@ -295,7 +293,7 @@ surv0_sock_init(void *arg, nni_sock *s) // We are always writable. nni_pollable_raise(&sock->writable); - // We allow for some buffering on a per pipe basis, to allow for + // We allow for some buffering on a per-pipe basis, to allow for // multiple contexts to have surveys outstanding. It is recommended // to increase this if many contexts will want to publish // at nearly the same time. @@ -307,14 +305,9 @@ surv0_sock_init(void *arg, nni_sock *s) // accidental collision across restarts. nni_id_map_init(&sock->surveys, 0x80000000u, 0xffffffffu, true); - if ((rv = surv0_ctx_init(&sock->ctx, sock)) != 0) { - surv0_sock_fini(sock); - return (rv); - } + surv0_ctx_init(&sock->ctx, sock); sock->ttl = 8; - - return (0); } static void diff --git a/src/sp/protocol/survey0/xrespond.c b/src/sp/protocol/survey0/xrespond.c index b2f203c3..81a40486 100644 --- a/src/sp/protocol/survey0/xrespond.c +++ b/src/sp/protocol/survey0/xrespond.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2021 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 @@ -67,8 +67,8 @@ xresp0_sock_fini(void *arg) nni_mtx_fini(&s->mtx); } -static int -xresp0_sock_init(void *arg, nni_sock *nsock) +static void +xresp0_sock_init(void *arg, nni_sock *ns) { xresp0_sock *s = arg; @@ -78,10 +78,8 @@ xresp0_sock_init(void *arg, nni_sock *nsock) nni_id_map_init(&s->pipes, 0, 0, false); nni_aio_init(&s->aio_getq, xresp0_sock_getq_cb, s); - s->urq = nni_sock_recvq(nsock); - s->uwq = nni_sock_sendq(nsock); - - return (0); + s->urq = nni_sock_recvq(ns); + s->uwq = nni_sock_sendq(ns); } static void diff --git a/src/sp/protocol/survey0/xsurvey.c b/src/sp/protocol/survey0/xsurvey.c index 2a198662..3cb3b6bd 100644 --- a/src/sp/protocol/survey0/xsurvey.c +++ b/src/sp/protocol/survey0/xsurvey.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2021 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 @@ -54,7 +54,7 @@ xsurv0_sock_fini(void *arg) nni_mtx_fini(&s->mtx); } -static int +static void xsurv0_sock_init(void *arg, nni_sock *nsock) { xsurv0_sock *s = arg; @@ -67,8 +67,6 @@ xsurv0_sock_init(void *arg, nni_sock *nsock) s->urq = nni_sock_recvq(nsock); nni_atomic_init(&s->ttl); nni_atomic_set(&s->ttl, 8); - - return (0); } static void |
