From bcc3814b58e9b198344bdaf6e7a916a354841275 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 3 Jan 2020 18:03:57 -0800 Subject: fixes #1104 move allocation of protocol objects to common core fixes #1103 respondent could inline backtrace --- src/protocol/pubsub0/pub.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src/protocol/pubsub0/pub.c') diff --git a/src/protocol/pubsub0/pub.c b/src/protocol/pubsub0/pub.c index c54274a6..22195c52 100644 --- a/src/protocol/pubsub0/pub.c +++ b/src/protocol/pubsub0/pub.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -63,27 +63,21 @@ pub0_sock_fini(void *arg) nni_pollable_free(s->sendable); nni_mtx_fini(&s->mtx); - NNI_FREE_STRUCT(s); } static int -pub0_sock_init(void **sp, nni_sock *nsock) +pub0_sock_init(void *arg, nni_sock *nsock) { - pub0_sock *sock; + pub0_sock *sock = arg; int rv; NNI_ARG_UNUSED(nsock); - if ((sock = NNI_ALLOC_STRUCT(sock)) == NULL) { - return (NNG_ENOMEM); - } if ((rv = nni_pollable_alloc(&sock->sendable)) != 0) { - NNI_FREE_STRUCT(sock); return (rv); } nni_mtx_init(&sock->mtx); NNI_LIST_INIT(&sock->pipes, pub0_pipe, node); sock->sendbuf = 16; // fairly arbitrary - *sp = sock; return (0); } @@ -120,21 +114,16 @@ pub0_pipe_fini(void *arg) nni_aio_fini(p->aio_send); nni_aio_fini(p->aio_recv); nni_lmq_fini(&p->sendq); - NNI_FREE_STRUCT(p); } static int -pub0_pipe_init(void **pp, nni_pipe *pipe, void *s) +pub0_pipe_init(void *arg, nni_pipe *pipe, void *s) { - pub0_pipe *p; + pub0_pipe *p = arg; pub0_sock *sock = s; int rv; size_t len; - if ((p = NNI_ALLOC_STRUCT(p)) == NULL) { - return (NNG_ENOMEM); - } - nni_mtx_lock(&sock->mtx); len = sock->sendbuf; nni_mtx_unlock(&sock->mtx); @@ -151,7 +140,6 @@ pub0_pipe_init(void **pp, nni_pipe *pipe, void *s) p->busy = false; p->pipe = pipe; p->pub = s; - *pp = p; return (0); } @@ -352,6 +340,7 @@ pub0_sock_get_sendbuf(void *arg, void *buf, size_t *szp, nni_type t) } static nni_proto_pipe_ops pub0_pipe_ops = { + .pipe_size = sizeof (pub0_pipe), .pipe_init = pub0_pipe_init, .pipe_fini = pub0_pipe_fini, .pipe_start = pub0_pipe_start, @@ -376,6 +365,7 @@ static nni_option pub0_sock_options[] = { }; static nni_proto_sock_ops pub0_sock_ops = { + .sock_size = sizeof (pub0_sock), .sock_init = pub0_sock_init, .sock_fini = pub0_sock_fini, .sock_open = pub0_sock_open, -- cgit v1.2.3-70-g09d2