diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/man/nng_aio_finish.3.adoc | 59 | ||||
| -rw-r--r-- | docs/man/nng_aio_get_input.3.adoc | 52 | ||||
| -rw-r--r-- | docs/man/nng_aio_reset.3.adoc | 41 | ||||
| -rw-r--r-- | docs/man/nng_aio_set_output.3.adoc | 59 | ||||
| -rw-r--r-- | docs/man/nng_aio_start.3.adoc | 69 | ||||
| -rw-r--r-- | docs/ref/api/aio.md | 97 | ||||
| -rw-r--r-- | docs/ref/xref.md | 10 |
7 files changed, 100 insertions, 287 deletions
diff --git a/docs/man/nng_aio_finish.3.adoc b/docs/man/nng_aio_finish.3.adoc deleted file mode 100644 index a4855ec8..00000000 --- a/docs/man/nng_aio_finish.3.adoc +++ /dev/null @@ -1,59 +0,0 @@ -= nng_aio_finish(3) -// -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// 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_finish - finish asynchronous I/O operation - -== SYNOPSIS - -[source, c] ----- -#include <nng/nng.h> - -void nng_aio_finish(nng_aio *aio, int err); ----- - -== DESCRIPTION - -The `nng_aio_finish()` function marks operation associated with _aio_ as -complete, with the status _err_. -This will be the result returned by -xref:nng_aio_result.3.adoc[`nng_aio_result()`]. - -This function causes the callback associated with the _aio_ to called. - -IMPORTANT: It is mandatory that operation providers call this function -*exactly once* when they are finished with the operation. -After calling this function they *must not* perform any further accesses -to the _aio_. - -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 have any need for this function. - -== RETURN VALUES - -None. - -== ERRORS - -None. - -== SEE ALSO - -[.text-left] -xref:nng_aio_reset.3.adoc[nng_aio_reset(3)], -xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], -xref:nng_aio_start.3.adoc[nng_aio_start(3)], -xref:nng_aio_result.3.adoc[nng_aio_result(3)], -xref:nng_aio.5.adoc[nng_aio(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/man/nng_aio_get_input.3.adoc b/docs/man/nng_aio_get_input.3.adoc deleted file mode 100644 index ef331312..00000000 --- a/docs/man/nng_aio_get_input.3.adoc +++ /dev/null @@ -1,52 +0,0 @@ -= nng_aio_get_input(3) -// -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// 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_get_input - return input parameter - -== SYNOPSIS - -[source, c] ----- -#include <nng/nng.h> - -void *nng_aio_get_input(nng_aio *aio, unsigned int index); ----- - -== DESCRIPTION - -The `nng_aio_get_input()` function returns the value of the input parameter -previously set at _index_ on _aio_ with the -xref:nng_aio_set_input.3.adoc[`nng_aio_set_input()`] function. - -The valid values of _index_ range from zero (0) to three (3), as no operation -currently defined can accept more than four parameters. -(This limit could increase in the future.) -If the index supplied is outside of this range, -or of the input parameter was not previously set, then `NULL` is returned. - -== RETURN VALUES - -Value previously set, or `NULL`. - -== ERRORS - -None. - -== SEE ALSO - -[.text-left] -xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], -xref:nng_aio_set_input.3.adoc[nng_aio_set_input(3)], -xref:nng_aio_result.3.adoc[nng_aio_result(3)], -xref:nng_aio.5.adoc[nng_aio(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/man/nng_aio_reset.3.adoc b/docs/man/nng_aio_reset.3.adoc deleted file mode 100644 index 8f4ba514..00000000 --- a/docs/man/nng_aio_reset.3.adoc +++ /dev/null @@ -1,41 +0,0 @@ -= nng_aio_reset(3) -// -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> -// -// 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_reset - reset asynchronous I/O operation - -== SYNOPSIS - -[source, c] ----- -#include <nng/nng.h> - -void nng_aio_reset(nng_aio *aio); ----- - -== DESCRIPTION - -The `nng_aio_reset()` is used by providers to reset certain fields in the _aio_. -This should be done before performing any operations on _aio_. - -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. - -== SEE ALSO - -[.text-left] -xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], -xref:nng_aio_start.3.adoc[nng_aio_start(3)], -xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], -xref:nng_aio_result.3.adoc[nng_aio_result(3)], -xref:nng_aio.5.adoc[nng_aio(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/man/nng_aio_set_output.3.adoc b/docs/man/nng_aio_set_output.3.adoc deleted file mode 100644 index 883598ce..00000000 --- a/docs/man/nng_aio_set_output.3.adoc +++ /dev/null @@ -1,59 +0,0 @@ -= nng_aio_set_output(3) -// -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// 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_set_output - set output result - -== SYNOPSIS - -[source, c] ----- -#include <nng/nng.h> - -void nng_aio_set_output(nng_aio *aio, unsigned int index, void *result); ----- - -== DESCRIPTION - -The `nng_aio_set_output()` function sets the output result at _index_ -to _result_ for the asynchronous operation associated with _aio_. - -The type and semantics of output results are determined by specific -operations; the operation must supply appropriate output results when -the operation completes successfully. - -The valid values of _index_ range from zero (0) to three (3), as no operation -currently defined can return more than four results. -(This limit could increase in the future.) - -NOTE: Note that attempts to set results with an _index_ greater than -three (3) will be ignored. - -An output result set with this function may be retrieved later with -the xref:nng_aio_get_output.3.adoc[`nng_aio_get_output()`] function. - -== RETURN VALUES - -None. - -== ERRORS - -None. - -== SEE ALSO - -[.text-left] -xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], -xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], -xref:nng_aio_result.3.adoc[nng_aio_result(3)], -xref:nng_aio.5.adoc[nng_aio(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/man/nng_aio_start.3.adoc b/docs/man/nng_aio_start.3.adoc deleted file mode 100644 index 4c5d090a..00000000 --- a/docs/man/nng_aio_start.3.adoc +++ /dev/null @@ -1,69 +0,0 @@ -= nng_aio_start(3) -// -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// 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_start - start asynchronous I/O operation - -== SYNOPSIS - -[source, c] ----- -#include <nng/nng.h> - -typedef void (*nng_aio_cancelfn)(nng_aio *aio, void *arg, int err); - -void nng_aio_start(nng_aio *aio, nng_aio_cancelfn fn, void *arg); ----- - -== DESCRIPTION - -The `nng_aio_started()` 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_start()`, 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 xref:nng_aio_finish.3.adoc[`nng_aio_finish()`] is called, with the -error code specified by _err_. - -IMPORTANT: It is mandatory that I/O providers call -xref:nng_aio_finish.3.adoc[`nng_aio_finish()`] -*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_start()`, -although it is harmless if it does. - -== SEE ALSO - -[.text-left] -xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], -xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], -xref:nng_aio_result.3.adoc[nng_aio_result(3)], -xref:nng_aio.5.adoc[nng_aio(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/ref/api/aio.md b/docs/ref/api/aio.md index b6e0ad58..0d0fa8da 100644 --- a/docs/ref/api/aio.md +++ b/docs/ref/api/aio.md @@ -249,8 +249,10 @@ A maximum of four (4) `nng_iov` members may be supplied. ## Inputs and Outputs ```c -void nng_aio_set_input(nng_aio *aio, unsigned int index, void *param); +void *nng_aio_get_input(nng_aio *aio, unsigned int index); void *nng_aio_get_output(nng_aio *aio, unsigned int index); +void nng_aio_set_input(nng_aio *aio, unsigned int index, void *param); +void nng_aio_set_output(nng_aio *aio, unsigned int index, void *result); ``` Asynchronous operations can take additional input parameters, and @@ -259,12 +261,20 @@ provide additional result outputs besides the [result][`nng_aio_result`] code. The `nng_aio_set_input` function sets the input parameter at _index_ to _param_ for the operation associated with _aio_. -The `nng_aio_get_output` function returns the output result at _index_ -for the operation associated with _aio_. +The `nng_aio_set_output` function sets the output result at _index_ +to _result_ for the operation associated with _aio_. + +The `nng_aio_get_output` function returns the output result previously set by `nng_aio_set_output`. + +The `nng_aio_get_input` function returns the input parameter previously set by `nng_aio_set_input`. The type and semantics of input parameters and output results are determined by specific operations. The documentation for the operation should provide details. +> [!TIP] +> Most applications will not need to use `nng_aio_get_input` or `nng_aio_set_output`, as those +> are used by [I/O Providers][I/O provider]. + The valid values of _index_ range from zero (0) to three (3), as no operation currently defined can accept more than four parameters or return more than four additional results. @@ -306,6 +316,87 @@ Note that many of these operations are not guaranteed to perform a full transfer successful operation should check the amount of data actually transferred using [`nng_aio_count`], and if necessary resubmit the operation with a suitably updated vector of `nng_iov` using this function. +## I/O Providers + +This section documents functions that are used by I/O providers, and will not be relevant +for the majority of applications that simply utilize operations provided for by the library. + +However, these functions will be useful if an application wants to implement its own asynchronous operations using [`nng_aio`]. + +### Starting an Operation + +```c +typedef void (*nng_aio_cancelfn)(nng_aio *aio, void *arg, nng_err err); + +void nng_aio_reset(nng_aio *aio); +bool nng_aio_start(nng_aio *aio, nng_aio_cancelfn fn, void *arg); +``` + +The {{i:`nng_aio_reset`}} function resets various fields in the _aio_. +It can be called before starting an operation. + +The {{i:`nng_aio_start`}} function starts the operation associated with _aio_. +It implies the same reset as `nng_aio_reset`. Thus, `nng_aio_reset` is typically +only useful when used with operations that complete synchronously. +The `nng_aio_start` function also registers the cancellation function _fn_ and +associated argument _arg_ with the operation. This allows the operation to be canceled. + +> [!IMPORTANT] +> This function must not be called on an _aio_ that is already has an operation in progress. + +If _fn_ is `NULL`, then the operation cannot be canceled. + +If `nng_aio_start` returns `false`, then the _aio_ has been permanently stopped +and the operation cannot proceed. In this case the caller should cease all +work with _aio_, and must not call [`nng_aio_finish`] or any other function, +as the _aio_ is no longer valid for use. + +If `nng_aio_start` returns true, then the operation may proceed. + +> [!IMPORTANT] +> Failure to check the return value from `nng_aio_start` can lead to deadlocks +> or infinite loops. + +If the _aio_ is subsequently canceled, the cancellation routine _fn_ will be called +with _aio_ and _arg_ and an error value in _err_. +The _err_ indicates the reason that the operation is being canceled. + +If the operation cannot be canceled, _fn_ should just return without making any change. + +If _fn_ 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. + +> [!TIP] +> Ensure that cancellation and completion of the routine are thread safe. +> This usually involves the use of locks or other synchronization primitives. + +### Finishing an Operation + +```c +void nng_aio_finish(nng_aio *aio, nng_err err); +``` + +The {{i:`nng_aio_finish`}} function completes the operation associated with _aio_. +The result of the the status _err_. + +This function causes the callback associated with the _aio_ to called. +The _aio_ may not be referenced again by the caller. + +> [!TIP] +> Set any results using [`nng_aio_set_output`] before calling this function. + +The return value subsequently obtained from [`nng_aio_result`] for _aio_ will be _err_. + +> [!IMPORTANT] +> It is mandatory that operation providers call this function +> _exactly once_ when they are finished with the operation. +> After calling this function they _must not_ perform any further accesses +> to the _aio_. + ## See Also [Synchronization][synchronization], diff --git a/docs/ref/xref.md b/docs/ref/xref.md index cbaeb7c1..33c83b2b 100644 --- a/docs/ref/xref.md +++ b/docs/ref/xref.md @@ -101,7 +101,9 @@ [`nng_aio_set_timeout`]: ../api/aio.md#set-timeout [`nng_aio_set_iov`]: ../api/aio.md#scatter-gather-vectors [`nng_aio_get_output`]: ../api/aio.md#inputs-and-outputs +[`nng_aio_get_input`]: ../api/aio.md#inputs-and-outputs [`nng_aio_set_input`]: ../api/aio.md#inputs-and-outputs +[`nng_aio_set_output`]: ../api/aio.md#inputs-and-outputs [`nng_iov`]: ../api/aio.md#scatter-gather-vectors [`nng_socket_id`]: ../api/sock.md#socket-identity [`nng_socket_raw`]: ../api/sock.md#socket-identity @@ -202,10 +204,9 @@ [`nng_listener_set_tls`]: ../TODO.md [`nng_listener_get_tls`]: ../TODO.md [`nng_args_parse`]: ../api/args.md#parse-command-line-arguments -[`nng_aio_finish`]: ../TODO.md -[`nng_aio_reset`]: ../TODO.md -[`nng_aio_start`]: ../TODO.md -[`nng_aio_set_output`]: ../TODO.md +[`nng_aio_finish`]: ../api/aio.md#finishing-an-operation +[`nng_aio_reset`]: ../api/aio.md#starting-an-operation +[`nng_aio_start`]: ../api/aio.md#starting-an-operation [`nng_recv`]: ../TODO.md [`nng_listener_get_url`]: ../TODO.md [`nng_dialer_get_url`]: ../TODO.md @@ -506,3 +507,4 @@ [polyamorous]: ../proto/pair.md#polyamorous-mode [libnanomsg]: https://github.com/nanomsg/nanomsg [mangos]: https://github.com/nanomsg/mangos +[I/O provider]: ../api/aio.md#io-providers |
