diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-26 12:15:48 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-26 12:53:46 -0800 |
| commit | 2c4324c2b7a3dd5583b3b2c499575cf1c8e52e0c (patch) | |
| tree | 6c6a70bcc3d2f2d78981dcf662b178e0a2da7277 | |
| parent | b5826dac78e75520c26f2d84a952fe04d69fa2d3 (diff) | |
| download | nng-2c4324c2b7a3dd5583b3b2c499575cf1c8e52e0c.tar.gz nng-2c4324c2b7a3dd5583b3b2c499575cf1c8e52e0c.tar.bz2 nng-2c4324c2b7a3dd5583b3b2c499575cf1c8e52e0c.zip | |
sockfd: convert to use nni_aio_start
| -rw-r--r-- | src/core/sockfd.c | 9 | ||||
| -rw-r--r-- | src/platform/posix/posix_sockfd.c | 14 | ||||
| -rw-r--r-- | src/sp/transport/socket/sockfd.c | 27 |
3 files changed, 11 insertions, 39 deletions
diff --git a/src/core/sockfd.c b/src/core/sockfd.c index 1a0e792f..ce0c6772 100644 --- a/src/core/sockfd.c +++ b/src/core/sockfd.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -116,10 +116,11 @@ sfd_listener_accept(void *arg, nng_aio *aio) { sfd_listener *l = arg; - if (nni_aio_begin(aio) != 0) { + nni_mtx_lock(&l->mtx); + if (!nni_aio_start(aio, sfd_cancel_accept, l)) { + nni_mtx_unlock(&l->mtx); return; } - nni_mtx_lock(&l->mtx); if (l->closed) { nni_mtx_unlock(&l->mtx); nni_aio_finish_error(aio, NNG_ECLOSED); @@ -128,7 +129,7 @@ sfd_listener_accept(void *arg, nng_aio *aio) if (l->listen_cnt) { sfd_start_conn(l, aio); - } else if (nni_aio_defer(aio, sfd_cancel_accept, l)) { + } else { nni_aio_list_append(&l->accept_q, aio); } nni_mtx_unlock(&l->mtx); diff --git a/src/platform/posix/posix_sockfd.c b/src/platform/posix/posix_sockfd.c index 7ed95681..96782c04 100644 --- a/src/platform/posix/posix_sockfd.c +++ b/src/platform/posix/posix_sockfd.c @@ -275,16 +275,11 @@ static void sfd_send(void *arg, nni_aio *aio) { nni_sfd_conn *c = arg; - int rv; - if (nni_aio_begin(aio) != 0) { - return; - } nni_mtx_lock(&c->mtx); - if ((rv = nni_aio_schedule(aio, sfd_cancel, c)) != 0) { + if (!nni_aio_start(aio, sfd_cancel, c)) { nni_mtx_unlock(&c->mtx); - nni_aio_finish_error(aio, rv); return; } nni_aio_list_append(&c->writeq, aio); @@ -305,16 +300,11 @@ static void sfd_recv(void *arg, nni_aio *aio) { nni_sfd_conn *c = arg; - int rv; - if (nni_aio_begin(aio) != 0) { - return; - } nni_mtx_lock(&c->mtx); - if ((rv = nni_aio_schedule(aio, sfd_cancel, c)) != 0) { + if (!nni_aio_start(aio, sfd_cancel, c)) { nni_mtx_unlock(&c->mtx); - nni_aio_finish_error(aio, rv); return; } nni_aio_list_append(&c->readq, aio); diff --git a/src/sp/transport/socket/sockfd.c b/src/sp/transport/socket/sockfd.c index 646151ed..b66687b3 100644 --- a/src/sp/transport/socket/sockfd.c +++ b/src/sp/transport/socket/sockfd.c @@ -453,19 +453,10 @@ static void sfd_tran_pipe_send(void *arg, nni_aio *aio) { sfd_tran_pipe *p = arg; - int rv; - if (nni_aio_begin(aio) != 0) { - // No way to give the message back to the protocol, so - // we just discard it silently to prevent it from leaking. - nni_msg_free(nni_aio_get_msg(aio)); - nni_aio_set_msg(aio, NULL); - return; - } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, sfd_tran_pipe_send_cancel, p)) != 0) { + if (!nni_aio_start(aio, sfd_tran_pipe_send_cancel, p)) { nni_mtx_unlock(&p->mtx); - nni_aio_finish_error(aio, rv); return; } nni_list_append(&p->sendq, aio); @@ -530,15 +521,10 @@ static void sfd_tran_pipe_recv(void *arg, nni_aio *aio) { sfd_tran_pipe *p = arg; - int rv; - if (nni_aio_begin(aio) != 0) { - return; - } nni_mtx_lock(&p->mtx); - if ((rv = nni_aio_schedule(aio, sfd_tran_pipe_recv_cancel, p)) != 0) { + if (!nni_aio_start(aio, sfd_tran_pipe_recv_cancel, p)) { nni_mtx_unlock(&p->mtx); - nni_aio_finish_error(aio, rv); return; } @@ -687,7 +673,7 @@ error: ep->useraio = NULL; nni_aio_finish_error(aio, rv); } - if (!ep->closed) { + if (!ep->closed && rv != NNG_ESTOPPED) { nng_stream_listener_accept(ep->listener, &ep->connaio); } nni_mtx_unlock(&ep->mtx); @@ -791,11 +777,7 @@ static void sfd_tran_ep_accept(void *arg, nni_aio *aio) { sfd_tran_ep *ep = arg; - int rv; - if (nni_aio_begin(aio) != 0) { - return; - } nni_mtx_lock(&ep->mtx); if (ep->closed) { nni_mtx_unlock(&ep->mtx); @@ -807,9 +789,8 @@ sfd_tran_ep_accept(void *arg, nni_aio *aio) nni_aio_finish_error(aio, NNG_EBUSY); return; } - if ((rv = nni_aio_schedule(aio, sfd_tran_ep_cancel, ep)) != 0) { + if (!nni_aio_start(aio, sfd_tran_ep_cancel, ep)) { nni_mtx_unlock(&ep->mtx); - nni_aio_finish_error(aio, rv); return; } ep->useraio = aio; |
