BIO_SET_FLAGS(3SSL)
π NAME π
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, BIO_get_retry_flags β bestie, these are the little guys that poke at a BIO's flags and read them back out. Manipulate and interpret BIO flags, that's the whole vibe. π¦
This is from the OpenSSL manual, section 3SSL, and it's genuinely so useful iykyk.
β¨ 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 π
okay so. A BIO has an internal set of bit flags that describe its state β like its little mood ring but for I/O. π These functions and macros are used primarily by BIO implementations and by code that builds BIO chains, to manipulate those flags.
BIO_set_flags()sets the bits given in flags in the BIO b. Any bits already set in the BIO's flag word remain set β it's additive, no cap. β¨BIO_clear_flags()clears the bits given in flags from the BIO b. Any other bits in the flag word are left unchanged. Not me touching only what you asked for.BIO_test_flags()tests the bits given in flags in the BIO b and returns a nonzero value if any of them are currently set and zero otherwise.BIO_get_flags()returns the current flag word from the BIO b. This is equivalent to testing for all bits and returning the result.
The following convenience macros are built on top of these primitives and are used to maintain the retry state of a BIO:
BIO_set_retry_read()marks the BIO b as 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 BIO b as 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 BIO b as 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. π (fr fr, it's vibe-dependent, check your BIO type)BIO_clear_retry_flags()clears all retry-related bits from b, i.e.BIO_FLAGS_READ,BIO_FLAGS_WRITE,BIO_FLAGS_IO_SPECIAL, andBIO_FLAGS_SHOULD_RETRY.BIO_get_retry_flags()returns retry-related bits that are currently set in b. 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. (the "RWS" girlies know π )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.
The following flag can be used only with the base64 encoding BIO. The result of using this flag with other BIOs is unpredictable. π
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.
The following flags can be used only with the memory buffer BIO and secure memory buffer BIO. The result of using these flags with other BIOs is unpredictable. π
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 is for internal use only. It should not be used outside BIO implementations. π« (hands off bestie, that's not for us)
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. π
π 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 β like, this is not your everyday main character move. They are 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. β¨
β οΈ These functions and macros are not thread-safe. If a single BIO is accessed from multiple threads, the caller must provide appropriate external synchronisation. No cap β you gotta lock it yourself.
π 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). So they've been serving looks for a minute. π
π COPYRIGHT π
Copyright 2025-2026 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 thing bestie π this was OpenSSL 4.0.3, dated 2026-09-29, and it lives in the manual as BIO_SET_FLAGS(3SSL). slay, go forth and retry responsibly π§β¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms