Blame doc/man3/ASYNC_WAIT_CTX_new.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
ASYNC_WAIT_CTX_new, ASYNC_WAIT_CTX_free, ASYNC_WAIT_CTX_set_wait_fd,
Packit c4476c
ASYNC_WAIT_CTX_get_fd, ASYNC_WAIT_CTX_get_all_fds,
Packit c4476c
ASYNC_WAIT_CTX_get_changed_fds, ASYNC_WAIT_CTX_clear_fd - functions to manage
Packit c4476c
waiting for asynchronous jobs to complete
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/async.h>
Packit c4476c
Packit c4476c
 ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void);
Packit c4476c
 void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx);
Packit c4476c
 int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
Packit c4476c
                                OSSL_ASYNC_FD fd,
Packit c4476c
                                void *custom_data,
Packit c4476c
                                void (*cleanup)(ASYNC_WAIT_CTX *, const void *,
Packit c4476c
                                                OSSL_ASYNC_FD, void *));
Packit c4476c
 int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,
Packit c4476c
                           OSSL_ASYNC_FD *fd, void **custom_data);
Packit c4476c
 int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,
Packit c4476c
                                size_t *numfds);
Packit c4476c
 int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,
Packit c4476c
                                    size_t *numaddfds, OSSL_ASYNC_FD *delfd,
Packit c4476c
                                    size_t *numdelfds);
Packit c4476c
 int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
