This documentation is for version v1.7.1 of NNG, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.

nng_aio_defer(3)

NAME

nng_aio_defer - defer asynchronous I/O operation

SYNOPSIS

#include <nng/nng.h>

typedef void (*nng_aio_cancelfn)(nng_aio *aio, void *arg, int err);

void nng_aio_defer(nng_aio *aio, nng_aio_cancelfn fn, void *arg);

DESCRIPTION

The nng_aio_defer() function marks operation associated with aio as being deferred for asynchronous completion, and also registers a cancellation function fn and associated argument arg, thereby permitting the operation to be canceled.

If the aio is being canceled, the cancellation routine fn will be called with the aio, the arg specified by nng_aio_defer(), and an error value in err, which is the reason that the operation is being canceled.

The operation may not be cancelable; for example it may have already been completed, or be in a state where it is no longer possible to unschedule it. In this case, the cancelfn should just return without making any changes.

If the cancellation routine successfully canceled the operation, it should ensure that nng_aio_finish() is called, with the error code specified by err.

It is mandatory that I/O providers call nng_aio_finish() EXACTLY ONCE when they are finished with the operation.
This function is only for I/O providers (those actually performing the operation such as HTTP handler functions or transport providers); ordinary users of the aio should not call this function.
Care must be taken to ensure that cancellation and completion of the routine are multi-thread safe; this will usually involve the use of locks or other synchronization primitives.
For operations that complete synchronously, without any need to be deferred, the provider should not bother to call nng_aio_defer(), although it is harmless if it does.

RETURN VALUES

None.

ERRORS

None.

SEE ALSO