BIO_F_BUFFER(3ossl)
β¨ BIO_F_BUFFER π (the OpenSSL manual, bestie edition)
okay so. you're in the OpenSSL docs, section 3ossl, and today's main character is the buffering BIO. yes bestie, the one that holds your data in a lil internal cushion so you don't have to think about it. slay. let's get into it π
πΈ NAME πΈ
BIO_get_buffer_num_linesβ tells you how many lines are sitting in the bufferBIO_set_read_buffer_sizeβ sets the read buffer sizeBIO_set_write_buffer_sizeβ sets the write buffer sizeBIO_set_buffer_sizeβ sets both, together, iconicBIO_set_buffer_read_dataβ forces data into the read bufferBIO_f_bufferβ returns the buffering BIO method itself
it's giving "buffering BIO" energy. periodt. π
β¨ SYNOPSIS β¨
#include <openssl/bio.h>
const BIO_METHOD *BIO_f_buffer(void);
long BIO_get_buffer_num_lines(BIO *b);
long BIO_set_read_buffer_size(BIO *b, long size);
long BIO_set_write_buffer_size(BIO *b, long size);
long BIO_set_buffer_size(BIO *b, long size);
long BIO_set_buffer_read_data(BIO *b, void *buf, long num);
π DESCRIPTION π
so BIO_f_buffer() returns the buffering BIO method. that's the whole vibe check.
when you write data to a buffering BIO, it gets buffered and then periodically flushed out to the next BIO in the chain. when you read from it, the bytes come out of an internal buffer which got filled from the next BIO in the chain. and yes, both BIO_gets() and BIO_puts() are supported. we love a versatile queen π
calling BIO_reset() on a buffering BIO clears any buffered data. poof. gone. π
BIO_get_buffer_num_lines()β returns how many lines are currently buffered, i.e. how many are chillin in thereBIO_set_read_buffer_size(),BIO_set_write_buffer_size()andBIO_set_buffer_size()β these set the read, write, or both read and write buffer sizes tosize. the initial buffer size isDEFAULT_BUFFER_SIZE, which is currently4096. any attempt to reduce the buffer size belowDEFAULT_BUFFER_SIZEgets ignored, no cap, it simply will not go lower. also, any buffered data gets cleared when the buffer is resized, so be aware π«ΆBIO_set_buffer_read_data()β clears the read buffer and fills it withnumbytes ofbuf. ifnumis larger than the current buffer size, the buffer gets expanded. growth mindset fr fr π±
π¦ NOTES π¦
these functions, other than BIO_f_buffer(), are implemented as macros. yes really, iykyk.
buffering BIOs implement BIO_read_ex() and BIO_gets() by doing BIO_read_ex() operations on the next BIO in the chain and storing the result in an internal buffer, from which bytes are handed back to the caller as appropriate for the call. a BIO_gets() is guaranteed to give the caller a whole line, and BIO_read_ex() is guaranteed to give the caller the number of bytes it asks for β unless there's an error or end of communication is reached in the next BIO. so by prepending a buffering BIO to a chain, you can provide BIO_gets() or exact-size BIO_read_ex() functionality even if the following BIOs don't support it. main character energy honestly π
π¨ do NOT add more than oneBIO_f_buffer()to a BIO chain. the result of doing so will force a full read of the size of the internal buffer of the topBIO_f_buffer(), which is 4 KiB at a minimum. one is enough bestie, pls π
data is only written to the next BIO in the chain when the write buffer fills or when BIO_flush() is called. so it's super important to call BIO_flush() whenever any pending data should be written β like when you're removing a buffering BIO using BIO_pop(). also BIO_flush() may need to be retried if the ultimate source/sink BIO is non blocking. just keep retrying, you got this π
π RETURN VALUES π
BIO_f_buffer()β returns the buffering BIO methodBIO_get_buffer_num_lines()β returns the number of lines buffered (may be0) or a negative value in case of errorsBIO_set_read_buffer_size(),BIO_set_write_buffer_size()andBIO_set_buffer_size()β return1if the buffer was successfully resized, or<=0for failureBIO_set_buffer_read_data()β returns1if the data was set correctly, or<=0if there was an error
π SEE ALSO π
bio(7), BIO_reset(3), BIO_flush(3), BIO_pop(3), BIO_ctrl(3).
go read those next, bestie, they're all connected π§
π COPYRIGHT π
Copyright 2000-2020 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>.
okay that's the whole page, mwah π this was OpenSSL version 3.5.9, dated 2026-09-29, and it was lowkey iconic of you to read the whole thing. stan a buffering BIO. bye bestie πβ¨π¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms