xref: /openbsd/lib/libcrypto/man/BIO_f_buffer.3 (revision 09467b48)
1.\"	$OpenBSD: BIO_f_buffer.3,v 1.10 2018/05/01 17:05:05 schwarze Exp $
2.\"	OpenSSL 9b86974e Mar 19 12:32:14 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: May 1 2018 $
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.Nd buffering BIO
63.Sh SYNOPSIS
64.In openssl/bio.h
65.Ft const BIO_METHOD *
66.Fo BIO_f_buffer
67.Fa void
68.Fc
69.Ft long
70.Fo BIO_get_buffer_num_lines
71.Fa "BIO *b"
72.Fc
73.Ft long
74.Fo BIO_set_read_buffer_size
75.Fa "BIO *b"
76.Fa "long size"
77.Fc
78.Ft long
79.Fo BIO_set_write_buffer_size
80.Fa "BIO *b"
81.Fa "long size"
82.Fc
83.Ft long
84.Fo BIO_set_buffer_size
85.Fa "BIO *b"
86.Fa "long size"
87.Fc
88.Fo BIO_set_buffer_read_data
89.Fa "BIO *b"
90.Fa "void *buf"
91.Fa "long num"
92.Fc
93.Sh DESCRIPTION
94.Fn BIO_f_buffer
95returns the buffering BIO method.
96.Pp
97Data written to a buffering BIO is buffered and periodically written
98to the next BIO in the chain.
99Data read from a buffering BIO comes from an internal buffer
100which is filled from the next BIO in the chain.
101Both
102.Xr BIO_gets 3
103and
104.Xr BIO_puts 3
105are supported.
106.Pp
107Calling
108.Xr BIO_reset 3
109on a buffering BIO clears any buffered data.
110.Pp
111.Fn BIO_get_buffer_num_lines
112returns the number of lines currently buffered.
113.Pp
114.Fn BIO_set_read_buffer_size ,
115.Fn BIO_set_write_buffer_size ,
116and
117.Fn BIO_set_buffer_size
118set the read, write or both read and write buffer sizes to
119.Fa size .
120The initial buffer size is
121.Dv DEFAULT_BUFFER_SIZE ,
122currently 4096.
123Any attempt to reduce the buffer size below
124.Dv DEFAULT_BUFFER_SIZE
125is ignored.
126Any buffered data is cleared when the buffer is resized.
127.Pp
128.Fn BIO_set_buffer_read_data
129clears the read buffer and fills it with
130.Fa num
131bytes of
132.Fa buf .
133If
134.Fa num
135is larger than the current buffer size the buffer is expanded.
136.Pp
137Except
138.Fn BIO_f_buffer ,
139these functions are implemented as macros.
140.Pp
141Buffering BIOs implement
142.Xr BIO_gets 3
143by using
144.Xr BIO_read 3
145operations on the next BIO in the chain.
146By prepending a buffering BIO to a chain
147it is therefore possible to provide the functionality of
148.Xr BIO_gets 3
149if the following BIOs do not support it (for example SSL BIOs).
150.Pp
151Data is only written to the next BIO in the chain
152when the write buffer fills or when
153.Xr BIO_flush 3
154is called.
155It is therefore important to call
156.Xr BIO_flush 3
157whenever any pending data should be written
158such as when removing a buffering BIO using
159.Xr BIO_pop 3 .
160.Xr BIO_flush 3
161may need to be retried if the ultimate source/sink BIO is non-blocking.
162.Sh RETURN VALUES
163.Fn BIO_f_buffer
164returns the buffering BIO method.
165.Pp
166.Fn BIO_get_buffer_num_lines
167returns the number of lines buffered (may be 0).
168.Pp
169.Fn BIO_set_read_buffer_size ,
170.Fn BIO_set_write_buffer_size ,
171and
172.Fn BIO_set_buffer_size
173return 1 if the buffer was successfully resized or 0 for failure.
174.Pp
175.Fn BIO_set_buffer_read_data
176returns 1 if the data was set correctly or 0 if there was an error.
177.Sh SEE ALSO
178.Xr BIO_ctrl 3 ,
179.Xr BIO_flush 3 ,
180.Xr BIO_new 3 ,
181.Xr BIO_pop 3 ,
182.Xr BIO_reset 3
183.Sh HISTORY
184.Fn BIO_f_buffer
185first appeared in SSLeay 0.6.0.
186.Fn BIO_get_buffer_num_lines
187and
188.Fn BIO_set_buffer_size
189first appeared in SSLeay 0.6.5.
190.Fn BIO_set_read_buffer_size
191and
192.Fn BIO_set_write_buffer_size
193first appeared in SSLeay 0.8.0.
194.Fn BIO_set_buffer_read_data
195first appeared in SSLeay 0.9.0.
196All these functions have been available since
197.Ox 2.4 .
198