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