xref: /openbsd-src/lib/libcrypto/man/BIO_f_buffer.3 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\"	$OpenBSD: BIO_f_buffer.3,v 1.3 2015/11/11 22:14:39 jmc Exp $
2.\"
3.Dd $Mdocdate: November 11 2015 $
4.Dt BIO_F_BUFFER 3
5.Os
6.Sh NAME
7.Nm BIO_f_buffer ,
8.Nm BIO_get_buffer_num_lines ,
9.Nm BIO_set_read_buffer_size ,
10.Nm BIO_set_write_buffer_size ,
11.Nm BIO_set_buffer_size ,
12.Nm BIO_set_buffer_read_data
13.Nd buffering BIO
14.Sh SYNOPSIS
15.In openssl/bio.h
16.Ft BIO_METHOD *
17.Fo BIO_f_buffer
18.Fa void
19.Fc
20.Bd -literal
21#define	BIO_get_buffer_num_lines(b) \e
22	BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
23#define	BIO_set_read_buffer_size(b,size) \e
24	BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
25#define	BIO_set_write_buffer_size(b,size) \e
26	BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
27#define	BIO_set_buffer_size(b,size) \e
28	BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
29#define	BIO_set_buffer_read_data(b,buf,num) \e
30	BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
31.Ed
32.Sh DESCRIPTION
33.Fn BIO_f_buffer
34returns the buffering BIO method.
35.Pp
36Data written to a buffering BIO is buffered and periodically written
37to the next BIO in the chain.
38Data read from a buffering BIO comes from an internal buffer
39which is filled from the next BIO in the chain.
40Both
41.Xr BIO_gets 3
42and
43.Xr BIO_puts 3
44are supported.
45.Pp
46Calling
47.Xr BIO_reset 3
48on a buffering BIO clears any buffered data.
49.Pp
50.Fn BIO_get_buffer_num_lines
51returns the number of lines currently buffered.
52.Pp
53.Fn BIO_set_read_buffer_size ,
54.Fn BIO_set_write_buffer_size ,
55and
56.Fn BIO_set_buffer_size
57set the read, write or both read and write buffer sizes to
58.Fa size .
59The initial buffer size is
60.Dv DEFAULT_BUFFER_SIZE ,
61currently 4096.
62Any attempt to reduce the buffer size below
63.Dv DEFAULT_BUFFER_SIZE
64is ignored.
65Any buffered data is cleared when the buffer is resized.
66.Pp
67.Fn BIO_set_buffer_read_data
68clears the read buffer and fills it with
69.Fa num
70bytes of
71.Fa buf .
72If
73.Fa num
74is larger than the current buffer size the buffer is expanded.
75.Sh NOTES
76Buffering BIOs implement
77.Xr BIO_gets 3
78by using
79.Xr BIO_read 3
80operations on the next BIO in the chain.
81By prepending a buffering BIO to a chain
82it is therefore possible to provide
83.Xr BIO_gets 3
84functionality if the following BIOs do not support it (for example SSL BIOs).
85.Pp
86Data is only written to the next BIO in the chain
87when the write buffer fills or when
88.Xr BIO_flush 3
89is called.
90It is therefore important to call
91.Xr BIO_flush 3
92whenever any pending data should be written
93such as when removing a buffering BIO using
94.Xr BIO_pop 3 .
95.Xr BIO_flush 3
96may need to be retried if the ultimate source/sink BIO is non blocking.
97.Sh RETURN VALUES
98.Fn BIO_f_buffer
99returns the buffering BIO method.
100.Pp
101.Fn BIO_get_buffer_num_lines
102returns the number of lines buffered (may be 0).
103.Pp
104.Fn BIO_set_read_buffer_size ,
105.Fn BIO_set_write_buffer_size ,
106and
107.Fn BIO_set_buffer_size
108return 1 if the buffer was successfully resized or 0 for failure.
109.Pp
110.Fn BIO_set_buffer_read_data
111returns 1 if the data was set correctly or 0 if there was an error.
112.Sh SEE ALSO
113.Xr BIO 3 ,
114.Xr BIO_ctrl 3 ,
115.Xr BIO_flush 3 ,
116.Xr BIO_pop 3 ,
117.Xr BIO_reset 3
118