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