Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tcp stop #1985

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/core/dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
4 changes: 1 addition & 3 deletions src/core/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
31 changes: 31 additions & 0 deletions src/sp/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/sp/transport/inproc/inproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
};
Expand Down
13 changes: 11 additions & 2 deletions src/sp/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
};
Expand Down
13 changes: 11 additions & 2 deletions src/sp/transport/tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
28 changes: 22 additions & 6 deletions src/sp/transport/ws/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -368,23 +368,37 @@ 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);
NNI_FREE_STRUCT(d);
}

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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/sp/transport/zerotier/zerotier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
};

Expand All @@ -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,
};

Expand Down
Loading