BIO_SET_FLAGS(3ossl)
π NAME π
okay so bestie, welcome to BIO_set_flags(3ossl) β this is the OpenSSL page for the little flag-wrangling crew: BIO_set_flags, BIO_clear_flags, BIO_test_flags, BIO_get_flags, BIO_set_retry_read, BIO_set_retry_write, BIO_set_retry_special, BIO_clear_retry_flags, and BIO_get_retry_flags β literally all of them exist to manipulate and interpret BIO flags. π
β¨ SYNOPSIS β¨
#include <openssl/bio.h>
void BIO_set_flags(BIO *b, int flags);
void BIO_clear_flags(BIO *b, int flags);
int BIO_test_flags(const BIO *b, int flags);
int BIO_get_flags(const BIO *b);
void BIO_set_retry_read(BIO *b);
void BIO_set_retry_write(BIO *b);
void BIO_set_retry_special(BIO *b);
void BIO_clear_retry_flags(BIO *b);
int BIO_get_retry_flags(BIO *b);
π¦ DESCRIPTION π¦
so a BIO has its own internal lil set of bit flags that describe its state, right? And these functions and macros are used primarily by BIO implementations and by code that builds BIO chains, to mess with those flags. Not your everyday main-character API, iykyk. π«
BIO_set_flags()β sets the bits given inflagsin the BIOb. Any bits already set in the BIO's flag word remain set. We're adding, not replacing, bestie. β¨BIO_clear_flags()β clears the bits given inflagsfrom the BIOb. Any other bits in the flag word are left unchanged. It's giving selective removal. π§ΉBIO_test_flags()β tests the bits given inflagsin the BIOband returns a nonzero value if any of them are currently set, and zero otherwise.BIO_get_flags()β returns the current flag word from the BIOb. This is equivalent to testing for all bits and returning the result. π―
The following convenience macros are built on top of those primitives, and they're the ones that maintain the retry state of a BIO:
BIO_set_retry_read()β marks the BIObas being in a retryable state by setting theBIO_FLAGS_SHOULD_RETRYflag. In addition, it sets theBIO_FLAGS_READflag to indicate that the retry condition is associated with a read operation. πBIO_set_retry_write()β marks the BIObas being in a retryable state by setting theBIO_FLAGS_SHOULD_RETRYflag. In addition, it sets theBIO_FLAGS_WRITEflag to indicate that the retry condition is associated with a write operation. βοΈBIO_set_retry_special()β marks the BIObas being in a retryable state by setting theBIO_FLAGS_SHOULD_RETRYflag. In addition, it sets theBIO_FLAGS_IO_SPECIALflag to indicate that the retry condition is associated with a read operation some "special" condition. The precise meaning of this condition depends on the BIO type. (yes, the original sentence is a lil wobbly, but that's exactly what it says, no cap β don't come for me, come for the manpage π)BIO_clear_retry_flags()β clears all retry-related bits fromb, i.e.BIO_FLAGS_READ,BIO_FLAGS_WRITE,BIO_FLAGS_IO_SPECIAL, andBIO_FLAGS_SHOULD_RETRY. Full reset, iconic. πBIO_get_retry_flags()β returns retry-related bits that are currently set inb. The result is a subset ofBIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY.
The retry bits are interpreted by the higher level macros BIO_should_read(), BIO_should_write(), BIO_should_io_special(), BIO_retry_type() and BIO_should_retry(), as documented in BIO_should_retry(3). Application code will typically use those macros rather than manipulate the underlying flags directly. π
The following flag bits are currently defined for use with BIO_set_flags(), BIO_clear_flags() and BIO_test_flags():
BIO_FLAGS_READβ the last I/O operation should be retried when the BIO becomes readable. This flag is normally set by the BIO implementation viaBIO_set_retry_read()after a failed read operation. πBIO_FLAGS_WRITEβ the last I/O operation should be retried when the BIO becomes writable. This flag is normally set by the BIO implementation viaBIO_set_retry_write()after a failed write operation.BIO_FLAGS_IO_SPECIALβ the last I/O operation should be retried when some "special" condition becomes true. The precise meaning of this condition depends on the BIO type and is usually obtained viaBIO_get_retry_BIO()andBIO_get_retry_reason()as described inBIO_should_retry(3). This flag is normally set by the BIO implementation viaBIO_set_retry_special().BIO_FLAGS_RWSβ the bitwise OR ofBIO_FLAGS_READ,BIO_FLAGS_WRITEandBIO_FLAGS_IO_SPECIAL. This mask is used when clearing or extracting the retry-direction bits. π§BIO_FLAGS_SHOULD_RETRYβ set if the last I/O operation on the BIO should be retried at a later time. If this bit is not set then the condition is treated as an error. This flag is normally set by the BIO implementation. β οΈBIO_FLAGS_BASE64_NO_NLβ when set on a base64 filter BIO, this flag disables the generation of newline characters in the encoded output and causes newlines to be ignored in the input. See alsoBIO_f_base64(3). The flag has no effect on any other built-in BIO types. πBIO_FLAGS_MEM_RDONLYβ when set on a memory BIO, this flag indicates that the underlying buffer is read only. Attempts to write to such a BIO will fail. The flag has no effect on any other built-in BIO types. πBIO_FLAGS_NONCLEAR_RSTβ on a memory BIO, this flag modifies the behaviour ofBIO_reset(). When it is set, resetting the BIO does not clear the underlying buffer but only resets the current read position. The flag has no effect on any other built-in BIO types. πBIO_FLAGS_IN_EOFβ this flag may be used by a BIO implementation to indicate that the end of the input stream has been reached. However, BIO types are not required to use this flag to signal end-of-file conditions; they may rely on other mechanisms such as system calls or by querying the next BIO in a chain. Applications must therefore not test this flag directly to determine whether EOF has been reached, and must useBIO_eof()instead. π¨
A range of additional flag values is reserved for internal use by OpenSSL to track kernel TLS (KTLS) state. This range and the corresponding flag macros are not part of the public API and must not be used by applications. Hands off, bestie. π₯
π RETURN VALUES π
BIO_get_flags()returns a bit mask of the flags currently set on the BIO.BIO_test_flags()returns a bit mask consisting of those flags from the argument that are currently set in the BIO. Consequently, it returns a nonzero value if and only if at least one of the requested flags is set.BIO_get_retry_flags()returns a bit mask consisting of those flags fromBIO_FLAGS_READ,BIO_FLAGS_WRITE,BIO_FLAGS_IO_SPECIAL, andBIO_FLAGS_SHOULD_RETRYthat are currently set in the BIO.
πΈ NOTES πΈ
Ordinary application code will rarely need to call BIO_set_flags(), BIO_clear_flags() or BIO_test_flags() directly. They're intended for BIO implementations and for code that forwards retry state from one BIO in a chain to another. After a failed I/O operation, applications should normally use BIO_should_retry() and related macros as described in BIO_should_retry(3) instead of inspecting the flags directly. Live your life through the high-level macros, periodt. π
These functions and macros are not thread-safe. If a single BIO is accessed from multiple threads, the caller must provide appropriate external synchronisation. Do not skip this, fr fr. π
π«Ά SEE ALSO π«Ά
BIO_should_retry(3), BIO_f_base64(3), bio(7)
β HISTORY β
The functions and macros described here have been available in OpenSSL since at least 1.1.0 (BIO_FLAGS_IN_EOF since 1.1.1). Been iconic for a minute. π
π COPYRIGHT π
Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html.
and that's the whole vibe check, bestie πβ¨ this was OpenSSL 3.5.9, dated 2026-09-29 β slay, go forth and BIO_should_retry() responsibly ππ¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms