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 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 3ossl"
way too many mistakes in technical documents.
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.
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.
[\s-1XXXXX:\s0 More return values need to be added here]
.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.
Licensed under the Apache License 2.0 (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>.