---
name: "libressl-BIO_f_buffer"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BIO_f_buffer"
---

# libressl-BIO\_f\_buffer(3)

buffering BIO

## NAME

**BIO\_f\_buffer**, **BIO\_get\_buffer\_num\_lines**, **BIO\_set\_read\_buffer\_size**, **BIO\_set\_write\_buffer\_size**, **BIO\_set\_buffer\_size**, **BIO\_set\_buffer\_read\_data** – buffering BIO

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#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.

Data written to a buffering BIO is buffered and periodically written to the next BIO in the chain. Data read from a buffering BIO comes from an internal buffer which is filled from the next BIO in the chain. Both BIO\_gets(3) and BIO\_puts(3) are supported.

Calling BIO\_reset(3) on a buffering BIO clears any buffered data.

**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.

**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.

Buffering BIOs implement BIO\_gets(3) by using BIO\_read(3) operations on the next BIO in the chain. By prepending a buffering BIO to a chain it is therefore possible to provide the functionality of BIO\_gets(3) if the following BIOs do not support it (for example SSL BIOs).

Data is only written to the next BIO in the chain when the write buffer fills or when BIO\_flush(3) is called. It is therefore important to call BIO\_flush(3) whenever any pending data should be written such as when removing a buffering BIO using BIO\_pop(3). BIO\_flush(3) may need to be retried if the ultimate source/sink BIO is non-blocking.

When a chain containing a buffering BIO is copied with BIO\_dup\_chain(3), **BIO\_set\_read\_buffer\_size**() and **BIO\_set\_write\_buffer\_size**() are called internally to automatically copy both buffer sizes from the original BIO object to the new one.

BIO\_ctrl(3) *cmd* arguments correspond to macros as follows:

| | |
| --- | --- |
| *cmd* constant | corresponding macro |
| BIO\_C\_GET\_BUFF\_NUM\_LINES | **BIO\_get\_buffer\_num\_lines**() |
| BIO\_C\_SET\_BUFF\_READ\_DATA | **BIO\_set\_buffer\_read\_data**() |
| BIO\_C\_SET\_BUFF\_SIZE | **BIO\_set\_buffer\_size**() |
| BIO\_CTRL\_FLUSH | BIO\_flush(3) |
| BIO\_CTRL\_PENDING | BIO\_pending(3) |
| BIO\_CTRL\_RESET | BIO\_reset(3) |
| BIO\_CTRL\_WPENDING | BIO\_wpending(3) |

The *cmd* constant BIO\_C\_SET\_BUFF\_SIZE is special. It is also used for BIO\_int\_ctrl(3) with the following *iarg* arguments:

| | | |
| --- | --- | --- |
| *cmd* constant | *iarg* | corresponding macro |
| BIO\_C\_SET\_BUFF\_SIZE | 0 | **BIO\_set\_read\_buffer\_size**() |
|  | 1 | **BIO\_set\_write\_buffer\_size**() |

## RETURN VALUES

**BIO\_f\_buffer**() returns the buffering BIO method.

When called on a buffering BIO object, BIO\_method\_type(3) returns the constant BIO\_TYPE\_BUFFER and BIO\_method\_name(3) returns a pointer to the static string "buffer".

**BIO\_get\_buffer\_num\_lines**() returns the number of lines buffered (may be 0).

**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\_ctrl(3), BIO\_flush(3), BIO\_new(3), BIO\_pop(3), BIO\_reset(3)

## HISTORY

**BIO\_f\_buffer**() first appeared in SSLeay 0.6.0. **BIO\_get\_buffer\_num\_lines**() and **BIO\_set\_buffer\_size**() first appeared in SSLeay 0.6.5. **BIO\_set\_read\_buffer\_size**() and **BIO\_set\_write\_buffer\_size**() first appeared in SSLeay 0.8.0. **BIO\_set\_buffer\_read\_data**() first appeared in SSLeay 0.9.0. All these functions have been available since OpenBSD 2.4.