Packit c4476c
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
For an overview of how asynchronous operations are implemented in OpenSSL see
Packit c4476c
L<ASYNC_start_job(3)>. An ASYNC_WAIT_CTX object represents an asynchronous
Packit c4476c
"session", i.e. a related set of crypto operations. For example in SSL terms
Packit c4476c
this would have a one-to-one correspondence with an SSL connection.
Packit c4476c
Packit c4476c
Application code must create an ASYNC_WAIT_CTX using the ASYNC_WAIT_CTX_new()
Packit c4476c
function prior to calling ASYNC_start_job() (see L<ASYNC_start_job(3)>). When
Packit c4476c
the job is started it is associated with the ASYNC_WAIT_CTX for the duration of
Packit c4476c
that job. An ASYNC_WAIT_CTX should only be used for one ASYNC_JOB at any one
Packit c4476c
time, but can be reused after an ASYNC_JOB has finished for a subsequent
Packit c4476c
ASYNC_JOB. When the session is complete (e.g. the SSL connection is closed),
Packit c4476c
application code cleans up with ASYNC_WAIT_CTX_free().
Packit c4476c
Packit c4476c
ASYNC_WAIT_CTXs can have "wait" file descriptors associated with them. Calling
Packit c4476c
ASYNC_WAIT_CTX_get_all_fds() and passing in a pointer to an ASYNC_WAIT_CTX in
Packit c4476c
the B<ctx> parameter will return the wait file descriptors associated with that
Packit c4476c
job in B<*fd>. The number of file descriptors returned will be stored in
Packit c4476c
B<*numfds>. It is the caller's responsibility to ensure that sufficient memory
Packit c4476c
has been allocated in B<*fd> to receive all the file descriptors. Calling
Packit c4476c
ASYNC_WAIT_CTX_get_all_fds() with a NULL B<fd> value will return no file
Packit c4476c
descriptors but will still populate B<*numfds>. Therefore application code is
Packit c4476c
typically expected to call this function twice: once to get the number of fds,
Packit c4476c
and then again when sufficient memory has been allocated. If only one
Packit c4476c
asynchronous engine is being used then normally this call will only ever return
Packit c4476c
one fd. If multiple asynchronous engines are being used then more could be
Packit c4476c
returned.
Packit c4476c
Packit c4476c
The function ASYNC_WAIT_CTX_get_changed_fds() can be used to detect if any fds
Packit c4476c
have changed since the last call time ASYNC_start_job() returned an ASYNC_PAUSE
Packit c4476c
result (or since the ASYNC_WAIT_CTX was created if no ASYNC_PAUSE result has
Packit c4476c
been received). The B<numaddfds> and B<numdelfds> parameters will be populated
Packit c4476c
with the number of fds added or deleted respectively. B<*addfd> and B<*delfd>
Packit c4476c
will be populated with the list of added and deleted fds respectively. Similarly
Packit c4476c
to ASYNC_WAIT_CTX_get_all_fds() either of these can be NULL, but if they are not
Packit c4476c
NULL then the caller is responsible for ensuring sufficient memory is allocated.
Packit c4476c
Packit c4476c
Implementors of async aware code (e.g. engines) are encouraged to return a
Packit c4476c
stable fd for the lifetime of the ASYNC_WAIT_CTX in order to reduce the "churn"
Packit c4476c
of regularly changing fds - although no guarantees of this are provided to
Packit c4476c
applications.
Packit c4476c
Packit c4476c
Applications can wait for the file descriptor to be ready for "read" using a
Packit c4476c
system function call such as select or poll (being ready for "read" indicates
Packit c4476c
that the job should be resumed). If no file descriptor is made available then an
Packit c4476c
application will have to periodically "poll" the job by attempting to restart it
Packit c4476c
to see if it is ready to continue.
Packit c4476c
Packit c4476c
Async aware code (e.g. engines) can get the current ASYNC_WAIT_CTX from the job
Packit c4476c
via L<ASYNC_get_wait_ctx(3)> and provide a file descriptor to use for waiting
Packit c4476c
on by calling ASYNC_WAIT_CTX_set_wait_fd(). Typically this would be done by an
Packit c4476c
engine immediately prior to calling ASYNC_pause_job() and not by end user code.
Packit c4476c
An existing association with a file descriptor can be obtained using
Packit c4476c
ASYNC_WAIT_CTX_get_fd() and cleared using ASYNC_WAIT_CTX_clear_fd(). Both of
Packit c4476c
these functions requires a B<key> value which is unique to the async aware
Packit c4476c
code.  This could be any unique value but a good candidate might be the
Packit c4476c
B<ENGINE *> for the engine. The B<custom_data> parameter can be any value, and
Packit c4476c
will be returned in a subsequent call to ASYNC_WAIT_CTX_get_fd(). The
Packit c4476c
ASYNC_WAIT_CTX_set_wait_fd() function also expects a pointer to a "cleanup"
Packit c4476c
routine. This can be NULL but if provided will automatically get called when
Packit c4476c
the ASYNC_WAIT_CTX is freed, and gives the engine the opportunity to close the
Packit c4476c
fd or any other resources. Note: The "cleanup" routine does not get called if
Packit c4476c
the fd is cleared directly via a call to ASYNC_WAIT_CTX_clear_fd().
Packit c4476c
Packit c4476c
An example of typical usage might be an async capable engine. User code would
Packit c4476c
initiate cryptographic operations. The engine would initiate those operations
Packit c4476c
asynchronously and then call ASYNC_WAIT_CTX_set_wait_fd() followed by
Packit c4476c
ASYNC_pause_job() to return control to the user code. The user code can then
Packit c4476c
perform other tasks or wait for the job to be ready by calling "select" or other
Packit c4476c
similar function on the wait file descriptor. The engine can signal to the user
Packit c4476c
code that the job should be resumed by making the wait file descriptor
Packit c4476c
"readable". Once resumed the engine should clear the wake signal on the wait
Packit c4476c
file descriptor.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
ASYNC_WAIT_CTX_new() returns a pointer to the newly allocated ASYNC_WAIT_CTX or
Packit c4476c
NULL on error.
Packit c4476c
Packit c4476c
ASYNC_WAIT_CTX_set_wait_fd, ASYNC_WAIT_CTX_get_fd, ASYNC_WAIT_CTX_get_all_fds,
Packit c4476c
ASYNC_WAIT_CTX_get_changed_fds and ASYNC_WAIT_CTX_clear_fd all return 1 on
Packit c4476c
success or 0 on error.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
On Windows platforms the openssl/async.h header is dependent on some
Packit c4476c
of the types customarily made available by including windows.h. The
Packit c4476c
application developer is likely to require control over when the latter
Packit c4476c
is included, commonly as one of the first included headers. Therefore
Packit c4476c
it is defined as an application developer's responsibility to include
Packit c4476c
windows.h prior to async.h.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<crypto(7)>, L<ASYNC_start_job(3)>
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
ASYNC_WAIT_CTX_new(), ASYNC_WAIT_CTX_free(), ASYNC_WAIT_CTX_set_wait_fd(),
Packit c4476c
ASYNC_WAIT_CTX_get_fd(), ASYNC_WAIT_CTX_get_all_fds(),
Packit c4476c
ASYNC_WAIT_CTX_get_changed_fds() and ASYNC_WAIT_CTX_clear_fd()
Packit c4476c
were added in OpenSSL 1.1.0.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut