xref: /freebsd/secure/lib/libcrypto/man/man3/BIO_s_bio.3 (revision 1f1e2261e341e6ca6862f82261066ef1705f0a7a)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "BIO_S_BIO 3"
BIO_S_BIO 3 "2022-06-21" "1.1.1p" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr, BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair, BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request, BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request - BIO pair BIO
"SYNOPSIS"
Header "SYNOPSIS" .Vb 1 #include <openssl/bio.h> \& const BIO_METHOD *BIO_s_bio(void); \& int BIO_make_bio_pair(BIO *b1, BIO *b2); int BIO_destroy_bio_pair(BIO *b); int BIO_shutdown_wr(BIO *b); \& int BIO_set_write_buf_size(BIO *b, long size); size_t BIO_get_write_buf_size(BIO *b, long size); \& int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2); \& int BIO_get_write_guarantee(BIO *b); size_t BIO_ctrl_get_write_guarantee(BIO *b); int BIO_get_read_request(BIO *b); size_t BIO_ctrl_get_read_request(BIO *b); int BIO_ctrl_reset_read_request(BIO *b); .Ve
"DESCRIPTION"
Header "DESCRIPTION" \fBBIO_s_bio() returns the method for a \s-1BIO\s0 pair. A \s-1BIO\s0 pair is a pair of source/sink BIOs where data written to either half of the pair is buffered and can be read from the other half. Both halves must usually by handled by the same application thread since no locking is done on the internal data structures.

Since \s-1BIO\s0 chains typically end in a source/sink \s-1BIO\s0 it is possible to make this one half of a \s-1BIO\s0 pair and have all the data processed by the chain under application control.

One typical use of \s-1BIO\s0 pairs is to place \s-1TLS/SSL I/O\s0 under application control, this can be used when the application wishes to use a non standard transport for \s-1TLS/SSL\s0 or the normal socket routines are inappropriate.

Calls to BIO_read_ex() will read data from the buffer or request a retry if no data is available.

Calls to BIO_write_ex() will place data in the buffer or request a retry if the buffer is full.

The standard calls BIO_ctrl_pending() and BIO_ctrl_wpending() can be used to determine the amount of pending data in the read or write buffer.

\fBBIO_reset() clears any data in the write buffer.

\fBBIO_make_bio_pair() joins two separate BIOs into a connected pair.

\fBBIO_destroy_pair() destroys the association between two connected BIOs. Freeing up any half of the pair will automatically destroy the association.

\fBBIO_shutdown_wr() is used to close down a \s-1BIO\s0 b. After this call no further writes on \s-1BIO\s0 b are allowed (they will return an error). Reads on the other half of the pair will return any pending data or \s-1EOF\s0 when all pending data has been read.

\fBBIO_set_write_buf_size() sets the write buffer size of \s-1BIO\s0 b to size. If the size is not initialized a default value is used. This is currently 17K, sufficient for a maximum size \s-1TLS\s0 record.

\fBBIO_get_write_buf_size() returns the size of the write buffer.

\fBBIO_new_bio_pair() combines the calls to BIO_new(), BIO_make_bio_pair() and \fBBIO_set_write_buf_size() to create a connected pair of BIOs bio1, bio2 with write buffer sizes writebuf1 and writebuf2. If either size is zero then the default size is used. BIO_new_bio_pair() does not check whether \fBbio1 or bio2 do point to some other \s-1BIO,\s0 the values are overwritten, \fBBIO_free() is not called.

\fBBIO_get_write_guarantee() and BIO_ctrl_get_write_guarantee() return the maximum length of data that can be currently written to the \s-1BIO.\s0 Writes larger than this value will return a value from BIO_write_ex() less than the amount requested or if the buffer is full request a retry. BIO_ctrl_get_write_guarantee() is a function whereas BIO_get_write_guarantee() is a macro.

\fBBIO_get_read_request() and BIO_ctrl_get_read_request() return the amount of data requested, or the buffer size if it is less, if the last read attempt at the other half of the \s-1BIO\s0 pair failed due to an empty buffer. This can be used to determine how much data should be written to the \s-1BIO\s0 so the next read will succeed: this is most useful in \s-1TLS/SSL\s0 applications where the amount of data read is usually meaningful rather than just a buffer size. After a successful read this call will return zero. It also will return zero once new data has been written satisfying the read request or part of it. Note that BIO_get_read_request() never returns an amount larger than that returned by BIO_get_write_guarantee().

\fBBIO_ctrl_reset_read_request() can also be used to reset the value returned by \fBBIO_get_read_request() to zero.

"NOTES"
Header "NOTES" Both halves of a \s-1BIO\s0 pair should be freed. That is even if one half is implicit freed due to a BIO_free_all() or SSL_free() call the other half needs to be freed.

When used in bidirectional applications (such as \s-1TLS/SSL\s0) care should be taken to flush any data in the write buffer. This can be done by calling BIO_pending() on the other half of the pair and, if any data is pending, reading it and sending it to the underlying transport. This must be done before any normal processing (such as calling select() ) due to a request and BIO_should_read() being true.

To see why this is important consider a case where a request is sent using \fBBIO_write_ex() and a response read with BIO_read_ex(), this can occur during an \s-1TLS/SSL\s0 handshake for example. BIO_write_ex() will succeed and place data in the write buffer. BIO_read_ex() will initially fail and BIO_should_read() will be true. If the application then waits for data to be available on the underlying transport before flushing the write buffer it will never succeed because the request was never sent!

\fBBIO_eof() is true if no data is in the peer \s-1BIO\s0 and the peer \s-1BIO\s0 has been shutdown.

\fBBIO_make_bio_pair(), BIO_destroy_bio_pair(), BIO_shutdown_wr(), \fBBIO_set_write_buf_size(), BIO_get_write_buf_size(), \fBBIO_get_write_guarantee(), and BIO_get_read_request() are implemented as macros.

"RETURN VALUES"
Header "RETURN VALUES" \fBBIO_new_bio_pair() returns 1 on success, with the new BIOs available in \fBbio1 and bio2, or 0 on failure, with \s-1NULL\s0 pointers stored into the locations for bio1 and bio2. Check the error stack for more information.

[\s-1XXXXX:\s0 More return values need to be added here]

"EXAMPLES"
Header "EXAMPLES" The \s-1BIO\s0 pair can be used to have full control over the network access of an application. The application can call select() on the socket as required without having to go through the SSL-interface.

.Vb 1 BIO *internal_bio, *network_bio; \& ... BIO_new_bio_pair(&internal_bio, 0, &network_bio, 0); SSL_set_bio(ssl, internal_bio, internal_bio); SSL_operations(); /* e.g. SSL_read and SSL_write */ ... \& application | TLS-engine | | +----------> SSL_operations() | /\e || | || \e/ | BIO-pair (internal_bio) | BIO-pair (network_bio) | || /\e | \e/ || +-----------< BIO_operations() | | | | socket \& ... SSL_free(ssl); /* implicitly frees internal_bio */ BIO_free(network_bio); ... .Ve

As the \s-1BIO\s0 pair will only buffer the data and never directly access the connection, it behaves nonblocking and will return as soon as the write buffer is full or the read buffer is drained. Then the application has to flush the write buffer and/or fill the read buffer.

Use the BIO_ctrl_pending(), to find out whether data is buffered in the \s-1BIO\s0 and must be transferred to the network. Use BIO_ctrl_get_read_request() to find out, how many bytes must be written into the buffer before the \fBSSL_operation() can successfully be continued.

"WARNINGS"
Header "WARNINGS" As the data is buffered, SSL_operation() may return with an \s-1ERROR_SSL_WANT_READ\s0 condition, but there is still data in the write buffer. An application must not rely on the error value of SSL_operation() but must assure that the write buffer is always flushed first. Otherwise a deadlock may occur as the peer might be waiting for the data before being able to continue.
"SEE ALSO"
Header "SEE ALSO" \fBSSL_set_bio\|(3), ssl\|(7), bio\|(7), \fBBIO_should_retry\|(3), BIO_read_ex\|(3)
"COPYRIGHT"
Header "COPYRIGHT" Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.