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