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/pubsub0/sub.c | |
| 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/pubsub0/sub.c')
| -rw-r--r-- | src/sp/protocol/pubsub0/sub.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/sp/protocol/pubsub0/sub.c b/src/sp/protocol/pubsub0/sub.c index 35b32af4..10f42724 100644 --- a/src/sp/protocol/pubsub0/sub.c +++ b/src/sp/protocol/pubsub0/sub.c @@ -27,7 +27,7 @@ #define NNI_PROTO_PUB_V0 NNI_PROTO(2, 0) #endif -// By default we accept 128 messages. +// By default, we accept 128 messages. #define SUB0_DEFAULT_RECV_BUF_LEN 128 // By default, prefer new messages when the queue is full. @@ -175,7 +175,7 @@ sub0_ctx_fini(void *arg) nni_lmq_fini(&ctx->lmq); } -static int +static void sub0_ctx_init(void *ctx_arg, void *sock_arg) { sub0_sock *sock = sock_arg; @@ -198,8 +198,6 @@ sub0_ctx_init(void *ctx_arg, void *sock_arg) nni_list_append(&sock->contexts, ctx); sock->num_contexts++; nni_mtx_unlock(&sock->lk); - - return (0); } static void @@ -212,11 +210,10 @@ sub0_sock_fini(void *arg) nni_mtx_fini(&sock->lk); } -static int +static void sub0_sock_init(void *arg, nni_sock *unused) { sub0_sock *sock = arg; - int rv; NNI_ARG_UNUSED(unused); @@ -226,12 +223,7 @@ sub0_sock_init(void *arg, nni_sock *unused) sock->prefer_new = SUB0_DEFAULT_PREFER_NEW; nni_pollable_init(&sock->readable); - if ((rv = sub0_ctx_init(&sock->master, sock)) != 0) { - sub0_sock_fini(sock); - return (rv); - } - - return (0); + sub0_ctx_init(&sock->master, sock); } static void @@ -456,7 +448,7 @@ sub0_ctx_set_recv_buf_len(void *arg, const void *buf, size_t sz, nni_type t) return (0); } -// For now we maintain subscriptions on a sorted linked list. As we do not +// For now, we maintain subscriptions on a sorted linked list. As we do not // expect to have huge numbers of subscriptions, and as the operation is // really O(n), we think this is acceptable. In the future we might decide // to replace this with a patricia trie, like old nanomsg had. |
