xref: /freebsd/crypto/openssl/doc/man3/BIO_should_retry.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimBIO_should_read, BIO_should_write,
6e71b7053SJung-uk KimBIO_should_io_special, BIO_retry_type, BIO_should_retry,
7e71b7053SJung-uk KimBIO_get_retry_BIO, BIO_get_retry_reason, BIO_set_retry_reason - BIO retry
8e71b7053SJung-uk Kimfunctions
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim=head1 SYNOPSIS
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim #include <openssl/bio.h>
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim int BIO_should_read(BIO *b);
15e71b7053SJung-uk Kim int BIO_should_write(BIO *b);
16e71b7053SJung-uk Kim int BIO_should_io_special(iBIO *b);
17e71b7053SJung-uk Kim int BIO_retry_type(BIO *b);
18e71b7053SJung-uk Kim int BIO_should_retry(BIO *b);
19e71b7053SJung-uk Kim
20e71b7053SJung-uk Kim BIO *BIO_get_retry_BIO(BIO *bio, int *reason);
21e71b7053SJung-uk Kim int BIO_get_retry_reason(BIO *bio);
22e71b7053SJung-uk Kim void BIO_set_retry_reason(BIO *bio, int reason);
23e71b7053SJung-uk Kim
24e71b7053SJung-uk Kim=head1 DESCRIPTION
25e71b7053SJung-uk Kim
26e71b7053SJung-uk KimThese functions determine why a BIO is not able to read or write data.
27e71b7053SJung-uk KimThey will typically be called after a failed BIO_read_ex() or BIO_write_ex()
28e71b7053SJung-uk Kimcall.
29e71b7053SJung-uk Kim
30e71b7053SJung-uk KimBIO_should_retry() is true if the call that produced this condition
31e71b7053SJung-uk Kimshould then be retried at a later time.
32e71b7053SJung-uk Kim
33e71b7053SJung-uk KimIf BIO_should_retry() is false then the cause is an error condition.
34e71b7053SJung-uk Kim
35e71b7053SJung-uk KimBIO_should_read() is true if the cause of the condition is that the BIO
36e71b7053SJung-uk Kimhas insufficient data to return. Check for readability and/or retry the
37e71b7053SJung-uk Kimlast operation.
38e71b7053SJung-uk Kim
39e71b7053SJung-uk KimBIO_should_write() is true if the cause of the condition is that the BIO
40e71b7053SJung-uk Kimhas pending data to write. Check for writability and/or retry the
41e71b7053SJung-uk Kimlast operation.
42e71b7053SJung-uk Kim
43e71b7053SJung-uk KimBIO_should_io_special() is true if some "special" condition, that is a
44e71b7053SJung-uk Kimreason other than reading or writing is the cause of the condition.
45e71b7053SJung-uk Kim
46e71b7053SJung-uk KimBIO_retry_type() returns a mask of the cause of a retry condition
47e71b7053SJung-uk Kimconsisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
48e71b7053SJung-uk KimB<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
49e71b7053SJung-uk Kimthese.
50e71b7053SJung-uk Kim
51e71b7053SJung-uk KimBIO_get_retry_BIO() determines the precise reason for the special
52e71b7053SJung-uk Kimcondition, it returns the BIO that caused this condition and if
53e71b7053SJung-uk KimB<reason> is not NULL it contains the reason code. The meaning of
54e71b7053SJung-uk Kimthe reason code and the action that should be taken depends on
55e71b7053SJung-uk Kimthe type of BIO that resulted in this condition.
56e71b7053SJung-uk Kim
57e71b7053SJung-uk KimBIO_get_retry_reason() returns the reason for a special condition if
58e71b7053SJung-uk Kimpassed the relevant BIO, for example as returned by BIO_get_retry_BIO().
59e71b7053SJung-uk Kim
60e71b7053SJung-uk KimBIO_set_retry_reason() sets the retry reason for a special condition for a given
61e71b7053SJung-uk KimBIO. This would usually only be called by BIO implementations.
62e71b7053SJung-uk Kim
63e71b7053SJung-uk Kim=head1 NOTES
64e71b7053SJung-uk Kim
65e71b7053SJung-uk KimBIO_should_read(), BIO_should_write(), BIO_should_io_special(),
66e71b7053SJung-uk KimBIO_retry_type(), and BIO_should_retry(), are implemented as macros.
67e71b7053SJung-uk Kim
68e71b7053SJung-uk KimIf BIO_should_retry() returns false then the precise "error condition"
69e71b7053SJung-uk Kimdepends on the BIO type that caused it and the return code of the BIO
70e71b7053SJung-uk Kimoperation. For example if a call to BIO_read_ex() on a socket BIO returns
71e71b7053SJung-uk Kim0 and BIO_should_retry() is false then the cause will be that the
72e71b7053SJung-uk Kimconnection closed. A similar condition on a file BIO will mean that it
73e71b7053SJung-uk Kimhas reached EOF. Some BIO types may place additional information on
74e71b7053SJung-uk Kimthe error queue. For more details see the individual BIO type manual
75e71b7053SJung-uk Kimpages.
76e71b7053SJung-uk Kim
77e71b7053SJung-uk KimIf the underlying I/O structure is in a blocking mode almost all current
78e71b7053SJung-uk KimBIO types will not request a retry, because the underlying I/O
79e71b7053SJung-uk Kimcalls will not. If the application knows that the BIO type will never
80e71b7053SJung-uk Kimsignal a retry then it need not call BIO_should_retry() after a failed
81e71b7053SJung-uk KimBIO I/O call. This is typically done with file BIOs.
82e71b7053SJung-uk Kim
83e71b7053SJung-uk KimSSL BIOs are the only current exception to this rule: they can request a
84e71b7053SJung-uk Kimretry even if the underlying I/O structure is blocking, if a handshake
85e71b7053SJung-uk Kimoccurs during a call to BIO_read(). An application can retry the failed
86e71b7053SJung-uk Kimcall immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
87e71b7053SJung-uk Kimon the underlying SSL structure.
88e71b7053SJung-uk Kim
89e71b7053SJung-uk KimWhile an application may retry a failed non blocking call immediately
90e71b7053SJung-uk Kimthis is likely to be very inefficient because the call will fail
91e71b7053SJung-uk Kimrepeatedly until data can be processed or is available. An application
92e71b7053SJung-uk Kimwill normally wait until the necessary condition is satisfied. How
93e71b7053SJung-uk Kimthis is done depends on the underlying I/O structure.
94e71b7053SJung-uk Kim
95e71b7053SJung-uk KimFor example if the cause is ultimately a socket and BIO_should_read()
96e71b7053SJung-uk Kimis true then a call to select() may be made to wait until data is
97e71b7053SJung-uk Kimavailable and then retry the BIO operation. By combining the retry
98e71b7053SJung-uk Kimconditions of several non blocking BIOs in a single select() call
99e71b7053SJung-uk Kimit is possible to service several BIOs in a single thread, though
100e71b7053SJung-uk Kimthe performance may be poor if SSL BIOs are present because long delays
101e71b7053SJung-uk Kimcan occur during the initial handshake process.
102e71b7053SJung-uk Kim
103e71b7053SJung-uk KimIt is possible for a BIO to block indefinitely if the underlying I/O
104e71b7053SJung-uk Kimstructure cannot process or return any data. This depends on the behaviour of
105e71b7053SJung-uk Kimthe platforms I/O functions. This is often not desirable: one solution
106e71b7053SJung-uk Kimis to use non blocking I/O and use a timeout on the select() (or
107e71b7053SJung-uk Kimequivalent) call.
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=head1 BUGS
110e71b7053SJung-uk Kim
111e71b7053SJung-uk KimThe OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
112e71b7053SJung-uk Kimthat is they cannot retry after a partial read or write. This is usually
113e71b7053SJung-uk Kimworked around by only passing the relevant data to ASN1 functions when
114e71b7053SJung-uk Kimthe entire structure can be read or written.
115e71b7053SJung-uk Kim
116e71b7053SJung-uk Kim=head1 RETURN VALUES
117e71b7053SJung-uk Kim
118e71b7053SJung-uk KimBIO_should_read(), BIO_should_write(), BIO_should_io_special(), and
119e71b7053SJung-uk KimBIO_should_retry() return either 1 or 0 based on the actual conditions
120e71b7053SJung-uk Kimof the B<BIO>.
121e71b7053SJung-uk Kim
122e71b7053SJung-uk KimBIO_retry_type() returns a flag combination presenting the cause of a retry
123e71b7053SJung-uk Kimcondition or false if there is no retry condition.
124e71b7053SJung-uk Kim
125e71b7053SJung-uk KimBIO_get_retry_BIO() returns a valid B<BIO> structure.
126e71b7053SJung-uk Kim
127e71b7053SJung-uk KimBIO_get_retry_reason() returns the reason for a special condition.
128e71b7053SJung-uk Kim
129e71b7053SJung-uk Kim=head1 SEE ALSO
130e71b7053SJung-uk Kim
131*b077aed3SPierre ProncheryL<bio(7)>
132e71b7053SJung-uk Kim
133e71b7053SJung-uk Kim=head1 HISTORY
134e71b7053SJung-uk Kim
135e71b7053SJung-uk KimThe BIO_get_retry_reason() and BIO_set_retry_reason() functions were added in
136e71b7053SJung-uk KimOpenSSL 1.1.0.
137e71b7053SJung-uk Kim
138e71b7053SJung-uk Kim=head1 COPYRIGHT
139e71b7053SJung-uk Kim
140e71b7053SJung-uk KimCopyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
141e71b7053SJung-uk Kim
142*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
143e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
144e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
145e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
146e71b7053SJung-uk Kim
147e71b7053SJung-uk Kim=cut
148