From 47eed71eee292ea5fafd140b4364ce4c509a1a1d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:27:36 -0800 Subject: [PATCH 1/6] tcp: implement ep stop --- src/sp/transport/tcp/tcp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index a32ee7a83..2497b899f 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -667,6 +667,15 @@ tcptran_pipe_start(tcptran_pipe *p, nng_stream *conn, tcptran_ep *ep) nng_stream_send(p->conn, p->negoaio); } +static void +tcptran_ep_stop(void *arg) +{ + tcptran_ep *ep = arg; + + nni_aio_stop(ep->timeaio); + nni_aio_stop(ep->connaio); +} + static void tcptran_ep_fini(void *arg) { @@ -679,8 +688,6 @@ tcptran_ep_fini(void *arg) return; } nni_mtx_unlock(&ep->mtx); - nni_aio_stop(ep->timeaio); - nni_aio_stop(ep->connaio); nng_stream_dialer_free(ep->dialer); nng_stream_listener_free(ep->listener); nni_aio_free(ep->timeaio); @@ -1139,6 +1146,7 @@ static nni_sp_dialer_ops tcptran_dialer_ops = { .d_fini = tcptran_ep_fini, .d_connect = tcptran_ep_connect, .d_close = tcptran_ep_close, + .d_stop = tcptran_ep_stop, .d_getopt = tcptran_dialer_getopt, .d_setopt = tcptran_dialer_setopt, }; @@ -1149,6 +1157,7 @@ static nni_sp_listener_ops tcptran_listener_ops = { .l_bind = tcptran_ep_bind, .l_accept = tcptran_ep_accept, .l_close = tcptran_ep_close, + .l_stop = tcptran_ep_stop, .l_getopt = tcptran_listener_getopt, .l_setopt = tcptran_listener_setopt, }; From 3b663bb405f603305c12c1dbcf0dba561b7e620b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:31:50 -0800 Subject: [PATCH 2/6] inproc: implement stub ep stop Inproc doesn't have any real need for action here, as it's simple, but the stub implementation will let us remove the check in the common code layer. --- src/sp/transport/inproc/inproc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sp/transport/inproc/inproc.c b/src/sp/transport/inproc/inproc.c index f8cdd2e64..373b9c877 100644 --- a/src/sp/transport/inproc/inproc.c +++ b/src/sp/transport/inproc/inproc.c @@ -334,6 +334,12 @@ inproc_listener_init(void **epp, nng_url *url, nni_listener *nlistener) return (0); } +static void +inproc_ep_stop(void *arg) +{ + NNI_ARG_UNUSED(arg); +} + static void inproc_ep_fini(void *arg) { @@ -669,6 +675,7 @@ static nni_sp_dialer_ops inproc_dialer_ops = { .d_fini = inproc_ep_fini, .d_connect = inproc_ep_connect, .d_close = inproc_ep_close, + .d_stop = inproc_ep_stop, .d_getopt = inproc_ep_getopt, .d_setopt = inproc_ep_setopt, }; @@ -679,6 +686,7 @@ static nni_sp_listener_ops inproc_listener_ops = { .l_bind = inproc_ep_bind, .l_accept = inproc_ep_accept, .l_close = inproc_ep_close, + .l_stop = inproc_ep_stop, .l_getopt = inproc_ep_getopt, .l_setopt = inproc_ep_setopt, }; From b1d1ded93c993ff8e2f913ad6148d0cd0caee045 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:33:47 -0800 Subject: [PATCH 3/6] tls: implement ep stop --- src/sp/transport/tls/tls.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c index 9d02b5282..7a907e8ed 100644 --- a/src/sp/transport/tls/tls.c +++ b/src/sp/transport/tls/tls.c @@ -641,8 +641,6 @@ tlstran_ep_fini(void *arg) return; } nni_mtx_unlock(&ep->mtx); - nni_aio_stop(ep->timeaio); - nni_aio_stop(ep->connaio); nng_stream_dialer_free(ep->dialer); nng_stream_listener_free(ep->listener); nni_aio_free(ep->timeaio); @@ -652,6 +650,15 @@ tlstran_ep_fini(void *arg) NNI_FREE_STRUCT(ep); } +static void +tlstran_ep_stop(void *arg) +{ + tlstran_ep *ep = arg; + + nni_aio_stop(ep->timeaio); + nni_aio_stop(ep->connaio); +} + static void tlstran_ep_close(void *arg) { @@ -1147,6 +1154,7 @@ static nni_sp_dialer_ops tlstran_dialer_ops = { .d_fini = tlstran_ep_fini, .d_connect = tlstran_ep_connect, .d_close = tlstran_ep_close, + .d_stop = tlstran_ep_stop, .d_getopt = tlstran_dialer_getopt, .d_setopt = tlstran_dialer_setopt, .d_get_tls = tlstran_dialer_get_tls, @@ -1159,6 +1167,7 @@ static nni_sp_listener_ops tlstran_listener_ops = { .l_bind = tlstran_ep_bind, .l_accept = tlstran_ep_accept, .l_close = tlstran_ep_close, + .l_stop = tlstran_ep_stop, .l_getopt = tlstran_listener_get, .l_setopt = tlstran_listener_set, .l_set_tls = tlstran_listener_set_tls, From c2de4a8fb5fb9659727fb182de17af57186e4a7a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:38:09 -0800 Subject: [PATCH 4/6] websocket: implement ep stop here While here renamed a couple of symbols to avoid conflation with the supplemental websocket functions of the same name. --- src/sp/transport/ws/websocket.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c index 805f19cf0..27cc64348 100644 --- a/src/sp/transport/ws/websocket.c +++ b/src/sp/transport/ws/websocket.c @@ -247,7 +247,7 @@ wstran_pipe_peer(void *arg) } static int -ws_listener_bind(void *arg, nng_url *url) +wstran_listener_bind(void *arg, nng_url *url) { ws_listener *l = arg; int rv; @@ -263,7 +263,7 @@ ws_listener_bind(void *arg, nng_url *url) } static void -ws_listener_cancel(nni_aio *aio, void *arg, int rv) +wstran_listener_cancel(nni_aio *aio, void *arg, int rv) { ws_listener *l = arg; @@ -288,7 +288,7 @@ wstran_listener_accept(void *arg, nni_aio *aio) return; } nni_mtx_lock(&l->mtx); - if ((rv = nni_aio_schedule(aio, ws_listener_cancel, l)) != 0) { + if ((rv = nni_aio_schedule(aio, wstran_listener_cancel, l)) != 0) { nni_mtx_unlock(&l->mtx); nni_aio_finish_error(aio, rv); return; @@ -368,11 +368,18 @@ static nni_sp_pipe_ops ws_pipe_ops = { }; static void -wstran_dialer_fini(void *arg) +wstran_dialer_stop(void *arg) { ws_dialer *d = arg; nni_aio_stop(&d->connaio); +} + +static void +wstran_dialer_fini(void *arg) +{ + ws_dialer *d = arg; + nng_stream_dialer_free(d->dialer); nni_aio_fini(&d->connaio); nni_mtx_fini(&d->mtx); @@ -380,11 +387,18 @@ wstran_dialer_fini(void *arg) } static void -wstran_listener_fini(void *arg) +wstran_listener_stop(void *arg) { ws_listener *l = arg; nni_aio_stop(&l->accaio); +} + +static void +wstran_listener_fini(void *arg) +{ + ws_listener *l = arg; + nng_stream_listener_free(l->listener); nni_aio_fini(&l->accaio); nni_mtx_fini(&l->mtx); @@ -656,6 +670,7 @@ static nni_sp_dialer_ops ws_dialer_ops = { .d_fini = wstran_dialer_fini, .d_connect = wstran_dialer_connect, .d_close = wstran_dialer_close, + .d_stop = wstran_dialer_stop, .d_setopt = wstran_dialer_setopt, .d_getopt = wstran_dialer_getopt, .d_get_tls = wstran_dialer_get_tls, @@ -665,9 +680,10 @@ static nni_sp_dialer_ops ws_dialer_ops = { static nni_sp_listener_ops ws_listener_ops = { .l_init = wstran_listener_init, .l_fini = wstran_listener_fini, - .l_bind = ws_listener_bind, + .l_bind = wstran_listener_bind, .l_accept = wstran_listener_accept, .l_close = wstran_listener_close, + .l_stop = wstran_listener_stop, .l_setopt = wstran_listener_set, .l_getopt = wstran_listener_get, .l_get_tls = wstran_listener_get_tls, From 7155676c0861b9f85e7a89a66dc1479085b8539b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:49:40 -0800 Subject: [PATCH 5/6] zerotier: implement ep stop --- src/sp/transport/zerotier/zerotier.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sp/transport/zerotier/zerotier.c b/src/sp/transport/zerotier/zerotier.c index 6e475c1a3..3dccd212c 100644 --- a/src/sp/transport/zerotier/zerotier.c +++ b/src/sp/transport/zerotier/zerotier.c @@ -2102,10 +2102,16 @@ zt_pipe_start_ping(zt_pipe *p) } static void -zt_ep_fini(void *arg) +zt_ep_stop(void *arg) { zt_ep *ep = arg; nni_aio_stop(ep->ze_creq_aio); +} + +static void +zt_ep_fini(void *arg) +{ + zt_ep *ep = arg; nni_aio_free(ep->ze_creq_aio); NNI_FREE_STRUCT(ep); } @@ -3177,6 +3183,7 @@ static nni_sp_dialer_ops zt_dialer_ops = { .d_fini = zt_ep_fini, .d_connect = zt_ep_connect, .d_close = zt_ep_close, + .d_stop = zt_ep_fini, .d_options = zt_dialer_options, }; @@ -3186,6 +3193,7 @@ static nni_sp_listener_ops zt_listener_ops = { .l_bind = zt_ep_bind, .l_accept = zt_ep_accept, .l_close = zt_ep_close, + .l_stop = zt_ep_stop, .l_options = zt_listener_options, }; From 90308d8a3651d163c08d4fae3cfda90c5292e812 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 11 Dec 2024 07:46:27 -0800 Subject: [PATCH 6/6] transports: all transports implement stop functions Add test cases ensuring that the transports implement all required functionality (entry points are not null). --- src/core/dialer.c | 4 +--- src/core/listener.c | 4 +--- src/sp/transport.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/core/dialer.c b/src/core/dialer.c index 6224ce9bb..4b0ad615f 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -544,9 +544,7 @@ nni_dialer_stop(nni_dialer *d) d->d_ops.d_close(d->d_data); nni_aio_stop(&d->d_tmo_aio); nni_aio_stop(&d->d_con_aio); - if (d->d_ops.d_stop) { - d->d_ops.d_stop(d->d_data); - } + d->d_ops.d_stop(d->d_data); } nni_sock * diff --git a/src/core/listener.c b/src/core/listener.c index 1eeaa3cde..28b7bc6f7 100644 --- a/src/core/listener.c +++ b/src/core/listener.c @@ -527,9 +527,7 @@ nni_listener_stop(nni_listener *l) l->l_ops.l_close(l->l_data); nni_aio_stop(&l->l_tmo_aio); nni_aio_stop(&l->l_acc_aio); - if (l->l_ops.l_stop) { - l->l_ops.l_stop(l->l_data); - } + l->l_ops.l_stop(l->l_data); } nni_sock * diff --git a/src/sp/transport.c b/src/sp/transport.c index 919a0f374..178cc7489 100644 --- a/src/sp/transport.c +++ b/src/sp/transport.c @@ -21,6 +21,37 @@ static nni_rwlock sp_tran_lk = NNI_RWLOCK_INITIALIZER; void nni_sp_tran_register(nni_sp_tran *tran) { +#ifndef NDEBUG + NNI_ASSERT(tran->tran_pipe->p_init != NULL); + NNI_ASSERT(tran->tran_pipe->p_fini != NULL); + NNI_ASSERT(tran->tran_pipe->p_stop != NULL); + NNI_ASSERT(tran->tran_pipe->p_close != NULL); + NNI_ASSERT(tran->tran_pipe->p_send != NULL); + NNI_ASSERT(tran->tran_pipe->p_recv != NULL); + NNI_ASSERT(tran->tran_pipe->p_peer != NULL); + + if (tran->tran_dialer != NULL) { + NNI_ASSERT(tran->tran_dialer->d_init != NULL); + NNI_ASSERT(tran->tran_dialer->d_fini != NULL); + NNI_ASSERT(tran->tran_dialer->d_close != NULL); + NNI_ASSERT(tran->tran_dialer->d_stop != NULL); + NNI_ASSERT(tran->tran_dialer->d_connect != NULL); + NNI_ASSERT(tran->tran_dialer->d_getopt != NULL); + NNI_ASSERT(tran->tran_dialer->d_setopt != NULL); + } + + if (tran->tran_listener != NULL) { + NNI_ASSERT(tran->tran_listener->l_init != NULL); + NNI_ASSERT(tran->tran_listener->l_fini != NULL); + NNI_ASSERT(tran->tran_listener->l_bind != NULL); + NNI_ASSERT(tran->tran_listener->l_accept != NULL); + NNI_ASSERT(tran->tran_listener->l_close != NULL); + NNI_ASSERT(tran->tran_listener->l_stop != NULL); + NNI_ASSERT(tran->tran_listener->l_getopt != NULL); + NNI_ASSERT(tran->tran_listener->l_setopt != NULL); + } +#endif + nni_rwlock_wrlock(&sp_tran_lk); if (!nni_list_node_active(&tran->tran_link)) { tran->tran_init();