BIO_CTRL(3ossl)
okay bestie, welcome to BIO_CTRL(3ossl) from OpenSSL β this is the manual page for BIO control operations, and it's giving very much "let me explain every little thing so you don't have to guess" energy. π
β¨
π NAME π
The whole squad on this page is: BIO_ctrl, BIO_callback_ctrl, BIO_ptr_ctrl, BIO_int_ctrl, BIO_reset, BIO_seek, BIO_tell, BIO_flush, BIO_eof, BIO_set_close, BIO_get_close, BIO_pending, BIO_wpending, BIO_ctrl_pending, BIO_ctrl_wpending, BIO_get_info_callback, BIO_set_info_callback, BIO_info_cb, BIO_get_ktls_send, BIO_get_ktls_recv, BIO_set_conn_mode, BIO_get_conn_mode, and BIO_set_tfo β all about BIO control operations. π«Ά
β¨ SYNOPSIS β¨
#include <openssl/bio.h>
typedef int BIO_info_cb(BIO *b, int state, int res);
long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb);
void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
int BIO_reset(BIO *b);
int BIO_seek(BIO *b, int ofs);
int BIO_tell(BIO *b);
int BIO_flush(BIO *b);
int BIO_eof(BIO *b);
int BIO_set_close(BIO *b, long flag);
int BIO_get_close(BIO *b);
int BIO_pending(BIO *b);
int BIO_wpending(BIO *b);
size_t BIO_ctrl_pending(BIO *b);
size_t BIO_ctrl_wpending(BIO *b);
int BIO_get_info_callback(BIO *b, BIO_info_cb **cbp);
int BIO_set_info_callback(BIO *b, BIO_info_cb *cb);
int BIO_get_ktls_send(BIO *b);
int BIO_get_ktls_recv(BIO *b);
int BIO_set_conn_mode(BIO *b, int mode);
int BIO_get_conn_mode(BIO *b);
int BIO_set_tfo(BIO *b, int onoff);
π¦ DESCRIPTION π¦
BIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl() and BIO_int_ctrl() are BIO "control" operations taking arguments of various types. These functions are not normally called directly β various macros are used instead. The standard macros are described below, and macros specific to a particular type of BIO are described in the specific BIOs manual page, along with any special features of the standard calls. π
BIO_reset()β typically resets aBIOto some initial state. For file relatedBIOs, for example, it rewinds the file pointer to the start of the file.BIO_seek()β resets a file relatedBIO's (that is, file descriptor andFILEBIOs) file position pointer toofsbytes from start of file.BIO_tell()β returns the current file position of a file relatedBIO.BIO_flush()β normally writes out any internally buffered data; in some cases it is used to signal EOF and that no more data will be written.BIO_eof()β returns 1 if theBIOhas read EOF. The precise meaning of "EOF" varies according to theBIOtype.BIO_set_close()β sets theBIObclose flag toflag.flagcan take the valueBIO_CLOSEorBIO_NOCLOSE. TypicallyBIO_CLOSEis used in a source/sinkBIOto indicate that the underlying I/O stream should be closed when theBIOis freed.BIO_get_close()β returns theBIO's close flag.BIO_pending(),BIO_ctrl_pending(),BIO_wpending()andBIO_ctrl_wpending()β return the number of pending characters in theBIOs' read and write buffers. Not allBIOs support these calls.BIO_ctrl_pending()andBIO_ctrl_wpending()return asize_ttype and are functions;BIO_pending()andBIO_wpending()are macros which callBIO_ctrl().BIO_get_ktls_send()β returns 1 if theBIOis using the Kernel TLS data-path for sending. Otherwise, it returns zero.BIO_get_ktls_recv()returns 1 if theBIOis using the Kernel TLS data-path for receiving. Otherwise, it returns zero.BIO_get_conn_mode()β returns theBIOconnection mode.BIO_set_conn_mode()sets theBIOconnection mode.BIO_set_tfo()β disables TCP Fast Open whenonoffis 0, and enables TCP Fast Open whenonoffis nonzero. Setting the value to 1 is equivalent to settingBIO_SOCK_TFOinBIO_set_conn_mode().
π RETURN VALUES π
BIO_reset()β normally returns 1 for success and<=0for failure. FileBIOs are an exception: they return 0 for success and -1 for failure.BIO_seek()andBIO_tell()β both return the current file position on success and -1 for failure, except fileBIOs which forBIO_seek()always return 0 for success and -1 for failure.BIO_flush()β returns 1 for success and<=0for failure.BIO_eof()β returns 1 if EOF has been reached, 0 if not, or negative values for failure.BIO_set_close()β returns 1 on success or<=0for failure.BIO_get_close()β returns the close flag value:BIO_CLOSEorBIO_NOCLOSE. It also returns other negative values if an error occurs.BIO_pending(),BIO_ctrl_pending(),BIO_wpending()andBIO_ctrl_wpending()β return the amount of pending data.BIO_pending()andBIO_wpending()return negative value or 0 on error.BIO_ctrl_pending()andBIO_ctrl_wpending()return 0 on error.BIO_get_ktls_send()β returns 1 if theBIOis using the Kernel TLS data-path for sending. Otherwise, it returns zero.BIO_get_ktls_recv()returns 1 if theBIOis using the Kernel TLS data-path for receiving. Otherwise, it returns zero.BIO_set_conn_mode()β returns 1 for success and 0 for failure.BIO_get_conn_mode()returns the current connection mode, which may contain the bitwise-or of the following flags:BIO_SOCK_REUSEADDRBIO_SOCK_V6_ONLYBIO_SOCK_KEEPALIVEBIO_SOCK_NONBLOCKBIO_SOCK_NODELAYBIO_SOCK_TFO
BIO_set_tfo()β returns 1 for success, and 0 for failure.
πΈ NOTES πΈ
BIO_flush(), because it can write data, may return 0 or -1 indicating that the call should be retried later in a similar manner to BIO_write_ex(). The BIO_should_retry() call should be used, and appropriate action taken if the call fails.
bestie, do not ignore those retry vibes. π
The return values of BIO_pending() and BIO_wpending() may not reliably determine the amount of pending data in all cases. For example, in the case of a file BIO, some data may be available in the FILE structure's internal buffers but it is not possible to determine this in a portable way. For other types of BIO, they may not be supported.
Filter BIOs, if they do not internally handle a particular BIO_ctrl() operation, usually pass the operation to the next BIO in the chain. This often means there is no need to locate the required BIO for a particular operation; it can be called on a chain and it will be automatically passed to the relevant BIO. However, this can cause unexpected results: for example, no current filter BIOs implement BIO_seek(), but this may still succeed if the chain ends in a FILE or file descriptor BIO.
Source/sink BIOs return an 0 if they do not recognize the BIO_ctrl() operation.
π BUGS π
Some of the return values are ambiguous and care should be taken. In particular, a return value of 0 can be returned if an operation is not supported, if an error occurred, if EOF has not been reached, and in the case of BIO_seek() on a file BIO for a successful operation.
lowkey a 0 is doing too many jobs here. π
In older versions of OpenSSL, the BIO_ctrl_pending() and BIO_ctrl_wpending() could return values greater than INT_MAX on error.
π HISTORY π
The BIO_get_ktls_send() and BIO_get_ktls_recv() macros were added in OpenSSL 3.0. They were modified to never return -1 in OpenSSL 3.0.4.
The BIO_get_conn_mode(), BIO_set_conn_mode() and BIO_set_tfo() functions were added in OpenSSL 3.2.
π COPYRIGHT π
Copyright 2000-2022 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, bestie β footer tea time: this is from OpenSSL version 3.5.0, dated 2026-09-25, and the manual page is BIO_CTRL(3ossl). slay. π
ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms