nng_aio_defer()

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, registering a cancellation function fn and associated argument arg. This permits the operation to be canceled.

If the aio is 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.

At any given time, 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.

important

It is mandatory that I/O providers call nng_aio_finish() exactly once when they are finished with the operation.

important

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.

tip

For operations that complete synchronously, without any need to be deferred, the provider need not call nng_aio_defer().

tip

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.

SEE ALSO

nng_aio_alloc(), nng_aio_cancel(), nng_aio_finish(), nng_aio