diff options
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); } } } |
