From 1d033484ee1a2ec26d3eead073e7bc0f889ffdf4 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 15 May 2018 01:47:12 -0700 Subject: fixes #419 want to nni_aio_stop without blocking (#428) * fixes #419 want to nni_aio_stop without blocking This actually introduces an nni_aio_close() API that causes nni_aio_begin to return NNG_ECLOSED, while scheduling a callback on the AIO to do an NNG_ECLOSED as well. This should be called in non-blocking close() contexts instead of nni_aio_stop(), and the cases where we call nni_aio_fini() multiple times are updated updated to add nni_aio_stop() calls on all "interlinked" aios before finalizing them. Furthermore, we call nni_aio_close() as soon as practical in the close path. This closes an annoying race condition where the callback from a lower subsystem could wind up rescheduling an operation that we wanted to abort. --- src/transport/ws/websocket.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/transport/ws/websocket.c') diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index 12f3aeb5..a4081b25 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -205,6 +205,9 @@ ws_pipe_close(void *arg) { ws_pipe *p = arg; + nni_aio_close(p->rxaio); + nni_aio_close(p->txaio); + nni_mtx_lock(&p->mtx); nni_ws_close(p->ws); nni_mtx_unlock(&p->mtx); @@ -588,7 +591,7 @@ static nni_tran_pipe_option ws_pipe_options[] = { } }; -static nni_tran_pipe ws_pipe_ops = { +static nni_tran_pipe_ops ws_pipe_ops = { .p_fini = ws_pipe_fini, .p_send = ws_pipe_send, .p_recv = ws_pipe_recv, @@ -690,6 +693,9 @@ ws_ep_close(void *arg) { ws_ep *ep = arg; + nni_aio_close(ep->accaio); + nni_aio_close(ep->connaio); + if (ep->mode == NNI_EP_MODE_LISTEN) { nni_ws_listener_close(ep->listener); } else { @@ -750,8 +756,8 @@ ws_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) nni_aio_list_init(&ep->aios); ep->mode = mode; - ep->lproto = nni_sock_proto(sock); - ep->rproto = nni_sock_peer(sock); + ep->lproto = nni_sock_proto_id(sock); + ep->rproto = nni_sock_peer_id(sock); if (mode == NNI_EP_MODE_DIAL) { pname = nni_sock_peer_name(sock); @@ -795,7 +801,7 @@ ws_tran_fini(void) { } -static nni_tran_ep ws_ep_ops = { +static nni_tran_ep_ops ws_ep_ops = { .ep_init = ws_ep_init, .ep_fini = ws_ep_fini, .ep_connect = ws_ep_connect, @@ -1015,7 +1021,7 @@ static nni_tran_ep_option wss_ep_options[] = { }, }; -static nni_tran_ep wss_ep_ops = { +static nni_tran_ep_ops wss_ep_ops = { .ep_init = ws_ep_init, .ep_fini = ws_ep_fini, .ep_connect = ws_ep_connect, -- cgit v1.2.3-70-g09d2