From c72bd53e2c5b4bc7207bfa1710ccff47655a099a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 20 Aug 2018 11:09:23 -0700 Subject: fixes #506 AIO "providers" need a way to call nni_aio_schedule. --- docs/man/CMakeLists.txt | 2 + docs/man/libnng.3.adoc | 4 +- docs/man/nng_aio_begin.3.adoc | 64 ++++++++++++++++++++++++ docs/man/nng_aio_defer.3.adoc | 78 ++++++++++++++++++++++++++++++ docs/man/nng_aio_finish.3.adoc | 2 + docs/man/nng_http_handler_alloc.3http.adoc | 11 ++++- 6 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 docs/man/nng_aio_begin.3.adoc create mode 100644 docs/man/nng_aio_defer.3.adoc (limited to 'docs/man') diff --git a/docs/man/CMakeLists.txt b/docs/man/CMakeLists.txt index 726d95c4..af644a62 100644 --- a/docs/man/CMakeLists.txt +++ b/docs/man/CMakeLists.txt @@ -62,8 +62,10 @@ if (NNG_ENABLE_DOC) libnng nng_aio_abort nng_aio_alloc + nng_aio_begin nng_aio_cancel nng_aio_count + nng_aio_defer nng_aio_finish nng_aio_free nng_aio_get_input diff --git a/docs/man/libnng.3.adoc b/docs/man/libnng.3.adoc index ec88cdd0..23306997 100644 --- a/docs/man/libnng.3.adoc +++ b/docs/man/libnng.3.adoc @@ -152,9 +152,11 @@ The following functions are used in the asynchronous model: |=== |<>|abort asynchronous I/O operation |<>|allocate asynchronous I/O handle +|<>|begin asynchronous I/O operation |<>|cancel asynchronous I/O operation |<>|return number of bytes transferred -|<>|finish an asynchronous I/O operation +|<>|defer asynchronous I/O operation +|<>|finish asynchronous I/O operation |<>|free asynchronous I/O handle |<>|return input parameter |<>|get message from an asynchronous receive diff --git a/docs/man/nng_aio_begin.3.adoc b/docs/man/nng_aio_begin.3.adoc new file mode 100644 index 00000000..fd72d401 --- /dev/null +++ b/docs/man/nng_aio_begin.3.adoc @@ -0,0 +1,64 @@ += nng_aio_begin(3) +// +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV +// +// This document is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +== NAME + +nng_aio_begin - begin asynchronous I/O operation + +== SYNOPSIS + +[source, c] +---- +#include + +bool nng_aio_begin(nng_aio *aio); +---- + +== DESCRIPTION + +The `nng_aio_begin()` function is called by the I/O provider to indicate that +it is going to process the operation. + +The function may return `false`, indicating that the _aio_ has been closed +by the caller asynchronously. +In this case the provider should abandon the operation and do nothing else. + +This operation should be called at the start of any I/O operation, and must +be called not more than once for a given I/O operation on a given _aio_. + +Once this function is called, if `true` is returned, then the provider MUST +guarantee that `<>` is called for the _aio_ +exactly once, when the operation is complete or canceled. + +NOTE: 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. + +== RETURN VALUES + +[horizontal] +`true`:: The operation has been started. +`false`:: The operation cannot be started. + +== ERRORS + +None. + +== SEE ALSO + +[.text-left] +<>, +<>, +<>, +<>, +<>, +<>, +<> diff --git a/docs/man/nng_aio_defer.3.adoc b/docs/man/nng_aio_defer.3.adoc new file mode 100644 index 00000000..67520293 --- /dev/null +++ b/docs/man/nng_aio_defer.3.adoc @@ -0,0 +1,78 @@ += nng_aio_defer(3) +// +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV +// +// This document is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +== NAME + +nng_aio_defer - defer asynchronous I/O operation + +== SYNOPSIS + +[source, c] +---- +#include + +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 `<>` is called, with the +error code specified by _err_. + +IMPORTANT: It is mandatory that I/O providers call +`<>` +*EXACTLY ONCE* when they are finished with the operation. + +NOTE: 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. + +NOTE: 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 should not bother to call `nng_aio_defer()`, +although it is harmless if it does. + +== RETURN VALUES + +None. + +== ERRORS + +None. + +== SEE ALSO + +[.text-left] +<>, +<>, +<>, +<>, +<>, +<> diff --git a/docs/man/nng_aio_finish.3.adoc b/docs/man/nng_aio_finish.3.adoc index 00148fd6..4733c1f2 100644 --- a/docs/man/nng_aio_finish.3.adoc +++ b/docs/man/nng_aio_finish.3.adoc @@ -52,7 +52,9 @@ None. [.text-left] <>, +<>, <>, +<>, <>, <>, <> diff --git a/docs/man/nng_http_handler_alloc.3http.adoc b/docs/man/nng_http_handler_alloc.3http.adoc index 187b91b6..523b5328 100644 --- a/docs/man/nng_http_handler_alloc.3http.adoc +++ b/docs/man/nng_http_handler_alloc.3http.adoc @@ -63,7 +63,8 @@ The generic (first) form of this creates a handler that uses a user-supplied function to process HTTP requests. This function uses the asynchronous I/O framework. The function takes a pointer to an `<>` structure. -That structure will be passed with the following input values (retrieved with + +The _aio_ will be passed with the following input values (retrieved with `<>`): 0: `nng_http_req *` __request__:: The client's HTTP request. @@ -86,6 +87,13 @@ If any non-zero status is returned back to the caller instead, then a generic 500 response will be created and sent, if possible, and the connection will be closed. +The _aio_ may be scheduled for deferred completion using the +`<>` function. + +NOTE: The callback function should *NOT* call +`<>`, +as that will already have been done by the server framework. + === Directory Handler The second member of this family, `nng_http_handler_alloc_directory()`, creates @@ -137,6 +145,7 @@ This function returns 0 on success, and non-zero otherwise. == SEE ALSO [.text-left] +<>, <>, <>, <>, -- cgit v1.2.3-70-g09d2