aboutsummaryrefslogtreecommitdiff
path: root/src/sp/transport/ws
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-09 13:33:11 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-22 21:31:28 -0800
commitc8ce57d668d73d92a071fa86f81e07ca403d8672 (patch)
treead7e602e43fefa64067fdac5fcd23987a50c3a90 /src/sp/transport/ws
parent013bb69c6be2f0a4572f4200de05e664692b6704 (diff)
downloadnng-c8ce57d668d73d92a071fa86f81e07ca403d8672.tar.gz
nng-c8ce57d668d73d92a071fa86f81e07ca403d8672.tar.bz2
nng-c8ce57d668d73d92a071fa86f81e07ca403d8672.zip
aio: introduce nni_aio_defer
This will replace nni_aio_schedule, and it includes finishing the task if needed. It does so without dropping the lock and so is more efficient and race free. This includes some conversion of some subsystems to it.
Diffstat (limited to 'src/sp/transport/ws')
-rw-r--r--src/sp/transport/ws/websocket.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c
index f962adbf..ab139a48 100644
--- a/src/sp/transport/ws/websocket.c
+++ b/src/sp/transport/ws/websocket.c
@@ -126,15 +126,13 @@ static void
wstran_pipe_recv(void *arg, nni_aio *aio)
{
ws_pipe *p = arg;
- int rv;
if (nni_aio_begin(aio) != 0) {
return;
}
nni_mtx_lock(&p->mtx);
- if ((rv = nni_aio_schedule(aio, wstran_pipe_recv_cancel, p)) != 0) {
+ if (!nni_aio_defer(aio, wstran_pipe_recv_cancel, p)) {
nni_mtx_unlock(&p->mtx);
- nni_aio_finish_error(aio, rv);
return;
}
p->user_rxaio = aio;
@@ -161,7 +159,6 @@ static void
wstran_pipe_send(void *arg, nni_aio *aio)
{
ws_pipe *p = arg;
- int rv;
if (nni_aio_begin(aio) != 0) {
// No way to give the message back to the protocol, so
@@ -171,9 +168,8 @@ wstran_pipe_send(void *arg, nni_aio *aio)
return;
}
nni_mtx_lock(&p->mtx);
- if ((rv = nni_aio_schedule(aio, wstran_pipe_send_cancel, p)) != 0) {
+ if (!nni_aio_defer(aio, wstran_pipe_send_cancel, p)) {
nni_mtx_unlock(&p->mtx);
- nni_aio_finish_error(aio, rv);
return;
}
p->user_txaio = aio;
@@ -271,7 +267,6 @@ static void
wstran_listener_accept(void *arg, nni_aio *aio)
{
ws_listener *l = arg;
- int rv;
// We already bound, so we just need to look for an available
// pipe (created by the handler), and match it.
@@ -280,9 +275,8 @@ wstran_listener_accept(void *arg, nni_aio *aio)
return;
}
nni_mtx_lock(&l->mtx);
- if ((rv = nni_aio_schedule(aio, wstran_listener_cancel, l)) != 0) {
+ if (!nni_aio_defer(aio, wstran_listener_cancel, l)) {
nni_mtx_unlock(&l->mtx);
- nni_aio_finish_error(aio, rv);
return;
}
nni_list_append(&l->aios, aio);
@@ -311,16 +305,14 @@ static void
wstran_dialer_connect(void *arg, nni_aio *aio)
{
ws_dialer *d = arg;
- int rv;
if (nni_aio_begin(aio) != 0) {
return;
}
nni_mtx_lock(&d->mtx);
- if ((rv = nni_aio_schedule(aio, wstran_dialer_cancel, d)) != 0) {
+ if (!nni_aio_defer(aio, wstran_dialer_cancel, d)) {
nni_mtx_unlock(&d->mtx);
- nni_aio_finish_error(aio, rv);
return;
}
NNI_ASSERT(nni_list_empty(&d->aios));