Latest update.
This commit is contained in:
@@ -27,40 +27,40 @@ ASYNC_get_current_job, ASYNC_block_pause, ASYNC_unblock_pause, ASYNC_is_capable
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
OpenSSL implements asynchronous capabilities through an ASYNC_JOB. This
|
||||
OpenSSL implements asynchronous capabilities through an B<ASYNC_JOB>. This
|
||||
represents code that can be started and executes until some event occurs. At
|
||||
that point the code can be paused and control returns to user code until some
|
||||
subsequent event indicates that the job can be resumed.
|
||||
|
||||
The creation of an ASYNC_JOB is a relatively expensive operation. Therefore, for
|
||||
efficiency reasons, jobs can be created up front and reused many times. They are
|
||||
held in a pool until they are needed, at which point they are removed from the
|
||||
pool, used, and then returned to the pool when the job completes. If the user
|
||||
application is multi-threaded, then ASYNC_init_thread() may be called for each
|
||||
thread that will initiate asynchronous jobs. Before
|
||||
The creation of an B<ASYNC_JOB> is a relatively expensive operation. Therefore,
|
||||
for efficiency reasons, jobs can be created up front and reused many times. They
|
||||
are held in a pool until they are needed, at which point they are removed from
|
||||
the pool, used, and then returned to the pool when the job completes. If the
|
||||
user application is multi-threaded, then ASYNC_init_thread() may be called for
|
||||
each thread that will initiate asynchronous jobs. Before
|
||||
user code exits per-thread resources need to be cleaned up. This will normally
|
||||
occur automatically (see L<OPENSSL_init_crypto(3)>) but may be explicitly
|
||||
initiated by using ASYNC_cleanup_thread(). No asynchronous jobs must be
|
||||
outstanding for the thread when ASYNC_cleanup_thread() is called. Failing to
|
||||
ensure this will result in memory leaks.
|
||||
|
||||
The B<max_size> argument limits the number of ASYNC_JOBs that will be held in
|
||||
the pool. If B<max_size> is set to 0 then no upper limit is set. When an
|
||||
ASYNC_JOB is needed but there are none available in the pool already then one
|
||||
will be automatically created, as long as the total of ASYNC_JOBs managed by the
|
||||
pool does not exceed B<max_size>. When the pool is first initialised
|
||||
B<init_size> ASYNC_JOBs will be created immediately. If ASYNC_init_thread() is
|
||||
not called before the pool is first used then it will be called automatically
|
||||
with a B<max_size> of 0 (no upper limit) and an B<init_size> of 0 (no ASYNC_JOBs
|
||||
created up front).
|
||||
The I<max_size> argument limits the number of B<ASYNC_JOB>s that will be held in
|
||||
the pool. If I<max_size> is set to 0 then no upper limit is set. When an
|
||||
B<ASYNC_JOB> is needed but there are none available in the pool already then one
|
||||
will be automatically created, as long as the total of B<ASYNC_JOB>s managed by
|
||||
the pool does not exceed I<max_size>. When the pool is first initialised
|
||||
I<init_size> B<ASYNC_JOB>s will be created immediately. If ASYNC_init_thread()
|
||||
is not called before the pool is first used then it will be called automatically
|
||||
with a I<max_size> of 0 (no upper limit) and an I<init_size> of 0 (no
|
||||
B<ASYNC_JOB>s created up front).
|
||||
|
||||
An asynchronous job is started by calling the ASYNC_start_job() function.
|
||||
Initially B<*job> should be NULL. B<ctx> should point to an ASYNC_WAIT_CTX
|
||||
object created through the L<ASYNC_WAIT_CTX_new(3)> function. B<ret> should
|
||||
Initially I<*job> should be NULL. I<ctx> should point to an B<ASYNC_WAIT_CTX>
|
||||
object created through the L<ASYNC_WAIT_CTX_new(3)> function. I<ret> should
|
||||
point to a location where the return value of the asynchronous function should
|
||||
be stored on completion of the job. B<func> represents the function that should
|
||||
be started asynchronously. The data pointed to by B<args> and of size B<size>
|
||||
will be copied and then passed as an argument to B<func> when the job starts.
|
||||
be stored on completion of the job. I<func> represents the function that should
|
||||
be started asynchronously. The data pointed to by I<args> and of size I<size>
|
||||
will be copied and then passed as an argument to I<func> when the job starts.
|
||||
ASYNC_start_job will return one of the following values:
|
||||
|
||||
=over 4
|
||||
@@ -78,47 +78,47 @@ again at a later time.
|
||||
=item B<ASYNC_PAUSE>
|
||||
|
||||
The job was successfully started but was "paused" before it completed (see
|
||||
ASYNC_pause_job() below). A handle to the job is placed in B<*job>. Other work
|
||||
ASYNC_pause_job() below). A handle to the job is placed in I<*job>. Other work
|
||||
can be performed (if desired) and the job restarted at a later time. To restart
|
||||
a job call ASYNC_start_job() again passing the job handle in B<*job>. The
|
||||
B<func>, B<args> and B<size> parameters will be ignored when restarting a job.
|
||||
a job call ASYNC_start_job() again passing the job handle in I<*job>. The
|
||||
I<func>, I<args> and I<size> parameters will be ignored when restarting a job.
|
||||
When restarting a job ASYNC_start_job() B<must> be called from the same thread
|
||||
that the job was originally started from.
|
||||
|
||||
=item B<ASYNC_FINISH>
|
||||
|
||||
The job completed. B<*job> will be NULL and the return value from B<func> will
|
||||
be placed in B<*ret>.
|
||||
The job completed. I<*job> will be NULL and the return value from I<func> will
|
||||
be placed in I<*ret>.
|
||||
|
||||
=back
|
||||
|
||||
At any one time there can be a maximum of one job actively running per thread
|
||||
(you can have many that are paused). ASYNC_get_current_job() can be used to get
|
||||
a pointer to the currently executing ASYNC_JOB. If no job is currently executing
|
||||
then this will return NULL.
|
||||
a pointer to the currently executing B<ASYNC_JOB>. If no job is currently
|
||||
executing then this will return NULL.
|
||||
|
||||
If executing within the context of a job (i.e. having been called directly or
|
||||
indirectly by the function "func" passed as an argument to ASYNC_start_job())
|
||||
then ASYNC_pause_job() will immediately return control to the calling
|
||||
application with ASYNC_PAUSE returned from the ASYNC_start_job() call. A
|
||||
subsequent call to ASYNC_start_job passing in the relevant ASYNC_JOB in the
|
||||
B<*job> parameter will resume execution from the ASYNC_pause_job() call. If
|
||||
application with B<ASYNC_PAUSE> returned from the ASYNC_start_job() call. A
|
||||
subsequent call to ASYNC_start_job passing in the relevant B<ASYNC_JOB> in the
|
||||
I<*job> parameter will resume execution from the ASYNC_pause_job() call. If
|
||||
ASYNC_pause_job() is called whilst not within the context of a job then no
|
||||
action is taken and ASYNC_pause_job() returns immediately.
|
||||
|
||||
ASYNC_get_wait_ctx() can be used to get a pointer to the ASYNC_WAIT_CTX
|
||||
for the B<job>. ASYNC_WAIT_CTXs contain two different ways to notify
|
||||
ASYNC_get_wait_ctx() can be used to get a pointer to the B<ASYNC_WAIT_CTX>
|
||||
for the I<job>. B<ASYNC_WAIT_CTX>s contain two different ways to notify
|
||||
applications that a job is ready to be resumed. One is a "wait" file
|
||||
descriptor, and the other is a "callback" mechanism.
|
||||
|
||||
The "wait" file descriptor associated with ASYNC_WAIT_CTX is used for
|
||||
The "wait" file descriptor associated with B<ASYNC_WAIT_CTX> is used for
|
||||
applications to wait for the file descriptor to be ready for "read" using a
|
||||
system function call such as select or poll (being ready for "read" indicates
|
||||
that the job should be resumed). If no file descriptor is made available then
|
||||
an application will have to periodically "poll" the job by attempting to restart
|
||||
it to see if it is ready to continue.
|
||||
|
||||
ASYNC_WAIT_CTXs also have a "callback" mechanism to notify applications. The
|
||||
B<ASYNC_WAIT_CTX>s also have a "callback" mechanism to notify applications. The
|
||||
callback is set by an application, and it will be automatically called when an
|
||||
engine completes a cryptography operation, so that the application can resume
|
||||
the paused work flow without polling. An engine could be written to look whether
|
||||
@@ -134,10 +134,10 @@ ASYNC_unblock_pause(). These functions can be nested, e.g. if you call
|
||||
ASYNC_block_pause() twice then you must call ASYNC_unblock_pause() twice in
|
||||
order to re-enable pausing. If these functions are called while there is no
|
||||
currently active job then they have no effect. This functionality can be useful
|
||||
to avoid deadlock scenarios. For example during the execution of an ASYNC_JOB an
|
||||
application acquires a lock. It then calls some cryptographic function which
|
||||
to avoid deadlock scenarios. For example during the execution of an B<ASYNC_JOB>
|
||||
an application acquires a lock. It then calls some cryptographic function which
|
||||
invokes ASYNC_pause_job(). This returns control back to the code that created
|
||||
the ASYNC_JOB. If that code then attempts to acquire the same lock before
|
||||
the B<ASYNC_JOB>. If that code then attempts to acquire the same lock before
|
||||
resuming the original job then a deadlock can occur. By calling
|
||||
ASYNC_block_pause() immediately after acquiring the lock and
|
||||
ASYNC_unblock_pause() immediately before releasing it then this situation cannot
|
||||
@@ -150,17 +150,17 @@ can be used to detect whether the current platform is async capable or not.
|
||||
|
||||
ASYNC_init_thread returns 1 on success or 0 otherwise.
|
||||
|
||||
ASYNC_start_job returns one of ASYNC_ERR, ASYNC_NO_JOBS, ASYNC_PAUSE or
|
||||
ASYNC_FINISH as described above.
|
||||
ASYNC_start_job returns one of B<ASYNC_ERR>, B<ASYNC_NO_JOBS>, B<ASYNC_PAUSE> or
|
||||
B<ASYNC_FINISH> as described above.
|
||||
|
||||
ASYNC_pause_job returns 0 if an error occurred or 1 on success. If called when
|
||||
not within the context of an ASYNC_JOB then this is counted as success so 1 is
|
||||
returned.
|
||||
not within the context of an B<ASYNC_JOB> then this is counted as success so 1
|
||||
is returned.
|
||||
|
||||
ASYNC_get_current_job returns a pointer to the currently executing ASYNC_JOB or
|
||||
NULL if not within the context of a job.
|
||||
ASYNC_get_current_job returns a pointer to the currently executing B<ASYNC_JOB>
|
||||
or NULL if not within the context of a job.
|
||||
|
||||
ASYNC_get_wait_ctx() returns a pointer to the ASYNC_WAIT_CTX for the job.
|
||||
ASYNC_get_wait_ctx() returns a pointer to the B<ASYNC_WAIT_CTX> for the job.
|
||||
|
||||
ASYNC_is_capable() returns 1 if the current platform is async capable or 0
|
||||
otherwise.
|
||||
|
||||
Reference in New Issue
Block a user