1 .\" $OpenBSD: BIO_should_retry.3,v 1.5 2016/12/06 14:45:08 schwarze Exp $
2 .\" OpenSSL 60e24554 Apr 6 14:45:18 2010 +0000
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2010, 2016 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: December 6 2016 $
52 .Dt BIO_SHOULD_RETRY 3
55 .Nm BIO_should_retry ,
57 .Nm BIO_should_write ,
58 .Nm BIO_should_io_special ,
60 .Nm BIO_should_retry ,
61 .Nm BIO_get_retry_BIO ,
62 .Nm BIO_get_retry_reason
63 .Nd BIO retry functions
75 .Fo BIO_should_io_special
86 .Fd #define BIO_FLAGS_READ 0x01
87 .Fd #define BIO_FLAGS_WRITE 0x02
88 .Fd #define BIO_FLAGS_IO_SPECIAL 0x04
89 .Fd #define BIO_FLAGS_RWS \e
90 .Fd \& (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
91 .Fd #define BIO_FLAGS_SHOULD_RETRY 0x08
98 .Fo BIO_get_retry_reason
102 These functions determine why a BIO is not able to read or write data.
103 They will typically be called after a failed
110 is true if the call that produced this condition
111 should be retried at a later time.
115 is false, the cause is an error condition.
118 is true if the cause of the condition is that a BIO needs to read data.
121 is true if the cause of the condition is that a BIO needs to write data.
123 .Fn BIO_should_io_special
124 is true if some "special" condition
125 (i.e. a reason other than reading or writing) is the cause of the condition.
128 returns a mask of the cause of a retry condition consisting of the values
130 .Dv BIO_FLAGS_WRITE ,
131 .Dv BIO_FLAGS_IO_SPECIAL
132 though current BIO types will only set one of these.
134 .Fn BIO_get_retry_BIO
135 determines the precise reason for the special condition.
136 It returns the BIO that caused this condition and if
140 it contains the reason code.
141 The meaning of the reason code and the action that should be taken
142 depends on the type of BIO that resulted in this condition.
144 .Fn BIO_get_retry_reason
145 returns the reason for a special condition
146 if passed the relevant BIO, for example as returned by
147 .Fn BIO_get_retry_BIO .
149 .Fn BIO_should_retry ,
150 .Fn BIO_should_read ,
151 .Fn BIO_should_write ,
152 .Fn BIO_should_io_special ,
155 are implemented as macros.
159 returns false, then the precise "error condition" depends on
160 the BIO type that caused it and the return code of the BIO operation.
161 For example if a call to
163 on a socket BIO returns 0 and
165 is false, then the cause will be that the connection closed.
166 A similar condition on a file BIO will mean that it has reached EOF.
167 Some BIO types may place additional information on the error queue.
168 For more details see the individual BIO type manual pages.
170 If the underlying I/O structure is in a blocking mode,
171 almost all current BIO types will not request a retry,
172 because the underlying I/O calls will not.
173 If the application knows that the BIO type will never
174 signal a retry then it need not call
176 after a failed BIO I/O call.
177 This is typically done with file BIOs.
179 SSL BIOs are the only current exception to this rule:
180 they can request a retry even if the underlying I/O structure
181 is blocking, if a handshake occurs during a call to
183 An application can retry the failed call immediately
184 or avoid this situation by setting
185 .Dv SSL_MODE_AUTO_RETRY
186 on the underlying SSL structure.
188 While an application may retry a failed non-blocking call immediately,
189 this is likely to be very inefficient because the call will fail
190 repeatedly until data can be processed or is available.
191 An application will normally wait until the necessary condition
193 How this is done depends on the underlying I/O structure.
195 For example if the cause is ultimately a socket and
197 is true then a call to
199 may be made to wait until data is available
200 and then retry the BIO operation.
201 By combining the retry conditions of several non-blocking BIOs in a single
203 call it is possible to service several BIOs in a single thread,
204 though the performance may be poor if SSL BIOs are present because
205 long delays can occur during the initial handshake process.
207 It is possible for a BIO to block indefinitely if the underlying I/O
208 structure cannot process or return any data.
209 This depends on the behaviour of the platforms I/O functions.
210 This is often not desirable: one solution is to use non-blocking I/O
211 and use a timeout on the
213 (or equivalent) call.
218 The OpenSSL ASN.1 functions cannot gracefully deal with non-blocking I/O:
219 they cannot retry after a partial read or write.
220 This is usually worked around by only passing the relevant data to ASN.1
221 functions when the entire structure can be read or written.