---
name: "libressl-BIO_should_retry"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BIO_should_retry"
---

# libressl-BIO\_should\_retry(3)

BIO retry functions

## NAME

**BIO\_should\_read**, **BIO\_should\_write**, **BIO\_should\_io\_special**, **BIO\_retry\_type**, **BIO\_should\_retry**, **BIO\_get\_retry\_BIO**, **BIO\_get\_retry\_reason**, **BIO\_set\_retry\_reason** – BIO retry functions

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bio.h\>**

*int*\

**BIO\_should\_read**(*BIO \*b*);

*int*\

**BIO\_should\_write**(*BIO \*b*);

*int*\

**BIO\_should\_io\_special**(*BIO \*b*);

*int*\

**BIO\_retry\_type**(*BIO \*b*);

*int*\

**BIO\_should\_retry**(*BIO \*b*);

**#define BIO\_FLAGS\_READ 0x01**

**#define BIO\_FLAGS\_WRITE 0x02**

**#define BIO\_FLAGS\_IO\_SPECIAL 0x04**

**#define BIO\_FLAGS\_RWS \\**

 **(BIO\_FLAGS\_READ\|BIO\_FLAGS\_WRITE\|BIO\_FLAGS\_IO\_SPECIAL)**

**#define BIO\_FLAGS\_SHOULD\_RETRY 0x08**

*BIO* *\**\

**BIO\_get\_retry\_BIO**(*BIO \*bio*, *int \*reason*);

*int*\

**BIO\_get\_retry\_reason**(*BIO \*bio*);

*void*\

**BIO\_set\_retry\_reason**(*BIO \*bio*, *int reason*);

## DESCRIPTION

These functions determine why a BIO is not able to read or write data. They will typically be called after a failed BIO\_read(3) or BIO\_write(3) call.

**BIO\_should\_retry**() returns 1 if the call that produced this condition should be retried at a later time, or 0 if an error occurred.

**BIO\_should\_read**() returns 1 if the cause of the retry condition is that a BIO needs to read data, or 0 otherwise.

**BIO\_should\_write**() returns 1 if the cause of the retry condition is that a BIO needs to write data, or 0 otherwise.

**BIO\_should\_io\_special**() returns 1 if some special condition (i.e. a reason other than reading or writing) is the cause of the retry condition, or 0 otherwise.

**BIO\_retry\_type**() returns the bitwise OR of one or more of the flags BIO\_FLAGS\_READ, BIO\_FLAGS\_WRITE, and BIO\_FLAGS\_IO\_SPECIAL representing the cause of the current retry condition, or 0 if there is no retry condition. Current BIO types only set one of the flags at a time.

**BIO\_get\_retry\_BIO**() determines the precise reason for the special condition. It walks the BIO chain starting at *bio* and returns the BIO that caused this condition. If there is no special condition, *bio* itself is returned. If *reason* is not a NULL pointer, \**reason* is set to one of the following reason codes:

- 0

  There is no special condition.

- BIO\_RR\_ACCEPT

  [accept(2)](/accept/2.md) would have blocked. This can occur for BIOs created from BIO\_s\_accept(3) or BIO\_f\_ssl(3).

- BIO\_RR\_CONNECT

  [connect(2)](/connect/2.md) would have blocked. This can occur for BIOs created from BIO\_s\_connect(3) or BIO\_f\_ssl(3).

- BIO\_RR\_SSL\_X509\_LOOKUP

  An application callback set by SSL\_CTX\_set\_client\_cert\_cb(3) has asked to be called again. This can occur for BIOs created from BIO\_f\_ssl(3).

**BIO\_get\_retry\_reason**() returns one of the above reason codes for a special condition that occurred in *bio*. It does not walk the chain and returns 0 if no special condition occurred in *bio* itself.

**BIO\_set\_retry\_reason**() sets the retry reason for a special condition for the given *bio*. It is intended to be called by functions implementing a BIO type rather than by functions merely using BIOs.

**BIO\_should\_retry**(), **BIO\_should\_read**(), **BIO\_should\_write**(), **BIO\_should\_io\_special**(), and **BIO\_retry\_type**() are implemented as macros.

If **BIO\_should\_retry**() returns false, then the precise "error condition" depends on the BIO type that caused it and the return code of the BIO operation. For example if a call to BIO\_read(3) on a socket BIO returns 0 and **BIO\_should\_retry**() is false, then the cause will be that the connection closed. A similar condition on a file BIO will mean that it has reached EOF. Some BIO types may place additional information on the error queue. For more details see the individual BIO type manual pages.

If the underlying I/O structure is in a blocking mode, almost all current BIO types will not request a retry, because the underlying I/O calls will not. If the application knows that the BIO type will never signal a retry then it need not call **BIO\_should\_retry**() after a failed BIO I/O call. This is typically done with file BIOs.

SSL BIOs are the only current exception to this rule: they can request a retry even if the underlying I/O structure is blocking, if a handshake occurs during a call to BIO\_read(3). An application can retry the failed call immediately or avoid this situation by setting SSL\_MODE\_AUTO\_RETRY on the underlying SSL structure.

While an application may retry a failed non-blocking call immediately, this is likely to be very inefficient because the call will fail repeatedly until data can be processed or is available. An application will normally wait until the necessary condition is satisfied. How this is done depends on the underlying I/O structure.

For example if the cause is ultimately a socket and **BIO\_should\_read**() is true then a call to [select(2)](/select/2.md) may be made to wait until data is available and then retry the BIO operation. By combining the retry conditions of several non-blocking BIOs in a single [select(2)](/select/2.md) call it is possible to service several BIOs in a single thread, though the performance may be poor if SSL BIOs are present because long delays can occur during the initial handshake process.

It is possible for a BIO to block indefinitely if the underlying I/O structure cannot process or return any data. This depends on the behaviour of the platforms I/O functions. This is often not desirable: one solution is to use non-blocking I/O and use a timeout on the [select(2)](/select/2.md) (or equivalent) call.

## SEE ALSO

BIO\_new(3), BIO\_read(3)

## HISTORY

**BIO\_should\_read**(), **BIO\_should\_write**(), **BIO\_retry\_type**(), and **BIO\_should\_retry**() first appeared in SSLeay 0.6.0. **BIO\_should\_io\_special**(), **BIO\_get\_retry\_BIO**(), and **BIO\_get\_retry\_reason**() first appeared in SSLeay 0.8.0. All these functions have been available since OpenBSD 2.4.

**BIO\_set\_retry\_reason**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 7.1.

## BUGS

The OpenSSL ASN.1 functions cannot gracefully deal with non-blocking I/O: they cannot retry after a partial read or write. This is usually worked around by only passing the relevant data to ASN.1 functions when the entire structure can be read or written.
