BIO_F_BUFFER(3ossl)
π NAME π
okay so this is the BIO_F_BUFFER(3ossl) page from the OpenSSL manual, and it's all about the buffering BIO β literally the main character of buffer management π
the whole squad is here:
BIO_get_buffer_num_linesBIO_set_read_buffer_sizeBIO_set_write_buffer_sizeBIO_set_buffer_sizeBIO_set_buffer_read_dataBIO_f_buffer
β all serving buffering BIO realness β¨
πΈ 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 π¦
BIO_f_buffer() returns the buffering BIO method. slay.
data written to a buffering BIO gets buffered and then periodically written to the next BIO in the chain. data read from a buffering BIO comes from an internal buffer, and that buffer gets filled from the next BIO in the chain. both BIO_gets() and BIO_puts() are supported. periodt π
calling BIO_reset() on a buffering BIO clears any buffered data. no lingering little buffer crumbs, bestie.
BIO_get_buffer_num_lines() returns the number of lines currently buffered.
BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size() set the read, write or both read and write buffer sizes to size. the initial buffer size is DEFAULT_BUFFER_SIZE, currently 4096. any attempt to reduce the buffer size below DEFAULT_BUFFER_SIZE is ignored. any buffered data is cleared when the buffer is resized. it's giving "new size, clean slate" energy β¨
BIO_set_buffer_read_data() clears the read buffer and fills it with num bytes of buf. if num is larger than the current buffer size, the buffer is expanded. iconic expansion behavior, honestly π
π«Ά NOTES π«Ά
these functions, other than BIO_f_buffer(), are implemented as macros. iykyk.
buffering BIOs implement BIO_read_ex() and BIO_gets() by using BIO_read_ex() operations on the next BIO in the chain and storing the result in an internal buffer, from which bytes are given 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. by prepending a buffering BIO to a chain it is therefore possible to provide BIO_gets() or exact size BIO_read_ex() functionality if the following BIOs do not support it. that's the whole flex, no cap π₯
π¨ bestie, do not add more than oneBIO_f_buffer()to aBIOchain. the result of doing so will force a full read of the size of the internal buffer of the topBIO_f_buffer(), which is4 KiBat a minimum. we are not doing that today, fr fr π
data is only written to the next BIO in the chain when the write buffer fills or when BIO_flush() is called. it is therefore important to call BIO_flush() whenever any pending data should be written, such as when removing a buffering BIO using BIO_pop(). BIO_flush() may need to be retried if the ultimate source/sink BIO is non blocking. very "remember to flush your faves" of it π«Ά
π RETURN VALUES π
BIO_f_buffer() returns the buffering BIO method. as it should, honestly.
BIO_get_buffer_num_lines() returns the number of lines buffered (may be 0) or a negative value in case of errors.
BIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size() return 1 if the buffer was successfully resized or <=0 for failure.
BIO_set_buffer_read_data() returns 1 if the data was set correctly or <=0 if there was an error.
π SEE ALSO π
bio(7), BIO_reset(3), BIO_flush(3), BIO_pop(3), BIO_ctrl(3).
go read the whole friend group, bestie πβ¨
π 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 bye bestie π this was the OpenSSL 3.5.6 edition, dated 2026-04-07. buffer responsibly and go off πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms