diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-15 21:59:55 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-16 18:31:42 -0700 |
| commit | a9633313ec8e578c805cd53b37ba3360d83157bc (patch) | |
| tree | 14d32c4031ea1c8508a75469407ca77e353fa315 /src/protocol | |
| parent | e7e2a6c14f0317eb77711951c6f1a650d4013dfe (diff) | |
| download | nng-a9633313ec8e578c805cd53b37ba3360d83157bc.tar.gz nng-a9633313ec8e578c805cd53b37ba3360d83157bc.tar.bz2 nng-a9633313ec8e578c805cd53b37ba3360d83157bc.zip | |
Provide versions of mutex, condvar, and aio init that never fail.
If the underlying platform fails (FreeBSD is the only one I'm aware
of that does this!), we use a global lock or condition variable instead.
This means that our lock initializers never ever fail.
Probably we could eliminate most of this for Linux and Darwin, since
on those platforms, mutex and condvar initialization reasonably never
fails. Initial benchmarks show little difference either way -- so we
can revisit (optimize) later.
This removes a lot of otherwise untested code in error cases and so forth,
improving coverage and resilience in the face of allocation failures.
Platforms other than POSIX should follow a similar pattern if they need
this. (VxWorks, I'm thinking of you.) Most sane platforms won't have
an issue here, since normally these initializations do not need to allocate
memory. (Reportedly, even FreeBSD has plans to "fix" this in libthr2.)
While here, some bugs were fixed in initialization & teardown.
The fallback code is properly tested with dedicated test cases.
Diffstat (limited to 'src/protocol')
| -rw-r--r-- | src/protocol/bus/bus.c | 57 | ||||
| -rw-r--r-- | src/protocol/pair/pair_v0.c | 27 | ||||
| -rw-r--r-- | src/protocol/pair/pair_v1.c | 50 | ||||
| -rw-r--r-- | src/protocol/pipeline/pull.c | 13 | ||||
| -rw-r--r-- | src/protocol/pipeline/push.c | 17 | ||||
| -rw-r--r-- | src/protocol/pubsub/pub.c | 36 | ||||
| -rw-r--r-- | src/protocol/pubsub/sub.c | 9 | ||||
| -rw-r--r-- | src/protocol/reqrep/rep.c | 46 | ||||
| -rw-r--r-- | src/protocol/reqrep/req.c | 42 | ||||
| -rw-r--r-- | src/protocol/survey/respond.c | 48 | ||||
| -rw-r--r-- | src/protocol/survey/survey.c | 43 |
11 files changed, 113 insertions, 275 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c index 79d7187e..88fd93e0 100644 --- a/src/protocol/bus/bus.c +++ b/src/protocol/bus/bus.c @@ -59,40 +59,28 @@ nni_bus_sock_fini(void *arg) { nni_bus_sock *psock = arg; - if (psock != NULL) { - nni_aio_stop(&psock->aio_getq); - nni_aio_fini(&psock->aio_getq); - nni_mtx_fini(&psock->mtx); - NNI_FREE_STRUCT(psock); - } + nni_aio_stop(&psock->aio_getq); + nni_aio_fini(&psock->aio_getq); + nni_mtx_fini(&psock->mtx); + NNI_FREE_STRUCT(psock); } static int nni_bus_sock_init(void **sp, nni_sock *nsock) { nni_bus_sock *psock; - int rv; if ((psock = NNI_ALLOC_STRUCT(psock)) == NULL) { return (NNG_ENOMEM); } NNI_LIST_INIT(&psock->pipes, nni_bus_pipe, node); - if ((rv = nni_mtx_init(&psock->mtx)) != 0) { - goto fail; - } - rv = nni_aio_init(&psock->aio_getq, nni_bus_sock_getq_cb, psock); - if (rv != 0) { - goto fail; - } + nni_mtx_init(&psock->mtx); + nni_aio_init(&psock->aio_getq, nni_bus_sock_getq_cb, psock); psock->nsock = nsock; psock->raw = 0; *sp = psock; return (0); - -fail: - nni_bus_sock_fini(psock); - return (rv); } static void @@ -134,36 +122,21 @@ nni_bus_pipe_init(void **pp, nni_pipe *npipe, void *psock) if ((ppipe = NNI_ALLOC_STRUCT(ppipe)) == NULL) { return (NNG_ENOMEM); } - NNI_LIST_NODE_INIT(&ppipe->node); - if (((rv = nni_mtx_init(&ppipe->mtx)) != 0) || - ((rv = nni_msgq_init(&ppipe->sendq, 16)) != 0)) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_getq, nni_bus_pipe_getq_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_send, nni_bus_pipe_send_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_recv, nni_bus_pipe_recv_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_putq, nni_bus_pipe_putq_cb, ppipe); - if (rv != 0) { - goto fail; + if ((rv = nni_msgq_init(&ppipe->sendq, 16)) != 0) { + NNI_FREE_STRUCT(ppipe); + return (rv); } + NNI_LIST_NODE_INIT(&ppipe->node); + nni_mtx_init(&ppipe->mtx); + nni_aio_init(&ppipe->aio_getq, nni_bus_pipe_getq_cb, ppipe); + nni_aio_init(&ppipe->aio_send, nni_bus_pipe_send_cb, ppipe); + nni_aio_init(&ppipe->aio_recv, nni_bus_pipe_recv_cb, ppipe); + nni_aio_init(&ppipe->aio_putq, nni_bus_pipe_putq_cb, ppipe); ppipe->npipe = npipe; ppipe->psock = psock; *pp = ppipe; return (0); - -fail: - nni_bus_pipe_fini(ppipe); - return (rv); } static int diff --git a/src/protocol/pair/pair_v0.c b/src/protocol/pair/pair_v0.c index a0e907f2..acf9ec25 100644 --- a/src/protocol/pair/pair_v0.c +++ b/src/protocol/pair/pair_v0.c @@ -53,15 +53,11 @@ static int pair0_sock_init(void **sp, nni_sock *nsock) { pair0_sock *s; - int rv; if ((s = NNI_ALLOC_STRUCT(s)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&s->mtx)) != 0) { - NNI_FREE_STRUCT(s); - return (rv); - } + nni_mtx_init(&s->mtx); s->nsock = nsock; s->ppipe = NULL; s->raw = 0; @@ -84,22 +80,19 @@ static int pair0_pipe_init(void **pp, nni_pipe *npipe, void *psock) { pair0_pipe *p; - int rv; if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { return (NNG_ENOMEM); } - if (((rv = nni_aio_init(&p->aio_send, pair0_send_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_recv, pair0_recv_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_getq, pair0_getq_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_putq, pair0_putq_cb, p)) != 0)) { - pair0_pipe_fini(p); - } else { - p->npipe = npipe; - p->psock = psock; - *pp = p; - } - return (rv); + nni_aio_init(&p->aio_send, pair0_send_cb, p); + nni_aio_init(&p->aio_recv, pair0_recv_cb, p); + nni_aio_init(&p->aio_getq, pair0_getq_cb, p); + nni_aio_init(&p->aio_putq, pair0_putq_cb, p); + + p->npipe = npipe; + p->psock = psock; + *pp = p; + return (0); } static void diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c index 1a7ad9fa..2b8a9120 100644 --- a/src/protocol/pair/pair_v1.c +++ b/src/protocol/pair/pair_v1.c @@ -73,22 +73,24 @@ pair1_sock_init(void **sp, nni_sock *nsock) if ((s = NNI_ALLOC_STRUCT(s)) == NULL) { return (NNG_ENOMEM); } + if ((rv = nni_idhash_init(&s->pipes)) != 0) { + NNI_FREE_STRUCT(s); + return (NNG_ENOMEM); + } NNI_LIST_INIT(&s->plist, pair1_pipe, node); // Raw mode uses this. - if (((rv = nni_aio_init(&s->aio_getq, pair1_sock_getq_cb, s)) != 0) || - ((rv = nni_mtx_init(&s->mtx)) != 0) || - ((rv = nni_idhash_init(&s->pipes)) != 0)) { - pair1_sock_fini(s); - } else { - s->nsock = nsock; - s->raw = 0; - s->poly = 0; - s->uwq = nni_sock_sendq(nsock); - s->urq = nni_sock_recvq(nsock); - s->ttl = 8; - *sp = s; - } + nni_aio_init(&s->aio_getq, pair1_sock_getq_cb, s); + nni_mtx_init(&s->mtx); + + s->nsock = nsock; + s->raw = 0; + s->poly = 0; + s->uwq = nni_sock_sendq(nsock); + s->urq = nni_sock_recvq(nsock); + s->ttl = 8; + *sp = s; + return (0); } @@ -101,17 +103,19 @@ pair1_pipe_init(void **pp, nni_pipe *npipe, void *psock) if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { return (NNG_ENOMEM); } - if (((rv = nni_msgq_init(&p->sendq, 2)) != 0) || - ((rv = nni_aio_init(&p->aio_send, pair1_pipe_send_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_recv, pair1_pipe_recv_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_getq, pair1_pipe_getq_cb, p)) != 0) || - ((rv = nni_aio_init(&p->aio_putq, pair1_pipe_putq_cb, p)) != 0)) { - pair1_pipe_fini(p); - } else { - p->npipe = npipe; - p->psock = psock; - *pp = p; + if ((rv = nni_msgq_init(&p->sendq, 2)) != 0) { + NNI_FREE_STRUCT(p); + return (NNG_ENOMEM); } + nni_aio_init(&p->aio_send, pair1_pipe_send_cb, p); + nni_aio_init(&p->aio_recv, pair1_pipe_recv_cb, p); + nni_aio_init(&p->aio_getq, pair1_pipe_getq_cb, p); + nni_aio_init(&p->aio_putq, pair1_pipe_putq_cb, p); + + p->npipe = npipe; + p->psock = psock; + *pp = p; + return (rv); } diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c index e3c73342..1ebcc4a2 100644 --- a/src/protocol/pipeline/pull.c +++ b/src/protocol/pipeline/pull.c @@ -63,20 +63,13 @@ static int nni_pull_pipe_init(void **ppp, nni_pipe *pipe, void *psock) { nni_pull_pipe *pp; - int rv; if ((pp = NNI_ALLOC_STRUCT(pp)) == NULL) { return (NNG_ENOMEM); } - if (((rv = nni_aio_init(&pp->putq_aio, nni_pull_putq_cb, pp))) != 0) { - NNI_FREE_STRUCT(pp); - return (rv); - } - if (((rv = nni_aio_init(&pp->recv_aio, nni_pull_recv_cb, pp))) != 0) { - nni_aio_fini(&pp->putq_aio); - NNI_FREE_STRUCT(pp); - return (rv); - } + nni_aio_init(&pp->putq_aio, nni_pull_putq_cb, pp); + nni_aio_init(&pp->recv_aio, nni_pull_recv_cb, pp); + pp->pipe = pipe; pp->pull = psock; *ppp = pp; diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c index 14b3b191..1bc1659c 100644 --- a/src/protocol/pipeline/push.c +++ b/src/protocol/pipeline/push.c @@ -93,30 +93,19 @@ static int nni_push_pipe_init(void **ppp, nni_pipe *pipe, void *psock) { nni_push_pipe *pp; - int rv; if ((pp = NNI_ALLOC_STRUCT(pp)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_aio_init(&pp->aio_recv, nni_push_recv_cb, pp)) != 0) { - goto fail; - } - if ((rv = nni_aio_init(&pp->aio_send, nni_push_send_cb, pp)) != 0) { - goto fail; - } - if ((rv = nni_aio_init(&pp->aio_getq, nni_push_getq_cb, pp)) != 0) { - goto fail; - } + nni_aio_init(&pp->aio_recv, nni_push_recv_cb, pp); + nni_aio_init(&pp->aio_send, nni_push_send_cb, pp); + nni_aio_init(&pp->aio_getq, nni_push_getq_cb, pp); NNI_LIST_NODE_INIT(&pp->node); pp->pipe = pipe; pp->push = psock; *ppp = pp; return (0); - -fail: - nni_push_pipe_fini(pp); - return (rv); } static int diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c index 161a5d79..940f2139 100644 --- a/src/protocol/pubsub/pub.c +++ b/src/protocol/pubsub/pub.c @@ -53,20 +53,13 @@ static int nni_pub_sock_init(void **pubp, nni_sock *sock) { nni_pub_sock *pub; - int rv; if ((pub = NNI_ALLOC_STRUCT(pub)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&pub->mtx)) != 0) { - nni_pub_sock_fini(pub); - return (rv); - } - rv = nni_aio_init(&pub->aio_getq, nni_pub_sock_getq_cb, pub); - if (rv != 0) { - nni_pub_sock_fini(pub); - return (rv); - } + nni_mtx_init(&pub->mtx); + nni_aio_init(&pub->aio_getq, nni_pub_sock_getq_cb, pub); + pub->sock = sock; pub->raw = 0; NNI_LIST_INIT(&pub->pipes, nni_pub_pipe, node); @@ -127,31 +120,18 @@ nni_pub_pipe_init(void **ppp, nni_pipe *pipe, void *psock) } // XXX: consider making this depth tunable if ((rv = nni_msgq_init(&pp->sendq, 16)) != 0) { - goto fail; - } - - rv = nni_aio_init(&pp->aio_getq, nni_pub_pipe_getq_cb, pp); - if (rv != 0) { - goto fail; + NNI_FREE_STRUCT(pp); + return (rv); } - rv = nni_aio_init(&pp->aio_send, nni_pub_pipe_send_cb, pp); - if (rv != 0) { - goto fail; - } + nni_aio_init(&pp->aio_getq, nni_pub_pipe_getq_cb, pp); + nni_aio_init(&pp->aio_send, nni_pub_pipe_send_cb, pp); + nni_aio_init(&pp->aio_recv, nni_pub_pipe_recv_cb, pp); - rv = nni_aio_init(&pp->aio_recv, nni_pub_pipe_recv_cb, pp); - if (rv != 0) { - goto fail; - } pp->pipe = pipe; pp->pub = psock; *ppp = pp; return (0); - -fail: - nni_pub_pipe_fini(pp); - return (rv); } static int diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c index 53f01e0f..78b9d157 100644 --- a/src/protocol/pubsub/sub.c +++ b/src/protocol/pubsub/sub.c @@ -95,16 +95,13 @@ static int nni_sub_pipe_init(void **spp, nni_pipe *pipe, void *ssock) { nni_sub_pipe *sp; - int rv; if ((sp = NNI_ALLOC_STRUCT(sp)) == NULL) { return (NNG_ENOMEM); } - if (((rv = nni_aio_init(&sp->aio_putq, nni_sub_putq_cb, sp)) != 0) || - ((rv = nni_aio_init(&sp->aio_recv, nni_sub_recv_cb, sp)) != 0)) { - nni_sub_pipe_fini(sp); - return (rv); - } + nni_aio_init(&sp->aio_putq, nni_sub_putq_cb, sp); + nni_aio_init(&sp->aio_recv, nni_sub_recv_cb, sp); + sp->pipe = pipe; sp->sub = ssock; *spp = sp; diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c index 4319cbf8..09f2b285 100644 --- a/src/protocol/reqrep/rep.c +++ b/src/protocol/reqrep/rep.c @@ -74,20 +74,18 @@ nni_rep_sock_init(void **repp, nni_sock *sock) if ((rep = NNI_ALLOC_STRUCT(rep)) == NULL) { return (NNG_ENOMEM); } + if ((rv = nni_idhash_init(&rep->pipes)) != 0) { + NNI_FREE_STRUCT(rep); + return (rv); + } + rep->ttl = 8; // Per RFC rep->sock = sock; rep->raw = 0; rep->btrace = NULL; rep->btrace_len = 0; - if ((rv = nni_idhash_init(&rep->pipes)) != 0) { - goto fail; - } - - rv = nni_aio_init(&rep->aio_getq, nni_rep_sock_getq_cb, rep); - if (rv != 0) { - goto fail; - } + nni_aio_init(&rep->aio_getq, nni_rep_sock_getq_cb, rep); rep->uwq = nni_sock_sendq(sock); rep->urq = nni_sock_recvq(sock); @@ -96,10 +94,6 @@ nni_rep_sock_init(void **repp, nni_sock *sock) nni_sock_senderr(sock, NNG_ESTATE); return (0); - -fail: - nni_rep_sock_fini(rep); - return (rv); } static void @@ -128,32 +122,18 @@ nni_rep_pipe_init(void **rpp, nni_pipe *pipe, void *rsock) return (NNG_ENOMEM); } if ((rv = nni_msgq_init(&rp->sendq, 2)) != 0) { - goto fail; - } - if ((rv = nni_aio_init(&rp->aio_getq, nni_rep_pipe_getq_cb, rp)) != - 0) { - goto fail; - } - if ((rv = nni_aio_init(&rp->aio_send, nni_rep_pipe_send_cb, rp)) != - 0) { - goto fail; - } - if ((rv = nni_aio_init(&rp->aio_recv, nni_rep_pipe_recv_cb, rp)) != - 0) { - goto fail; - } - if ((rv = nni_aio_init(&rp->aio_putq, nni_rep_pipe_putq_cb, rp)) != - 0) { - goto fail; + NNI_FREE_STRUCT(rp); + return (rv); } + nni_aio_init(&rp->aio_getq, nni_rep_pipe_getq_cb, rp); + nni_aio_init(&rp->aio_send, nni_rep_pipe_send_cb, rp); + nni_aio_init(&rp->aio_recv, nni_rep_pipe_recv_cb, rp); + nni_aio_init(&rp->aio_putq, nni_rep_pipe_putq_cb, rp); + rp->pipe = pipe; rp->rep = rsock; *rpp = rp; return (0); - -fail: - nni_rep_pipe_fini(rp); - return (rv); } static void diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c index fdf29fd9..bab81331 100644 --- a/src/protocol/reqrep/req.c +++ b/src/protocol/reqrep/req.c @@ -75,19 +75,12 @@ static int nni_req_sock_init(void **reqp, nni_sock *sock) { nni_req_sock *req; - int rv; if ((req = NNI_ALLOC_STRUCT(req)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&req->mtx)) != 0) { - NNI_FREE_STRUCT(req); - return (rv); - } - if ((rv = nni_cv_init(&req->cv, &req->mtx)) != 0) { - nni_mtx_fini(&req->mtx); - NNI_FREE_STRUCT(req); - } + nni_mtx_init(&req->mtx); + nni_cv_init(&req->cv, &req->mtx); NNI_LIST_INIT(&req->readypipes, nni_req_pipe, node); NNI_LIST_INIT(&req->busypipes, nni_req_pipe, node); @@ -152,41 +145,22 @@ static int nni_req_pipe_init(void **rpp, nni_pipe *pipe, void *rsock) { nni_req_pipe *rp; - int rv; if ((rp = NNI_ALLOC_STRUCT(rp)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&rp->mtx)) != 0) { - goto failed; - } - if ((rv = nni_aio_init(&rp->aio_getq, nni_req_getq_cb, rp)) != 0) { - goto failed; - } - if ((rv = nni_aio_init(&rp->aio_putq, nni_req_putq_cb, rp)) != 0) { - goto failed; - } - if ((rv = nni_aio_init(&rp->aio_recv, nni_req_recv_cb, rp)) != 0) { - goto failed; - } - rv = nni_aio_init(&rp->aio_sendraw, nni_req_sendraw_cb, rp); - if (rv != 0) { - goto failed; - } - rv = nni_aio_init(&rp->aio_sendcooked, nni_req_sendcooked_cb, rp); - if (rv != 0) { - goto failed; - } + nni_mtx_init(&rp->mtx); + nni_aio_init(&rp->aio_getq, nni_req_getq_cb, rp); + nni_aio_init(&rp->aio_putq, nni_req_putq_cb, rp); + nni_aio_init(&rp->aio_recv, nni_req_recv_cb, rp); + nni_aio_init(&rp->aio_sendraw, nni_req_sendraw_cb, rp); + nni_aio_init(&rp->aio_sendcooked, nni_req_sendcooked_cb, rp); NNI_LIST_NODE_INIT(&rp->node); rp->pipe = pipe; rp->req = rsock; *rpp = rp; return (0); - -failed: - nni_req_pipe_fini(rp); - return (rv); } static void diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c index 32513134..a097f551 100644 --- a/src/protocol/survey/respond.c +++ b/src/protocol/survey/respond.c @@ -77,6 +77,11 @@ nni_resp_sock_init(void **pp, nni_sock *nsock) if ((psock = NNI_ALLOC_STRUCT(psock)) == NULL) { return (NNG_ENOMEM); } + if ((rv = nni_idhash_init(&psock->pipes)) != 0) { + NNI_FREE_STRUCT(psock); + return (rv); + } + psock->ttl = 8; // Per RFC psock->nsock = nsock; psock->raw = 0; @@ -85,24 +90,12 @@ nni_resp_sock_init(void **pp, nni_sock *nsock) psock->urq = nni_sock_recvq(nsock); psock->uwq = nni_sock_sendq(nsock); - if ((rv = nni_mtx_init(&psock->mtx)) != 0) { - goto fail; - } - if ((rv = nni_idhash_init(&psock->pipes)) != 0) { - goto fail; - } - rv = nni_aio_init(&psock->aio_getq, nni_resp_sock_getq_cb, psock); - if (rv != 0) { - goto fail; - } + nni_mtx_init(&psock->mtx); + nni_aio_init(&psock->aio_getq, nni_resp_sock_getq_cb, psock); *pp = psock; nni_sock_senderr(nsock, NNG_ESTATE); return (0); - -fail: - nni_resp_sock_fini(psock); - return (rv); } static void @@ -131,33 +124,18 @@ nni_resp_pipe_init(void **pp, nni_pipe *npipe, void *psock) return (NNG_ENOMEM); } if ((rv = nni_msgq_init(&ppipe->sendq, 2)) != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_putq, nni_resp_putq_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_recv, nni_resp_recv_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_getq, nni_resp_getq_cb, ppipe); - if (rv != 0) { - goto fail; - } - rv = nni_aio_init(&ppipe->aio_send, nni_resp_send_cb, ppipe); - if (rv != 0) { - goto fail; + NNI_FREE_STRUCT(ppipe); + return (rv); } + nni_aio_init(&ppipe->aio_putq, nni_resp_putq_cb, ppipe); + nni_aio_init(&ppipe->aio_recv, nni_resp_recv_cb, ppipe); + nni_aio_init(&ppipe->aio_getq, nni_resp_getq_cb, ppipe); + nni_aio_init(&ppipe->aio_send, nni_resp_send_cb, ppipe); ppipe->npipe = npipe; ppipe->psock = psock; *pp = ppipe; return (0); - -fail: - nni_resp_pipe_fini(ppipe); - return (rv); } static void diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c index cb90c13f..2a32f289 100644 --- a/src/protocol/survey/survey.c +++ b/src/protocol/survey/survey.c @@ -70,19 +70,13 @@ static int nni_surv_sock_init(void **sp, nni_sock *nsock) { nni_surv_sock *psock; - int rv; if ((psock = NNI_ALLOC_STRUCT(psock)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&psock->mtx)) != 0) { - goto fail; - } - rv = nni_aio_init(&psock->aio_getq, nni_surv_sock_getq_cb, psock); - if (rv != 0) { - goto fail; - } NNI_LIST_INIT(&psock->pipes, nni_surv_pipe, node); + nni_mtx_init(&psock->mtx); + nni_aio_init(&psock->aio_getq, nni_surv_sock_getq_cb, psock); nni_timer_init(&psock->timer, nni_surv_timeout, psock); psock->nextid = nni_random(); @@ -96,10 +90,6 @@ nni_surv_sock_init(void **sp, nni_sock *nsock) *sp = psock; nni_sock_recverr(nsock, NNG_ESTATE); return (0); - -fail: - nni_surv_sock_fini(psock); - return (rv); } static void @@ -143,32 +133,19 @@ nni_surv_pipe_init(void **pp, nni_pipe *npipe, void *psock) } // This depth could be tunable. if ((rv = nni_msgq_init(&ppipe->sendq, 16)) != 0) { - goto failed; - } - rv = nni_aio_init(&ppipe->aio_getq, nni_surv_getq_cb, ppipe); - if (rv != 0) { - goto failed; - } - rv = nni_aio_init(&ppipe->aio_putq, nni_surv_putq_cb, ppipe); - if (rv != 0) { - goto failed; - } - rv = nni_aio_init(&ppipe->aio_send, nni_surv_send_cb, ppipe); - if (rv != 0) { - goto failed; - } - rv = nni_aio_init(&ppipe->aio_recv, nni_surv_recv_cb, ppipe); - if (rv != 0) { - goto failed; + NNI_FREE_STRUCT(ppipe); + return (rv); } + + nni_aio_init(&ppipe->aio_getq, nni_surv_getq_cb, ppipe); + nni_aio_init(&ppipe->aio_putq, nni_surv_putq_cb, ppipe); + nni_aio_init(&ppipe->aio_send, nni_surv_send_cb, ppipe); + nni_aio_init(&ppipe->aio_recv, nni_surv_recv_cb, ppipe); + ppipe->npipe = npipe; ppipe->psock = psock; *pp = ppipe; return (0); - -failed: - nni_surv_pipe_fini(ppipe); - return (rv); } static int |
