diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nng.c | 15 | ||||
| -rw-r--r-- | src/nng.h | 18 |
2 files changed, 33 insertions, 0 deletions
@@ -1601,6 +1601,21 @@ nng_aio_finish(nng_aio *aio, int rv) nni_aio_finish(aio, rv, nni_aio_count(aio)); } +void +nng_aio_defer(nng_aio *aio, nng_aio_cancelfn fn, void *arg) +{ + nni_aio_schedule(aio, fn, arg); +} + +bool +nng_aio_begin(nng_aio *aio) +{ + if (nni_aio_begin(aio) != 0) { + return (false); + } + return (true); +} + #if 0 int nng_snapshot_create(nng_socket sock, nng_snapshot **snapp) @@ -564,6 +564,11 @@ NNG_DECL void nng_aio_set_timeout(nng_aio *, nng_duration); // to succeed if n <= 4, otherwise it may fail due to NNG_ENOMEM. NNG_DECL int nng_aio_set_iov(nng_aio *, unsigned, const nng_iov *); +// nng_aio_begin is called by the provider to mark the operation as +// beginning. If it returns false, then the provider must take no +// further action on the aio. +NNG_DECL bool nng_aio_begin(nng_aio *); + // nng_aio_finish is used to "finish" an asynchronous operation. // It should only be called by "providers" (such as HTTP server API users). // The argument is the value that nng_aio_result() should return. @@ -571,6 +576,19 @@ NNG_DECL int nng_aio_set_iov(nng_aio *, unsigned, const nng_iov *); // given aio. NNG_DECL void nng_aio_finish(nng_aio *, int); +// nng_aio_defer is used to register a cancellation routine, and indicate +// that the operation will be completed asynchronously. It must only be +// called once per operation on an aio, and must only be called by providers. +// If the operation is canceled by the consumer, the cancellation callback +// will be called. The provider *must* still ensure that the nng_aio_finish() +// function is called EXACTLY ONCE. If the operation cannot be canceled +// for any reason, the cancellation callback should do nothing. The +// final argument is passed to the cancelfn. The final argument of the +// cancellation function is the error number (will not be zero) corresponding +// to the reason for cancellation, e.g. NNG_ETIMEDOUT or NNG_ECANCELED. +typedef void (*nng_aio_cancelfn)(nng_aio *, void *, int); +NNG_DECL void nng_aio_defer(nng_aio *, nng_aio_cancelfn, void *); + // nng_aio_sleep does a "sleeping" operation, basically does nothing // but wait for the specified number of milliseconds to expire, then // calls the callback. This returns 0, rather than NNG_ETIMEDOUT. |
