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