xref: /freebsd/crypto/openssl/doc/man3/BIO_set_flags.pod (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
1*f25b8c9fSEnji Cooper=pod
2*f25b8c9fSEnji Cooper
3*f25b8c9fSEnji Cooper=head1 NAME
4*f25b8c9fSEnji Cooper
5*f25b8c9fSEnji CooperBIO_set_flags, BIO_clear_flags, BIO_test_flags, BIO_get_flags,
6*f25b8c9fSEnji CooperBIO_set_retry_read, BIO_set_retry_write, BIO_set_retry_special,
7*f25b8c9fSEnji CooperBIO_clear_retry_flags, BIO_get_retry_flags
8*f25b8c9fSEnji Cooper- manipulate and interpret BIO flags
9*f25b8c9fSEnji Cooper
10*f25b8c9fSEnji Cooper=head1 SYNOPSIS
11*f25b8c9fSEnji Cooper
12*f25b8c9fSEnji Cooper #include <openssl/bio.h>
13*f25b8c9fSEnji Cooper
14*f25b8c9fSEnji Cooper void BIO_set_flags(BIO *b, int flags);
15*f25b8c9fSEnji Cooper void BIO_clear_flags(BIO *b, int flags);
16*f25b8c9fSEnji Cooper int  BIO_test_flags(const BIO *b, int flags);
17*f25b8c9fSEnji Cooper int  BIO_get_flags(const BIO *b);
18*f25b8c9fSEnji Cooper
19*f25b8c9fSEnji Cooper void BIO_set_retry_read(BIO *b);
20*f25b8c9fSEnji Cooper void BIO_set_retry_write(BIO *b);
21*f25b8c9fSEnji Cooper void BIO_set_retry_special(BIO *b);
22*f25b8c9fSEnji Cooper void BIO_clear_retry_flags(BIO *b);
23*f25b8c9fSEnji Cooper int  BIO_get_retry_flags(BIO *b);
24*f25b8c9fSEnji Cooper
25*f25b8c9fSEnji Cooper=head1 DESCRIPTION
26*f25b8c9fSEnji Cooper
27*f25b8c9fSEnji CooperA B<BIO> has an internal set of bit flags that describe its state.  These
28*f25b8c9fSEnji Cooperfunctions and macros are used primarily by B<BIO> implementations and by code
29*f25b8c9fSEnji Cooperthat builds B<BIO> chains to manipulate those flags.
30*f25b8c9fSEnji Cooper
31*f25b8c9fSEnji CooperBIO_set_flags() sets the bits given in I<flags> in the B<BIO> I<b>.  Any bits
32*f25b8c9fSEnji Cooperalready set in the B<BIO>'s flag word remain set.
33*f25b8c9fSEnji Cooper
34*f25b8c9fSEnji CooperBIO_clear_flags() clears the bits given in I<flags> from the B<BIO> I<b>.  Any
35*f25b8c9fSEnji Cooperother bits in the flag word are left unchanged.
36*f25b8c9fSEnji Cooper
37*f25b8c9fSEnji CooperBIO_test_flags() tests the bits given in I<flags> in the B<BIO> I<b> and
38*f25b8c9fSEnji Cooperreturns a nonzero value if any of them are currently set and zero
39*f25b8c9fSEnji Cooperotherwise.
40*f25b8c9fSEnji Cooper
41*f25b8c9fSEnji CooperBIO_get_flags() returns the current flag word from the B<BIO> I<b>.  This is
42*f25b8c9fSEnji Cooperequivalent to testing for all bits and returning the result.
43*f25b8c9fSEnji Cooper
44*f25b8c9fSEnji CooperThe following convenience macros are built on top of these primitives and are
45*f25b8c9fSEnji Cooperused to maintain the retry state of a BIO:
46*f25b8c9fSEnji Cooper
47*f25b8c9fSEnji CooperBIO_set_retry_read() marks the B<BIO> I<b> as being in a retryable state
48*f25b8c9fSEnji Cooperby setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
49*f25b8c9fSEnji CooperB<BIO_FLAGS_READ> flag to indicate that the retry condition is
50*f25b8c9fSEnji Cooperassociated with a read operation.
51*f25b8c9fSEnji Cooper
52*f25b8c9fSEnji CooperBIO_set_retry_write() marks the B<BIO> I<b> as being in a retryable state
53*f25b8c9fSEnji Cooperby setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
54*f25b8c9fSEnji CooperB<BIO_FLAGS_WRITE> flag to indicate that the retry condition is
55*f25b8c9fSEnji Cooperassociated with a write operation.
56*f25b8c9fSEnji Cooper
57*f25b8c9fSEnji CooperBIO_set_retry_special() marks the B<BIO> I<b> as being in a retryable state
58*f25b8c9fSEnji Cooperby setting the B<BIO_FLAGS_SHOULD_RETRY> flag. In addition, it sets the
59*f25b8c9fSEnji CooperB<BIO_FLAGS_IO_SPECIAL> flag to indicate that the retry condition is
60*f25b8c9fSEnji Cooperassociated with a read operation some "special" condition.
61*f25b8c9fSEnji CooperThe precise meaning of this condition depends on the B<BIO> type.
62*f25b8c9fSEnji Cooper
63*f25b8c9fSEnji CooperBIO_clear_retry_flags() clears all retry-related bits from I<b>, i.e.
64*f25b8c9fSEnji CooperB<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>, B<BIO_FLAGS_IO_SPECIAL>, and
65*f25b8c9fSEnji CooperB<BIO_FLAGS_SHOULD_RETRY>.
66*f25b8c9fSEnji Cooper
67*f25b8c9fSEnji CooperBIO_get_retry_flags() returns retry-related bits that are
68*f25b8c9fSEnji Coopercurrently set in I<b>.  The result is a subset of
69*f25b8c9fSEnji CooperB<BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY>.
70*f25b8c9fSEnji Cooper
71*f25b8c9fSEnji CooperThe retry bits are interpreted by the higher level macros
72*f25b8c9fSEnji CooperBIO_should_read(), BIO_should_write(), BIO_should_io_special(),
73*f25b8c9fSEnji CooperBIO_retry_type() and BIO_should_retry(), as documented in
74*f25b8c9fSEnji CooperL<BIO_should_retry(3)>.  Application code will typically use those macros
75*f25b8c9fSEnji Cooperrather than manipulate the underlying flags directly.
76*f25b8c9fSEnji Cooper
77*f25b8c9fSEnji CooperThe following flag bits are currently defined for use with BIO_set_flags(),
78*f25b8c9fSEnji CooperBIO_clear_flags() and BIO_test_flags():
79*f25b8c9fSEnji Cooper
80*f25b8c9fSEnji Cooper=over 4
81*f25b8c9fSEnji Cooper
82*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_READ>
83*f25b8c9fSEnji Cooper
84*f25b8c9fSEnji CooperThe last I/O operation should be retried when the B<BIO> becomes readable.
85*f25b8c9fSEnji CooperThis flag is normally set by the B<BIO> implementation via BIO_set_retry_read()
86*f25b8c9fSEnji Cooperafter a failed read operation.
87*f25b8c9fSEnji Cooper
88*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_WRITE>
89*f25b8c9fSEnji Cooper
90*f25b8c9fSEnji CooperThe last I/O operation should be retried when the B<BIO> becomes writable.
91*f25b8c9fSEnji CooperThis flag is normally set by the B<BIO> implementation via BIO_set_retry_write()
92*f25b8c9fSEnji Cooperafter a failed write operation.
93*f25b8c9fSEnji Cooper
94*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_IO_SPECIAL>
95*f25b8c9fSEnji Cooper
96*f25b8c9fSEnji CooperThe last I/O operation should be retried when some "special" condition
97*f25b8c9fSEnji Cooperbecomes true.  The precise meaning of this condition depends on the B<BIO>
98*f25b8c9fSEnji Coopertype and is usually obtained via BIO_get_retry_BIO() and
99*f25b8c9fSEnji CooperBIO_get_retry_reason() as described in L<BIO_should_retry(3)>.
100*f25b8c9fSEnji CooperThis flag is normally set by the B<BIO> implementation via
101*f25b8c9fSEnji CooperBIO_set_retry_special().
102*f25b8c9fSEnji Cooper
103*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_RWS>
104*f25b8c9fSEnji Cooper
105*f25b8c9fSEnji CooperThe bitwise OR of B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE> and
106*f25b8c9fSEnji CooperB<BIO_FLAGS_IO_SPECIAL>.  This mask is used when clearing or extracting
107*f25b8c9fSEnji Cooperthe retry-direction bits.
108*f25b8c9fSEnji Cooper
109*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_SHOULD_RETRY>
110*f25b8c9fSEnji Cooper
111*f25b8c9fSEnji CooperSet if the last I/O operation on the B<BIO> should be retried at a later time.
112*f25b8c9fSEnji CooperIf this bit is not set then the condition is treated as an error.
113*f25b8c9fSEnji CooperThis flag is normally set by the B<BIO> implementation.
114*f25b8c9fSEnji Cooper
115*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_BASE64_NO_NL>
116*f25b8c9fSEnji Cooper
117*f25b8c9fSEnji CooperWhen set on a base64 filter B<BIO> this flag disables the generation of
118*f25b8c9fSEnji Coopernewline characters in the encoded output and causes newlines to be ignored
119*f25b8c9fSEnji Cooperin the input.  See also L<BIO_f_base64(3)>.
120*f25b8c9fSEnji CooperThe flag has no effect on any other built-in B<BIO> types.
121*f25b8c9fSEnji Cooper
122*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_MEM_RDONLY>
123*f25b8c9fSEnji Cooper
124*f25b8c9fSEnji CooperWhen set on a memory B<BIO> this flag indicates that the underlying buffer is
125*f25b8c9fSEnji Cooperread only.  Attempts to write to such a B<BIO> will fail.
126*f25b8c9fSEnji CooperThe flag has no effect on any other built-in B<BIO> types.
127*f25b8c9fSEnji Cooper
128*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_NONCLEAR_RST>
129*f25b8c9fSEnji Cooper
130*f25b8c9fSEnji CooperOn a memory B<BIO> this flag modifies the behaviour of BIO_reset().  When it
131*f25b8c9fSEnji Cooperis set, resetting the B<BIO> does not clear the underlying buffer but only
132*f25b8c9fSEnji Cooperresets the current read position.
133*f25b8c9fSEnji CooperThe flag has no effect on any other built-in B<BIO> types.
134*f25b8c9fSEnji Cooper
135*f25b8c9fSEnji Cooper=item B<BIO_FLAGS_IN_EOF>
136*f25b8c9fSEnji Cooper
137*f25b8c9fSEnji CooperThis flag may be used by a B<BIO> implementation to indicate that the end
138*f25b8c9fSEnji Cooperof the input stream has been reached.  However, B<BIO> types are not
139*f25b8c9fSEnji Cooperrequired to use this flag to signal end-of-file conditions; they may rely
140*f25b8c9fSEnji Cooperon other mechanisms such as system calls or by querying the next B<BIO> in a
141*f25b8c9fSEnji Cooperchain.  Applications must therefore not test this flag directly to
142*f25b8c9fSEnji Cooperdetermine whether EOF has been reached, and must use BIO_eof() instead.
143*f25b8c9fSEnji Cooper
144*f25b8c9fSEnji Cooper=back
145*f25b8c9fSEnji Cooper
146*f25b8c9fSEnji CooperA range of additional flag values is reserved for internal use by OpenSSL
147*f25b8c9fSEnji Cooperto track kernel TLS (KTLS) state.  This range and the corresponding flag
148*f25b8c9fSEnji Coopermacros are not part of the public API and must not be used by applications.
149*f25b8c9fSEnji Cooper
150*f25b8c9fSEnji Cooper=head1 RETURN VALUES
151*f25b8c9fSEnji Cooper
152*f25b8c9fSEnji CooperBIO_get_flags() returns a bit mask of the flags currently set on the B<BIO>.
153*f25b8c9fSEnji Cooper
154*f25b8c9fSEnji CooperBIO_test_flags() returns a bit mask consisting of those flags from the
155*f25b8c9fSEnji Cooperargument that are currently set in the B<BIO>. Consequently, it returns a
156*f25b8c9fSEnji Coopernonzero value if and only if at least one of the requested flags is set.
157*f25b8c9fSEnji Cooper
158*f25b8c9fSEnji CooperBIO_get_retry_flags() returns a bit mask consisting of those flags from
159*f25b8c9fSEnji CooperB<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>, B<BIO_FLAGS_IO_SPECIAL>, and
160*f25b8c9fSEnji CooperB<BIO_FLAGS_SHOULD_RETRY> that are currently set in the I<BIO>.
161*f25b8c9fSEnji Cooper
162*f25b8c9fSEnji Cooper=head1 NOTES
163*f25b8c9fSEnji Cooper
164*f25b8c9fSEnji CooperOrdinary application code will rarely need to call BIO_set_flags(),
165*f25b8c9fSEnji CooperBIO_clear_flags() or BIO_test_flags() directly.  They are intended for B<BIO>
166*f25b8c9fSEnji Cooperimplementations and for code that forwards retry state from one B<BIO> in a
167*f25b8c9fSEnji Cooperchain to another.
168*f25b8c9fSEnji CooperAfter a failed I/O operation, applications should normally use
169*f25b8c9fSEnji CooperBIO_should_retry() and related macros as described in
170*f25b8c9fSEnji CooperL<BIO_should_retry(3)> instead of inspecting the flags directly.
171*f25b8c9fSEnji Cooper
172*f25b8c9fSEnji CooperThese functions and macros are not thread-safe. If a single B<BIO>
173*f25b8c9fSEnji Cooperis accessed from multiple threads, the caller must provide appropriate
174*f25b8c9fSEnji Cooperexternal synchronisation.
175*f25b8c9fSEnji Cooper
176*f25b8c9fSEnji Cooper=head1 SEE ALSO
177*f25b8c9fSEnji Cooper
178*f25b8c9fSEnji CooperL<BIO_should_retry(3)>, L<BIO_f_base64(3)>, L<bio(7)>
179*f25b8c9fSEnji Cooper
180*f25b8c9fSEnji Cooper=head1 HISTORY
181*f25b8c9fSEnji Cooper
182*f25b8c9fSEnji CooperThe functions and macros described here have been available in OpenSSL since
183*f25b8c9fSEnji Cooperat least 1.1.0 (B<BIO_FLAGS_IN_EOF> since 1.1.1).
184*f25b8c9fSEnji Cooper
185*f25b8c9fSEnji Cooper=head1 COPYRIGHT
186*f25b8c9fSEnji Cooper
187*f25b8c9fSEnji CooperCopyright 2025 The OpenSSL Project Authors. All Rights Reserved.
188*f25b8c9fSEnji Cooper
189*f25b8c9fSEnji CooperLicensed under the Apache License 2.0 (the "License").  You may not use
190*f25b8c9fSEnji Cooperthis file except in compliance with the License.  You can obtain a copy
191*f25b8c9fSEnji Cooperin the file LICENSE in the source distribution or at
192*f25b8c9fSEnji CooperL<https://www.openssl.org/source/license.html>.
193*f25b8c9fSEnji Cooper
194*f25b8c9fSEnji Cooper=cut
195