1BIO_should_retry(3) OpenSSL BIO_should_retry(3)
2
3
4
6 BIO_should_retry, BIO_should_read, BIO_should_write,
7 BIO_should_io_special, BIO_retry_type, BIO_should_retry,
8 BIO_get_retry_BIO, BIO_get_retry_reason - BIO retry functions
9
11 #include <openssl/bio.h>
12
13 #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
14 #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
15 #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
16 #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
17 #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
18
19 #define BIO_FLAGS_READ 0x01
20 #define BIO_FLAGS_WRITE 0x02
21 #define BIO_FLAGS_IO_SPECIAL 0x04
22 #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
23 #define BIO_FLAGS_SHOULD_RETRY 0x08
24
25 BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
26 int BIO_get_retry_reason(BIO *bio);
27
29 These functions determine why a BIO is not able to read or write data.
30 They will typically be called after a failed BIO_read() or BIO_write()
31 call.
32
33 BIO_should_retry() is true if the call that produced this condition
34 should then be retried at a later time.
35
36 If BIO_should_retry() is false then the cause is an error condition.
37
38 BIO_should_read() is true if the cause of the condition is that a BIO
39 needs to read data.
40
41 BIO_should_write() is true if the cause of the condition is that a BIO
42 needs to read data.
43
44 BIO_should_io_special() is true if some "special" condition, that is a
45 reason other than reading or writing is the cause of the condition.
46
47 BIO_retry_type() returns a mask of the cause of a retry condition
48 consisting of the values BIO_FLAGS_READ, BIO_FLAGS_WRITE,
49 BIO_FLAGS_IO_SPECIAL though current BIO types will only set one of
50 these.
51
52 BIO_get_retry_BIO() determines the precise reason for the special
53 condition, it returns the BIO that caused this condition and if reason
54 is not NULL it contains the reason code. The meaning of the reason code
55 and the action that should be taken depends on the type of BIO that
56 resulted in this condition.
57
58 BIO_get_retry_reason() returns the reason for a special condition if
59 passed the relevant BIO, for example as returned by
60 BIO_get_retry_BIO().
61
63 If BIO_should_retry() returns false then the precise "error condition"
64 depends on the BIO type that caused it and the return code of the BIO
65 operation. For example if a call to BIO_read() on a socket BIO returns
66 0 and BIO_should_retry() is false then the cause will be that the
67 connection closed. A similar condition on a file BIO will mean that it
68 has reached EOF. Some BIO types may place additional information on the
69 error queue. For more details see the individual BIO type manual pages.
70
71 If the underlying I/O structure is in a blocking mode almost all
72 current BIO types will not request a retry, because the underlying I/O
73 calls will not. If the application knows that the BIO type will never
74 signal a retry then it need not call BIO_should_retry() after a failed
75 BIO I/O call. This is typically done with file BIOs.
76
77 SSL BIOs are the only current exception to this rule: they can request
78 a retry even if the underlying I/O structure is blocking, if a
79 handshake occurs during a call to BIO_read(). An application can retry
80 the failed call immediately or avoid this situation by setting
81 SSL_MODE_AUTO_RETRY on the underlying SSL structure.
82
83 While an application may retry a failed non blocking call immediately
84 this is likely to be very inefficient because the call will fail
85 repeatedly until data can be processed or is available. An application
86 will normally wait until the necessary condition is satisfied. How this
87 is done depends on the underlying I/O structure.
88
89 For example if the cause is ultimately a socket and BIO_should_read()
90 is true then a call to select() may be made to wait until data is
91 available and then retry the BIO operation. By combining the retry
92 conditions of several non blocking BIOs in a single select() call it is
93 possible to service several BIOs in a single thread, though the
94 performance may be poor if SSL BIOs are present because long delays can
95 occur during the initial handshake process.
96
97 It is possible for a BIO to block indefinitely if the underlying I/O
98 structure cannot process or return any data. This depends on the
99 behaviour of the platforms I/O functions. This is often not desirable:
100 one solution is to use non blocking I/O and use a timeout on the
101 select() (or equivalent) call.
102
104 The OpenSSL ASN1 functions cannot gracefully deal with non blocking
105 I/O: that is they cannot retry after a partial read or write. This is
106 usually worked around by only passing the relevant data to ASN1
107 functions when the entire structure can be read or written.
108
110 TBA
111
112
113
1141.0.2o 2020-08-01 BIO_should_retry(3)