Documentation for BIO flags and related functions.
Some checks failed
GitHub CI / check_update (push) Has been cancelled
GitHub CI / check_docs (push) Has been cancelled
GitHub CI / check-ansi (push) Has been cancelled
GitHub CI / basic_gcc (push) Has been cancelled
GitHub CI / basic_clang (push) Has been cancelled
GitHub CI / linux-arm64 (push) Has been cancelled
GitHub CI / freebsd-x86_64 (push) Has been cancelled
GitHub CI / minimal (push) Has been cancelled
GitHub CI / no-deprecated (push) Has been cancelled
GitHub CI / no-shared-ubuntu (push) Has been cancelled
GitHub CI / no-shared-macos (push) Has been cancelled
GitHub CI / non-caching (push) Has been cancelled
GitHub CI / address_ub_sanitizer (push) Has been cancelled
GitHub CI / fuzz_tests (push) Has been cancelled
GitHub CI / memory_sanitizer (push) Has been cancelled
GitHub CI / threads_sanitizer (push) Has been cancelled
GitHub CI / enable_non-default_options (push) Has been cancelled
GitHub CI / full_featured (push) Has been cancelled
GitHub CI / no-legacy (push) Has been cancelled
GitHub CI / legacy (push) Has been cancelled
GitHub CI / out-of-readonly-source-and-install-ubuntu (push) Has been cancelled
GitHub CI / out-of-readonly-source-and-install-macos (push) Has been cancelled
GitHub CI / external-tests (push) Has been cancelled
GitHub CI / external-test-pyca (3.9, 1.51.0) (push) Has been cancelled
GitHub CI / external-test-cf-quiche (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-11 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-12 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-13 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-14 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-15 distro:ubuntu-22.04 llvm-ppa-name:jammy]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-16 distro:ubuntu-22.04 llvm-ppa-name:jammy]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:clang-17 distro:ubuntu-22.04 llvm-ppa-name:jammy]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:gcc-10 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:gcc-11 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:gcc-12 distro:ubuntu-22.04]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:gcc-13 distro:ubuntu-22.04 gcc-ppa-name:ubuntu-toolchain-r/test]) (push) Has been cancelled
Compiler Zoo CI / compiler (map[cc:gcc-9 distro:ubuntu-22.04]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:aarch64-linux-gnu libs:libc6-dev-arm64-cross target:linux-aarch64]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:alpha-linux-gnu libs:libc6.1-dev-alpha-cross target:linux-alpha-gcc]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:arm-linux-gnueabi libs:libc6-dev-armel-cross target:linux-armv4 tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:arm-linux-gnueabihf libs:libc6-dev-armhf-cross target:linux-armv4 tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:hppa-linux-gnu fips:no libs:libc6-dev-hppa-cross target:-static linux-generic32 tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:hppa-linux-gnu libs:libc6-dev-hppa-cross target:linux-generic32 tests:none]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:i386-pc-msdosdjgpp libs:libc-djgpp-dev libwatt-djgpp-dev djgpp-utils ppa:jwt27/djgpp-toolchain target:no-threads 386 DJGPP tests:none]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:m68k-linux-gnu fips:no libs:libc6-dev-m68k-cross target:-static -m68040 linux-latomic -Wno-stringop-overflow tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:m68k-linux-gnu libs:libc6-dev-m68k-cross target:-mcfv4e -mxgot linux-latomic -Wno-stringop-overflow no-quic tests:none]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:mips-linux-gnu fips:no libs:libc6-dev-mips-cross target:-static linux-mips32 tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:mips-linux-gnu libs:libc6-dev-mips-cross target:linux-mips32 tests:none]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:mips64-linux-gnuabi64 fips:no libs:libc6-dev-mips64-cross target:-static linux64-mips64]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:mips64-linux-gnuabi64 libs:libc6-dev-mips64-cross target:linux64-mips64 tests:none]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:mipsel-linux-gnu libs:libc6-dev-mipsel-cross target:linux-mips32 tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:powerpc64le-linux-gnu libs:libc6-dev-ppc64el-cross target:linux-ppc64le]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:riscv64-linux-gnu libs:libc6-dev-riscv64-cross target:linux64-riscv64]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:s390x-linux-gnu libs:libc6-dev-s390x-cross target:linux64-s390x -Wno-stringop-overflow]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:sh4-linux-gnu libs:libc6-dev-sh4-cross target:no-async linux-latomic tests:-test_includes -test_store -test_x509_store]) (push) Has been cancelled
Cross Compile / cross-compilation (map[arch:sparc64-linux-gnu libs:libc6-dev-sparc64-cross target:linux64-sparcv9 tests:none]) (push) Has been cancelled
Trigger docs.openssl.org deployment / trigger (push) Has been cancelled
Fuzz-checker CI / fuzz-checker (map[cc:afl-clang-fast config:enable-fuzz-afl no-module install:afl++ name:AFL]) (push) Has been cancelled
Fuzz-checker CI / fuzz-checker (map[cc:clang-18 config:enable-fuzz-libfuzzer enable-asan enable-ubsan -fno-sanitize=function -fsanitize-coverage=trace-cmp -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION extra:enable-fips enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment ena… (push) Has been cancelled
Fuzz-checker CI / fuzz-checker (map[cc:clang-18 config:enable-fuzz-libfuzzer enable-asan enable-ubsan -fno-sanitize=function install:libfuzzer-18-dev libs:--with-fuzzer-lib=/usr/lib/llvm-18/lib/libFuzzer.a --with-fuzzer-include=/usr/include/clang/18/include/fuzzer linke… (push) Has been cancelled
CIFuzz / Fuzzing (push) Has been cancelled
Run-checker CI / run-checker (enable-ssl-trace) (push) Has been cancelled
Run-checker CI / run-checker (enable-trace enable-fips) (push) Has been cancelled
Run-checker CI / run-checker (no-cmp) (push) Has been cancelled
Run-checker CI / run-checker (no-cms) (push) Has been cancelled
Run-checker CI / run-checker (no-default-thread-pool) (push) Has been cancelled
Run-checker CI / run-checker (no-dgram) (push) Has been cancelled
Run-checker CI / run-checker (no-dh) (push) Has been cancelled
Run-checker CI / run-checker (no-dtls) (push) Has been cancelled
Run-checker CI / run-checker (no-ec) (push) Has been cancelled
Run-checker CI / run-checker (no-ecx) (push) Has been cancelled
Run-checker CI / run-checker (no-http) (push) Has been cancelled
Run-checker CI / run-checker (no-legacy) (push) Has been cancelled
Run-checker CI / run-checker (no-quic) (push) Has been cancelled
Run-checker CI / run-checker (no-sock) (push) Has been cancelled
Run-checker CI / run-checker (no-stdio) (push) Has been cancelled
Run-checker CI / run-checker (no-thread-pool) (push) Has been cancelled
Run-checker CI / run-checker (no-threads) (push) Has been cancelled
Run-checker CI / run-checker (no-tls) (push) Has been cancelled
Run-checker CI / run-checker (no-tls1_2) (push) Has been cancelled
Run-checker CI / run-checker (no-tls1_3) (push) Has been cancelled
Run-checker CI / run-checker (no-ui) (push) Has been cancelled
Run-checker merge / run-checker (enable-asan enable-ubsan no-shared no-asm -DOPENSSL_SMALL_FOOTPRINT -fno-sanitize=function) (push) Has been cancelled
Run-checker merge / run-checker (enable-ubsan no-asm -DOPENSSL_SMALL_FOOTPRINT -fno-sanitize=function) (push) Has been cancelled
Run-checker merge / run-checker (enable-weak-ssl-ciphers) (push) Has been cancelled
Run-checker merge / run-checker (enable-zlib) (push) Has been cancelled
Run-checker merge / run-checker (no-ct) (push) Has been cancelled
Run-checker merge / run-checker (no-dso) (push) Has been cancelled
Run-checker merge / run-checker (no-dynamic-engine) (push) Has been cancelled
Run-checker merge / run-checker (no-ec2m) (push) Has been cancelled
Run-checker merge / run-checker (no-engine no-shared) (push) Has been cancelled
Run-checker merge / run-checker (no-err) (push) Has been cancelled
Run-checker merge / run-checker (no-filenames) (push) Has been cancelled
Run-checker merge / run-checker (no-module) (push) Has been cancelled
Run-checker merge / run-checker (no-ocsp) (push) Has been cancelled
Run-checker merge / run-checker (no-pinshared) (push) Has been cancelled
Run-checker merge / run-checker (no-srp) (push) Has been cancelled
Run-checker merge / run-checker (no-srtp) (push) Has been cancelled
Run-checker merge / run-checker (no-ts) (push) Has been cancelled
Run-checker merge / threads_sanitizer_atomic_fallback (push) Has been cancelled
Windows GitHub CI / shared (map[arch:win32 config:--strict-warnings no-fips os:windows-2025]) (push) Has been cancelled
Windows GitHub CI / shared (map[arch:win64 config:enable-fips no-thread-pool no-quic os:windows-2025]) (push) Has been cancelled
Windows GitHub CI / shared (map[arch:win64 config:enable-fips os:windows-2022]) (push) Has been cancelled
Windows GitHub CI / plain (windows-2022) (push) Has been cancelled
Windows GitHub CI / minimal (windows-2022) (push) Has been cancelled
Windows GitHub CI / cygwin (windows-2022, map[arch:win64 config:-DCMAKE_C_COMPILER=gcc --strict-warnings no-fips]) (push) Has been cancelled

Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29311)

(cherry picked from commit e12870deb0)
This commit is contained in:
Igor Ustinov
2025-12-04 17:05:59 +01:00
committed by Tomas Mraz
parent 0e4c3eed4a
commit e7c699b67a
4 changed files with 208 additions and 3 deletions

View File

@@ -691,6 +691,10 @@ DEPEND[html/man3/BIO_set_callback.html]=man3/BIO_set_callback.pod
GENERATE[html/man3/BIO_set_callback.html]=man3/BIO_set_callback.pod
DEPEND[man/man3/BIO_set_callback.3]=man3/BIO_set_callback.pod
GENERATE[man/man3/BIO_set_callback.3]=man3/BIO_set_callback.pod
DEPEND[html/man3/BIO_set_flags.html]=man3/BIO_set_flags.pod
GENERATE[html/man3/BIO_set_flags.html]=man3/BIO_set_flags.pod
DEPEND[man/man3/BIO_set_flags.3]=man3/BIO_set_flags.pod
GENERATE[man/man3/BIO_set_flags.3]=man3/BIO_set_flags.pod
DEPEND[html/man3/BIO_should_retry.html]=man3/BIO_should_retry.pod
GENERATE[html/man3/BIO_should_retry.html]=man3/BIO_should_retry.pod
DEPEND[man/man3/BIO_should_retry.3]=man3/BIO_should_retry.pod
@@ -3112,6 +3116,7 @@ html/man3/BIO_s_null.html \
html/man3/BIO_s_socket.html \
html/man3/BIO_sendmmsg.html \
html/man3/BIO_set_callback.html \
html/man3/BIO_set_flags.html \
html/man3/BIO_should_retry.html \
html/man3/BIO_socket_wait.html \
html/man3/BN_BLINDING_new.html \
@@ -3759,6 +3764,7 @@ man/man3/BIO_s_null.3 \
man/man3/BIO_s_socket.3 \
man/man3/BIO_sendmmsg.3 \
man/man3/BIO_set_callback.3 \
man/man3/BIO_set_flags.3 \
man/man3/BIO_should_retry.3 \
man/man3/BIO_socket_wait.3 \
man/man3/BN_BLINDING_new.3 \

194
doc/man3/BIO_set_flags.pod Normal file
View File

@@ -0,0 +1,194 @@
=pod
=head1 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
- manipulate and interpret BIO flags
=head1 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);
=head1 DESCRIPTION
A B<BIO> has an internal set of bit flags that describe its state. These
functions and macros are used primarily by B<BIO> implementations and by code
that builds B<BIO> chains to manipulate those flags.
BIO_set_flags() sets the bits given in I<flags> in the B<BIO> I<b>. Any bits
already set in the B<BIO>'s flag word remain set.
BIO_clear_flags() clears the bits given in I<flags> from the B<BIO> I<b>. Any
other bits in the flag word are left unchanged.
BIO_test_flags() tests the bits given in I<flags> in the B<BIO> I<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 B<BIO> I<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 B<BIO> I<b> as being in a retryable state
by setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
B<BIO_FLAGS_READ> flag to indicate that the retry condition is
associated with a read operation.
BIO_set_retry_write() marks the B<BIO> I<b> as being in a retryable state
by setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
B<BIO_FLAGS_WRITE> flag to indicate that the retry condition is
associated with a write operation.
BIO_set_retry_special() marks the B<BIO> I<b> as being in a retryable state
by setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
B<BIO_FLAGS_IO_SPECIAL> flag to indicate that the retry condition is
associated with a read operation some "special" condition.
The precise meaning of this condition depends on the B<BIO> type.
BIO_clear_retry_flags() clears all retry-related bits from I<b>, i.e.
B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>, B<BIO_FLAGS_IO_SPECIAL>, and
B<BIO_FLAGS_SHOULD_RETRY>.
BIO_get_retry_flags() returns retry-related bits that are
currently set in I<b>. The result is a subset of
B<BIO_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
L<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():
=over 4
=item B<BIO_FLAGS_READ>
The last I/O operation should be retried when the B<BIO> becomes readable.
This flag is normally set by the B<BIO> implementation via BIO_set_retry_read()
after a failed read operation.
=item B<BIO_FLAGS_WRITE>
The last I/O operation should be retried when the B<BIO> becomes writable.
This flag is normally set by the B<BIO> implementation via BIO_set_retry_write()
after a failed write operation.
=item B<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 B<BIO>
type and is usually obtained via BIO_get_retry_BIO() and
BIO_get_retry_reason() as described in L<BIO_should_retry(3)>.
This flag is normally set by the B<BIO> implementation via
BIO_set_retry_special().
=item B<BIO_FLAGS_RWS>
The bitwise OR of B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE> and
B<BIO_FLAGS_IO_SPECIAL>. This mask is used when clearing or extracting
the retry-direction bits.
=item B<BIO_FLAGS_SHOULD_RETRY>
Set if the last I/O operation on the B<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 B<BIO> implementation.
=item B<BIO_FLAGS_BASE64_NO_NL>
When set on a base64 filter B<BIO> this flag disables the generation of
newline characters in the encoded output and causes newlines to be ignored
in the input. See also L<BIO_f_base64(3)>.
The flag has no effect on any other built-in B<BIO> types.
=item B<BIO_FLAGS_MEM_RDONLY>
When set on a memory B<BIO> this flag indicates that the underlying buffer is
read only. Attempts to write to such a B<BIO> will fail.
The flag has no effect on any other built-in B<BIO> types.
=item B<BIO_FLAGS_NONCLEAR_RST>
On a memory B<BIO> this flag modifies the behaviour of BIO_reset(). When it
is set, resetting the B<BIO> does not clear the underlying buffer but only
resets the current read position.
The flag has no effect on any other built-in B<BIO> types.
=item B<BIO_FLAGS_IN_EOF>
This flag may be used by a B<BIO> implementation to indicate that the end
of the input stream has been reached. However, B<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 B<BIO> in a
chain. Applications must therefore not test this flag directly to
determine whether EOF has been reached, and must use BIO_eof() instead.
=back
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.
=head1 RETURN VALUES
BIO_get_flags() returns a bit mask of the flags currently set on the B<BIO>.
BIO_test_flags() returns a bit mask consisting of those flags from the
argument that are currently set in the B<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 from
B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>, B<BIO_FLAGS_IO_SPECIAL>, and
B<BIO_FLAGS_SHOULD_RETRY> that are currently set in the I<BIO>.
=head1 NOTES
Ordinary application code will rarely need to call BIO_set_flags(),
BIO_clear_flags() or BIO_test_flags() directly. They are intended for B<BIO>
implementations and for code that forwards retry state from one B<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
L<BIO_should_retry(3)> instead of inspecting the flags directly.
These functions and macros are not thread-safe. If a single B<BIO>
is accessed from multiple threads, the caller must provide appropriate
external synchronisation.
=head1 SEE ALSO
L<BIO_should_retry(3)>, L<BIO_f_base64(3)>, L<bio(7)>
=head1 HISTORY
The functions and macros described here have been available in OpenSSL since
at least 1.1.0 (B<BIO_FLAGS_IN_EOF> since 1.1.1).
=head1 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
L<https://www.openssl.org/source/license.html>.
=cut

View File

@@ -170,7 +170,6 @@ BIO_asn1_get_prefix(3)
BIO_asn1_get_suffix(3)
BIO_asn1_set_prefix(3)
BIO_asn1_set_suffix(3)
BIO_clear_flags(3)
BIO_copy_next_retry(3)
BIO_dgram_is_sctp(3)
BIO_dgram_non_fatal_error(3)
@@ -208,7 +207,6 @@ BIO_nwrite(3)
BIO_nwrite0(3)
BIO_s_datagram_sctp(3)
BIO_s_log(3)
BIO_set_flags(3)
BIO_set_tcp_ndelay(3)
BIO_sock_error(3)
BIO_sock_info(3)
@@ -217,7 +215,6 @@ BIO_sock_non_fatal_error(3)
BIO_sock_should_retry(3)
BIO_socket_ioctl(3)
BIO_socket_nbio(3)
BIO_test_flags(3)
BN_GF2m_add(3)
BN_GF2m_arr2poly(3)
BN_GF2m_mod(3)

View File

@@ -203,6 +203,8 @@ BIO_get_conn_port define
BIO_get_conn_ip_family define
BIO_get_conn_mode define
BIO_get_fd define
BIO_get_flags define
BIO_get_retry_flags define
BIO_get_fp define
BIO_get_indent define
BIO_get_info_callback define
@@ -237,6 +239,12 @@ BIO_set_conn_port define
BIO_set_conn_ip_family define
BIO_set_conn_mode define
BIO_set_fd define
BIO_set_flags define
BIO_set_retry_read define
BIO_set_retry_write define
BIO_set_retry_special define
BIO_clear_flags define
BIO_clear_retry_flags define
BIO_set_fp define
BIO_set_indent define
BIO_set_info_callback define