import libcrypto (LibreSSL 2.5.2)
[unleashed.git] / lib / libcrypto / man / BIO_should_retry.3
blob601bb997a7c1c5b381a78be64ab0679fa057b473
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
3 .\"
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2010, 2016 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
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
17 .\"    distribution.
18 .\"
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/)"
23 .\"
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.
28 .\"
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.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
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.
50 .\"
51 .Dd $Mdocdate: December 6 2016 $
52 .Dt BIO_SHOULD_RETRY 3
53 .Os
54 .Sh NAME
55 .Nm BIO_should_retry ,
56 .Nm BIO_should_read ,
57 .Nm BIO_should_write ,
58 .Nm BIO_should_io_special ,
59 .Nm BIO_retry_type ,
60 .Nm BIO_should_retry ,
61 .Nm BIO_get_retry_BIO ,
62 .Nm BIO_get_retry_reason
63 .Nd BIO retry functions
64 .Sh SYNOPSIS
65 .In openssl/bio.h
66 .Ft int
67 .Fo BIO_should_read
68 .Fa "BIO *b"
69 .Fc
70 .Ft int
71 .Fo BIO_should_write
72 .Fa "BIO *b"
73 .Fc
74 .Ft int
75 .Fo BIO_should_io_special
76 .Fa "BIO *b"
77 .Fc
78 .Ft int
79 .Fo BIO_retry_type
80 .Fa "BIO *b"
81 .Fc
82 .Ft int
83 .Fo BIO_should_retry
84 .Fa "BIO *b"
85 .Fc
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
92 .Ft BIO *
93 .Fo BIO_get_retry_BIO
94 .Fa "BIO *bio"
95 .Fa "int *reason"
96 .Fc
97 .Ft int
98 .Fo BIO_get_retry_reason
99 .Fa "BIO *bio"
101 .Sh DESCRIPTION
102 These functions determine why a BIO is not able to read or write data.
103 They will typically be called after a failed
104 .Xr BIO_read 3
106 .Xr BIO_write 3
107 call.
109 .Fn BIO_should_retry
110 is true if the call that produced this condition
111 should be retried at a later time.
114 .Fn BIO_should_retry
115 is false, the cause is an error condition.
117 .Fn BIO_should_read
118 is true if the cause of the condition is that a BIO needs to read data.
120 .Fn BIO_should_write
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.
127 .Fn BIO_retry_type
128 returns a mask of the cause of a retry condition consisting of the values
129 .Dv BIO_FLAGS_READ ,
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
137 .Fa reason
138 is not
139 .Dv NULL
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 ,
154 .Fn BIO_retry_type
155 are implemented as macros.
158 .Fn BIO_should_retry
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
162 .Xr BIO_read 3
163 on a socket BIO returns 0 and
164 .Fn BIO_should_retry
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
175 .Fn BIO_should_retry
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
182 .Xr BIO_read 3 .
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
192 is satisfied.
193 How this is done depends on the underlying I/O structure.
195 For example if the cause is ultimately a socket and
196 .Fn BIO_should_read
197 is true then a call to
198 .Xr select 2
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
202 .Xr select 2
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
212 .Xr select 2
213 (or equivalent) call.
214 .Sh SEE ALSO
215 .Xr BIO_new 3 ,
216 .Xr BIO_read 3
217 .Sh BUGS
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.