1.\" $OpenBSD: BIO_f_buffer.3,v 1.13 2022/12/23 17:27:53 schwarze Exp $ 2.\" full merge up to OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2000, 2010, 2015, 2016 The OpenSSL Project. 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in 17.\" the documentation and/or other materials provided with the 18.\" distribution. 19.\" 20.\" 3. All advertising materials mentioning features or use of this 21.\" software must display the following acknowledgment: 22.\" "This product includes software developed by the OpenSSL Project 23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24.\" 25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26.\" endorse or promote products derived from this software without 27.\" prior written permission. For written permission, please contact 28.\" openssl-core@openssl.org. 29.\" 30.\" 5. Products derived from this software may not be called "OpenSSL" 31.\" nor may "OpenSSL" appear in their names without prior written 32.\" permission of the OpenSSL Project. 33.\" 34.\" 6. Redistributions of any form whatsoever must retain the following 35.\" acknowledgment: 36.\" "This product includes software developed by the OpenSSL Project 37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38.\" 39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51.\" 52.Dd $Mdocdate: December 23 2022 $ 53.Dt BIO_F_BUFFER 3 54.Os 55.Sh NAME 56.Nm BIO_f_buffer , 57.Nm BIO_get_buffer_num_lines , 58.Nm BIO_set_read_buffer_size , 59.Nm BIO_set_write_buffer_size , 60.Nm BIO_set_buffer_size , 61.Nm BIO_set_buffer_read_data 62.\" .Nm BIO_buffer_get_num_lines is intentionally undocumented. 63.\" Contrary to what bio.h says, it does not *not* get some "IO type", 64.\" whatever that is supposed to be, but is a NOOP, and nothing uses it. 65.Nd buffering BIO 66.Sh SYNOPSIS 67.In openssl/bio.h 68.Ft const BIO_METHOD * 69.Fo BIO_f_buffer 70.Fa void 71.Fc 72.Ft long 73.Fo BIO_get_buffer_num_lines 74.Fa "BIO *b" 75.Fc 76.Ft long 77.Fo BIO_set_read_buffer_size 78.Fa "BIO *b" 79.Fa "long size" 80.Fc 81.Ft long 82.Fo BIO_set_write_buffer_size 83.Fa "BIO *b" 84.Fa "long size" 85.Fc 86.Ft long 87.Fo BIO_set_buffer_size 88.Fa "BIO *b" 89.Fa "long size" 90.Fc 91.Fo BIO_set_buffer_read_data 92.Fa "BIO *b" 93.Fa "void *buf" 94.Fa "long num" 95.Fc 96.Sh DESCRIPTION 97.Fn BIO_f_buffer 98returns the buffering BIO method. 99.Pp 100Data written to a buffering BIO is buffered and periodically written 101to the next BIO in the chain. 102Data read from a buffering BIO comes from an internal buffer 103which is filled from the next BIO in the chain. 104Both 105.Xr BIO_gets 3 106and 107.Xr BIO_puts 3 108are supported. 109.Pp 110Calling 111.Xr BIO_reset 3 112on a buffering BIO clears any buffered data. 113.Pp 114.Fn BIO_get_buffer_num_lines 115returns the number of lines currently buffered. 116.Pp 117.Fn BIO_set_read_buffer_size , 118.Fn BIO_set_write_buffer_size , 119and 120.Fn BIO_set_buffer_size 121set the read, write or both read and write buffer sizes to 122.Fa size . 123The initial buffer size is 124.Dv DEFAULT_BUFFER_SIZE , 125currently 4096. 126Any attempt to reduce the buffer size below 127.Dv DEFAULT_BUFFER_SIZE 128is ignored. 129Any buffered data is cleared when the buffer is resized. 130.Pp 131.Fn BIO_set_buffer_read_data 132clears the read buffer and fills it with 133.Fa num 134bytes of 135.Fa buf . 136If 137.Fa num 138is larger than the current buffer size, the buffer is expanded. 139.Pp 140Except 141.Fn BIO_f_buffer , 142these functions are implemented as macros. 143.Pp 144Buffering BIOs implement 145.Xr BIO_gets 3 146by using 147.Xr BIO_read 3 148operations on the next BIO in the chain. 149By prepending a buffering BIO to a chain 150it is therefore possible to provide the functionality of 151.Xr BIO_gets 3 152if the following BIOs do not support it (for example SSL BIOs). 153.Pp 154Data is only written to the next BIO in the chain 155when the write buffer fills or when 156.Xr BIO_flush 3 157is called. 158It is therefore important to call 159.Xr BIO_flush 3 160whenever any pending data should be written 161such as when removing a buffering BIO using 162.Xr BIO_pop 3 . 163.Xr BIO_flush 3 164may need to be retried if the ultimate source/sink BIO is non-blocking. 165.Pp 166When a chain containing a buffering BIO is copied with 167.Xr BIO_dup_chain 3 , 168.Fn BIO_set_read_buffer_size 169and 170.Fn BIO_set_write_buffer_size 171are called internally to automatically copy both buffer sizes from the 172original BIO object to the new one. 173.Sh RETURN VALUES 174.Fn BIO_f_buffer 175returns the buffering BIO method. 176.Pp 177.Fn BIO_get_buffer_num_lines 178returns the number of lines buffered (may be 0). 179.Pp 180.Fn BIO_set_read_buffer_size , 181.Fn BIO_set_write_buffer_size , 182and 183.Fn BIO_set_buffer_size 184return 1 if the buffer was successfully resized or 0 for failure. 185.Pp 186.Fn BIO_set_buffer_read_data 187returns 1 if the data was set correctly or 0 if there was an error. 188.Sh SEE ALSO 189.Xr BIO_ctrl 3 , 190.Xr BIO_flush 3 , 191.Xr BIO_new 3 , 192.Xr BIO_pop 3 , 193.Xr BIO_reset 3 194.Sh HISTORY 195.Fn BIO_f_buffer 196first appeared in SSLeay 0.6.0. 197.Fn BIO_get_buffer_num_lines 198and 199.Fn BIO_set_buffer_size 200first appeared in SSLeay 0.6.5. 201.Fn BIO_set_read_buffer_size 202and 203.Fn BIO_set_write_buffer_size 204first appeared in SSLeay 0.8.0. 205.Fn BIO_set_buffer_read_data 206first appeared in SSLeay 0.9.0. 207All these functions have been available since 208.Ox 2.4 . 209