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/core | |
| 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/core')
| -rw-r--r-- | src/core/protocol.h | 4 | ||||
| -rw-r--r-- | src/core/socket.c | 34 |
2 files changed, 17 insertions, 21 deletions
diff --git a/src/core/protocol.h b/src/core/protocol.h index a8645763..6118a2ac 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -63,7 +63,7 @@ struct nni_proto_ctx_ops { // ctx_init initializes a new context. The second argument is the // protocol specific socket structure. - int (*ctx_init)(void *, void *); + void (*ctx_init)(void *, void *); // ctx_fini destroys a context. void (*ctx_fini)(void *); @@ -85,7 +85,7 @@ struct nni_proto_sock_ops { // sock_init initializes the protocol instance, which will be stored // on the socket. This is run without the sock lock held. - int (*sock_init)(void *, nni_sock *); + void (*sock_init)(void *, nni_sock *); // sock_fini destroys the protocol instance. This is run without the // socket lock held, and is intended to release resources. It may diff --git a/src/core/socket.c b/src/core/socket.c index a8850b5d..425499ae 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -577,25 +577,26 @@ nni_sock_create(nni_sock **sp, const nni_proto *proto) #endif if (((rv = nni_msgq_init(&s->s_uwq, 0)) != 0) || - ((rv = nni_msgq_init(&s->s_urq, 1)) != 0) || - ((rv = s->s_sock_ops.sock_init(s->s_data, s)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_SENDTIMEO, &s->s_sndtimeo, - sizeof(nni_duration), NNI_TYPE_DURATION)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECVTIMEO, &s->s_rcvtimeo, - sizeof(nni_duration), NNI_TYPE_DURATION)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECONNMINT, &s->s_reconn, - sizeof(nni_duration), NNI_TYPE_DURATION)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECONNMAXT, &s->s_reconnmax, - sizeof(nni_duration), NNI_TYPE_DURATION)) != 0) || - ((rv = nni_sock_setopt(s, NNG_OPT_RECVMAXSZ, &s->s_rcvmaxsz, - sizeof(size_t), NNI_TYPE_SIZE)) != 0)) { + ((rv = nni_msgq_init(&s->s_urq, 1)) != 0)) { sock_destroy(s); return (rv); } + s->s_sock_ops.sock_init(s->s_data, s); - // These we *attempt* to call so that we are likely to have initial + // These we *attempt* to set so that we are likely to have initial // values loaded. They should not fail, but if they do we don't // worry about it. + (void) nni_sock_setopt(s, NNG_OPT_SENDTIMEO, &s->s_sndtimeo, + sizeof(nni_duration), NNI_TYPE_DURATION); + (void) nni_sock_setopt(s, NNG_OPT_RECVTIMEO, &s->s_rcvtimeo, + sizeof(nni_duration), NNI_TYPE_DURATION); + (void) nni_sock_setopt(s, NNG_OPT_RECONNMINT, &s->s_reconn, + sizeof(nni_duration), NNI_TYPE_DURATION); + (void) nni_sock_setopt(s, NNG_OPT_RECONNMAXT, &s->s_reconnmax, + sizeof(nni_duration), NNI_TYPE_DURATION); + (void) nni_sock_setopt(s, NNG_OPT_RECVMAXSZ, &s->s_rcvmaxsz, + sizeof(size_t), NNI_TYPE_SIZE); + on = true; (void) nni_sock_setopt( s, NNG_OPT_TCP_NODELAY, &on, sizeof(on), NNI_TYPE_BOOL); @@ -1292,12 +1293,7 @@ nni_ctx_open(nni_ctx **ctxp, nni_sock *sock) return (rv); } - if ((rv = sock->s_ctx_ops.ctx_init(ctx->c_data, sock->s_data)) != 0) { - nni_id_remove(&ctx_ids, ctx->c_id); - nni_mtx_unlock(&sock_lk); - nni_free(ctx, ctx->c_size); - return (rv); - } + sock->s_ctx_ops.ctx_init(ctx->c_data, sock->s_data); nni_list_append(&sock->s_ctxs, ctx); nni_mtx_unlock(&sock_lk); |
