diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-07 19:32:40 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-07 19:39:38 -0800 |
| commit | 3ca7bcc0edd0f26c33264d32e7b6f07276e72e3c (patch) | |
| tree | 99b7a80b4c7241c030e0ee4e1b08f3d515f1db3f /src/core/aio.c | |
| parent | 8af6befd3a3805501e5c13612558241e60b349ba (diff) | |
| download | nng-3ca7bcc0edd0f26c33264d32e7b6f07276e72e3c.tar.gz nng-3ca7bcc0edd0f26c33264d32e7b6f07276e72e3c.tar.bz2 nng-3ca7bcc0edd0f26c33264d32e7b6f07276e72e3c.zip | |
aio: task_abort was a mistake
The use of task_abort to prematurely fail an aio at scheduling
time was a mistake, because it could have led to duplicate calls
to nng_aio_finish(). We do need to ensure that we leave an indicator
so that nni_aio_schedule can return the abort status to caller,
in the case that abort is called between the nni_aio_begin and
nni_aio_schedule calls.
Diffstat (limited to 'src/core/aio.c')
| -rw-r--r-- | src/core/aio.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index d003c251..eaff5c80 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -118,8 +118,6 @@ nni_aio_fini(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECLOSED); - } else { - nni_task_abort(&aio->a_task); } nni_task_fini(&aio->a_task); @@ -203,8 +201,6 @@ nni_aio_stop(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECANCELED); - } else { - nni_task_abort(&aio->a_task); } nni_aio_wait(aio); @@ -230,8 +226,6 @@ nni_aio_close(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECLOSED); - } else { - nni_task_abort(&aio->a_task); } } } @@ -352,6 +346,7 @@ nni_aio_begin(nni_aio *aio) aio->a_result = 0; aio->a_count = 0; aio->a_cancel_fn = NULL; + aio->a_abort = false; // We should not reschedule anything at this point. if (aio->a_stop || eq->eq_stop) { @@ -378,7 +373,6 @@ nni_aio_schedule(nni_aio *aio, nni_aio_cancel_fn cancel, void *data) // Convert the relative timeout to an absolute timeout. switch (aio->a_timeout) { case NNG_DURATION_ZERO: - nni_task_abort(&aio->a_task); return (NNG_ETIMEDOUT); case NNG_DURATION_INFINITE: case NNG_DURATION_DEFAULT: @@ -391,8 +385,12 @@ nni_aio_schedule(nni_aio *aio, nni_aio_cancel_fn cancel, void *data) } nni_mtx_lock(&eq->eq_mtx); + if (aio->a_abort) { + int rv = aio->a_result; + nni_mtx_unlock(&eq->eq_mtx); + return (rv); + } if (aio->a_stop || eq->eq_stop) { - nni_task_abort(&aio->a_task); nni_mtx_unlock(&eq->eq_mtx); return (NNG_ECLOSED); } @@ -426,13 +424,17 @@ nni_aio_abort(nni_aio *aio, int rv) arg = aio->a_cancel_arg; aio->a_cancel_fn = NULL; aio->a_cancel_arg = NULL; + if (fn == NULL) { + // We haven't been scheduled yet, + // so make sure that schedule will abort. + aio->a_abort = true; + aio->a_result = rv; + } nni_mtx_unlock(&eq->eq_mtx); // Stop any I/O at the provider level. if (fn != NULL) { fn(aio, arg, rv); - } else { - nni_task_abort(&aio->a_task); } } } |
