diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-08-20 09:00:46 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-08-20 09:26:20 -0700 |
| commit | 6e5f6a26beec0a44d25625cacb5095cdc7a94146 (patch) | |
| tree | 7d6ef720b239a30d4906f1f2303fed77707b2761 /src/core/device.c | |
| parent | 3e70013111b70f1439b2f9991211c887a8eefff3 (diff) | |
| download | nng-6e5f6a26beec0a44d25625cacb5095cdc7a94146.tar.gz nng-6e5f6a26beec0a44d25625cacb5095cdc7a94146.tar.bz2 nng-6e5f6a26beec0a44d25625cacb5095cdc7a94146.zip | |
fixes #664 aio cancellation could be better
This changes the signature of the aio cancellation routines
to take the argument for cancellation directly, so we do not
need to lookup the argument using the nni_aio_get_prov_data.
We should probably consider eliminating nni_aio_get_prov_data,
and co, and changing the prov_extra to reflect prov_data. Later.
Diffstat (limited to 'src/core/device.c')
| -rw-r--r-- | src/core/device.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core/device.c b/src/core/device.c index 0fd23add..fee108a8 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -30,28 +30,29 @@ typedef struct nni_device_data { int npath; nni_device_path paths[2]; nni_mtx mtx; - int running; + bool running; } nni_device_data; typedef struct nni_device_pair nni_device_pair; static void -nni_device_cancel(nni_aio *aio, int rv) +nni_device_cancel(nni_aio *aio, void *arg, int rv) { - nni_device_data *dd = nni_aio_get_prov_data(aio); + nni_device_data *dd = arg; // cancellation is the only path to shutting it down. nni_mtx_lock(&dd->mtx); - if (dd->running == 0) { + if ((!dd->running) || (dd->user != aio)) { nni_mtx_unlock(&dd->mtx); return; } - dd->running = 0; + dd->running = false; + dd->user = NULL; nni_mtx_unlock(&dd->mtx); nni_sock_shutdown(dd->paths[0].src); nni_sock_shutdown(dd->paths[0].dst); - nni_aio_finish_error(dd->user, rv); + nni_aio_finish_error(aio, rv); } static void @@ -209,7 +210,7 @@ nni_device_start(nni_device_data *dd, nni_aio *user) p->state = NNI_DEVICE_STATE_RECV; nni_sock_recv(p->src, p->aio); } - dd->running = 1; + dd->running = true; nni_mtx_unlock(&dd->mtx); } |
