Async Operation Interface

DESCRIPTION

SILC Async Operation API is an interface that can be used to control asynchronous operations. All functions that take callback as argument should return SilcAsyncOperation context. That context then can be used to control, such as, abort the asynchronous operation. Using SILC Async Operation API, asynchronous functions can be controlled and aborted safely.

The SILC Async Operation API is divided in two levels; the underlaying operation level that implements the asynchronous operation, and the upper layer that can control the asynchronous operation. The operation layer must guarantee that if the upper layer aborts the asynchronous operation, no callback function will be called back to the upper layer. This must be remembered when implementing the operation layer.

EXAMPLE

 SilcAsyncOperation async_call(Callback callback, void *cb_context)
 {
   SilcAsyncOperation op;
   OpContext ctx;

   // Allocate async operation so that caller can control us, like abort
   op = silc_async_alloc(async_call_abort, NULL, ctx);
   ctx->callback = callback;

   ...

   // Return async operation for upper layer
   return op;
 }

 // This callback is called when silc_async_abort is called by upper layer.
 // The callback given to async_call must not be called after this.
 void async_call_abort(SilcAsyncOperation op, void *context)
 {
   OpContext ctx = context;
   ctx->aborted = TRUE;
   ctx->callback = NULL;
 }

TABLE OF CONTENTS