summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-23 09:30:13 -0700
committerGarrett D'Amore <garrett@damore.org>2018-03-30 12:38:56 -0700
commit5f69a5ba55058c7f5bfc4d5a250e72c56f31e0eb (patch)
treeb83eff910ba236f1b63069ab4b02ac39bda4f866
parent122bd6086c0fef009f582d6c4fec5a5a3ae5e6de (diff)
downloadnng-5f69a5ba55058c7f5bfc4d5a250e72c56f31e0eb.tar.gz
nng-5f69a5ba55058c7f5bfc4d5a250e72c56f31e0eb.tar.bz2
nng-5f69a5ba55058c7f5bfc4d5a250e72c56f31e0eb.zip
fixes #316 nni_aio_set_synch() usually doesn't do anything
-rw-r--r--docs/man/nng_aio_stop.3.adoc13
-rw-r--r--src/core/aio.c10
2 files changed, 19 insertions, 4 deletions
diff --git a/docs/man/nng_aio_stop.3.adoc b/docs/man/nng_aio_stop.3.adoc
index 5e65b8f7..02c258f8 100644
--- a/docs/man/nng_aio_stop.3.adoc
+++ b/docs/man/nng_aio_stop.3.adoc
@@ -28,9 +28,16 @@ The `nng_aio_stop()` function stops the asynchronous I/O operation
associated with _aio_ by aborting with `NNG_ECANCELED`, and then waits
for it to complete or to be completely aborted.
-This is logically the equivalent of <<nng_aio_cancel.3#,`nng_aio_cancel()`>>
-followed by <<nng_aio_wait.3#,`nng_aio_wait()`>>, except that the asynchronous
-I/O handle may not be used for any further operations.
+If an operation is in progress when this function is called, that operation
+is canceled and the callback function is _not_ allowed to run.
+
+If the callback function is already running when this function is called,
+then it is allowed to complete before returning to the caller.
+
+No new operations will be started on this _aio_.
+
+NOTE: Calling this function means that the operation may be aborted without
+completing its callback function.
TIP: When multiple asynchronous I/O handles are in use and need to be
shut down, it is safest to stop all of them, before deallocating any of
diff --git a/src/core/aio.c b/src/core/aio.c
index 1aaffe12..f3af80d8 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -392,7 +392,15 @@ nni_aio_finish_impl(nni_aio *aio, int rv, size_t count, nni_msg *msg)
aio->a_waiting = 0;
nni_cv_wake(&aio->a_cv);
}
- nni_task_dispatch(&aio->a_task);
+
+ if (!aio->a_synch) {
+ nni_task_dispatch(&aio->a_task);
+ } else {
+ nni_mtx_unlock(&nni_aio_lk);
+ aio->a_task.task_cb(aio->a_task.task_arg);
+ nni_mtx_lock(&nni_aio_lk);
+ aio->a_synch = 0;
+ }
}
nni_mtx_unlock(&nni_aio_lk);
}