Merge from vendor branch NTPD:
[dragonfly.git] / secure / lib / libcrypto / man / BIO_s_bio.3
1 .rn '' }`
2 ''' $RCSfile$$Revision$$Date$
3 '''
4 ''' $Log$
5 '''
6 .de Sh
7 .br
8 .if t .Sp
9 .ne 5
10 .PP
11 \fB\\$1\fR
12 .PP
13 ..
14 .de Sp
15 .if t .sp .5v
16 .if n .sp
17 ..
18 .de Ip
19 .br
20 .ie \\n(.$>=3 .ne \\$3
21 .el .ne 3
22 .IP "\\$1" \\$2
23 ..
24 .de Vb
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve
30 .ft R
31
32 .fi
33 ..
34 '''
35 '''
36 '''     Set up \*(-- to give an unbreakable dash;
37 '''     string Tr holds user defined translation string.
38 '''     Bell System Logo is used as a dummy character.
39 '''
40 .tr \(*W-|\(bv\*(Tr
41 .ie n \{\
42 .ds -- \(*W-
43 .ds PI pi
44 .if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
45 .if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
46 .ds L" ""
47 .ds R" ""
48 '''   \*(M", \*(S", \*(N" and \*(T" are the equivalent of
49 '''   \*(L" and \*(R", except that they are used on ".xx" lines,
50 '''   such as .IP and .SH, which do another additional levels of
51 '''   double-quote interpretation
52 .ds M" """
53 .ds S" """
54 .ds N" """""
55 .ds T" """""
56 .ds L' '
57 .ds R' '
58 .ds M' '
59 .ds S' '
60 .ds N' '
61 .ds T' '
62 'br\}
63 .el\{\
64 .ds -- \(em\|
65 .tr \*(Tr
66 .ds L" ``
67 .ds R" ''
68 .ds M" ``
69 .ds S" ''
70 .ds N" ``
71 .ds T" ''
72 .ds L' `
73 .ds R' '
74 .ds M' `
75 .ds S' '
76 .ds N' `
77 .ds T' '
78 .ds PI \(*p
79 'br\}
80 .\"     If the F register is turned on, we'll generate
81 .\"     index entries out stderr for the following things:
82 .\"             TH      Title 
83 .\"             SH      Header
84 .\"             Sh      Subsection 
85 .\"             Ip      Item
86 .\"             X<>     Xref  (embedded
87 .\"     Of course, you have to process the output yourself
88 .\"     in some meaninful fashion.
89 .if \nF \{
90 .de IX
91 .tm Index:\\$1\t\\n%\t"\\$2"
92 ..
93 .nr % 0
94 .rr F
95 .\}
96 .TH BIO_s_bio 3 "0.9.7d" "2/Sep/2004" "OpenSSL"
97 .UC
98 .if n .hy 0
99 .if n .na
100 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
101 .de CQ          \" put $1 in typewriter font
102 .ft CW
103 'if n "\c
104 'if t \\&\\$1\c
105 'if n \\&\\$1\c
106 'if n \&"
107 \\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
108 '.ft R
109 ..
110 .\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
111 .       \" AM - accent mark definitions
112 .bd B 3
113 .       \" fudge factors for nroff and troff
114 .if n \{\
115 .       ds #H 0
116 .       ds #V .8m
117 .       ds #F .3m
118 .       ds #[ \f1
119 .       ds #] \fP
120 .\}
121 .if t \{\
122 .       ds #H ((1u-(\\\\n(.fu%2u))*.13m)
123 .       ds #V .6m
124 .       ds #F 0
125 .       ds #[ \&
126 .       ds #] \&
127 .\}
128 .       \" simple accents for nroff and troff
129 .if n \{\
130 .       ds ' \&
131 .       ds ` \&
132 .       ds ^ \&
133 .       ds , \&
134 .       ds ~ ~
135 .       ds ? ?
136 .       ds ! !
137 .       ds /
138 .       ds q
139 .\}
140 .if t \{\
141 .       ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
142 .       ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
143 .       ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
144 .       ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
145 .       ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
146 .       ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
147 .       ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
148 .       ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
149 .       ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
150 .\}
151 .       \" troff and (daisy-wheel) nroff accents
152 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
153 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
154 .ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
155 .ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
156 .ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
157 .ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
158 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
159 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
160 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
161 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
162 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
163 .ds ae a\h'-(\w'a'u*4/10)'e
164 .ds Ae A\h'-(\w'A'u*4/10)'E
165 .ds oe o\h'-(\w'o'u*4/10)'e
166 .ds Oe O\h'-(\w'O'u*4/10)'E
167 .       \" corrections for vroff
168 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
169 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
170 .       \" for low resolution devices (crt and lpr)
171 .if \n(.H>23 .if \n(.V>19 \
172 \{\
173 .       ds : e
174 .       ds 8 ss
175 .       ds v \h'-1'\o'\(aa\(ga'
176 .       ds _ \h'-1'^
177 .       ds . \h'-1'.
178 .       ds 3 3
179 .       ds o a
180 .       ds d- d\h'-1'\(ga
181 .       ds D- D\h'-1'\(hy
182 .       ds th \o'bp'
183 .       ds Th \o'LP'
184 .       ds ae ae
185 .       ds Ae AE
186 .       ds oe oe
187 .       ds Oe OE
188 .\}
189 .rm #[ #] #H #V #F C
190 .SH "NAME"
191 BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr, 
192 BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
193 BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
194 BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request \- BIO pair BIO
195 .SH "SYNOPSIS"
196 .PP
197 .Vb 1
198 \& #include <openssl/bio.h>
199 .Ve
200 .Vb 1
201 \& BIO_METHOD *BIO_s_bio(void);
202 .Ve
203 .Vb 2
204 \& #define BIO_make_bio_pair(b1,b2)   (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
205 \& #define BIO_destroy_bio_pair(b)    (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
206 .Ve
207 .Vb 1
208 \& #define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
209 .Ve
210 .Vb 2
211 \& #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
212 \& #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
213 .Ve
214 .Vb 1
215 \& int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2);
216 .Ve
217 .Vb 2
218 \& #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
219 \& size_t BIO_ctrl_get_write_guarantee(BIO *b);
220 .Ve
221 .Vb 2
222 \& #define BIO_get_read_request(b)    (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
223 \& size_t BIO_ctrl_get_read_request(BIO *b);
224 .Ve
225 .Vb 1
226 \& int BIO_ctrl_reset_read_request(BIO *b);
227 .Ve
228 .SH "DESCRIPTION"
229 \fIBIO_s_bio()\fR returns the method for a BIO pair. A BIO pair is a pair of source/sink
230 BIOs where data written to either half of the pair is buffered and can be read from
231 the other half. Both halves must usually by handled by the same application thread
232 since no locking is done on the internal data structures.
233 .PP
234 Since BIO chains typically end in a source/sink BIO it is possible to make this
235 one half of a BIO pair and have all the data processed by the chain under application
236 control.
237 .PP
238 One typical use of BIO pairs is to place TLS/SSL I/O under application control, this
239 can be used when the application wishes to use a non standard transport for
240 TLS/SSL or the normal socket routines are inappropriate.
241 .PP
242 Calls to \fIBIO_read()\fR will read data from the buffer or request a retry if no
243 data is available.
244 .PP
245 Calls to \fIBIO_write()\fR will place data in the buffer or request a retry if the
246 buffer is full.
247 .PP
248 The standard calls \fIBIO_ctrl_pending()\fR and \fIBIO_ctrl_wpending()\fR can be used to
249 determine the amount of pending data in the read or write buffer.
250 .PP
251 \fIBIO_reset()\fR clears any data in the write buffer.
252 .PP
253 \fIBIO_make_bio_pair()\fR joins two separate BIOs into a connected pair.
254 .PP
255 \fIBIO_destroy_pair()\fR destroys the association between two connected BIOs. Freeing
256 up any half of the pair will automatically destroy the association.
257 .PP
258 \fIBIO_shutdown_wr()\fR is used to close down a BIO \fBb\fR. After this call no further
259 writes on BIO \fBb\fR are allowed (they will return an error). Reads on the other
260 half of the pair will return any pending data or EOF when all pending data has
261 been read. 
262 .PP
263 \fIBIO_set_write_buf_size()\fR sets the write buffer size of BIO \fBb\fR to \fBsize\fR.
264 If the size is not initialized a default value is used. This is currently
265 17K, sufficient for a maximum size TLS record.
266 .PP
267 \fIBIO_get_write_buf_size()\fR returns the size of the write buffer.
268 .PP
269 \fIBIO_new_bio_pair()\fR combines the calls to \fIBIO_new()\fR, \fIBIO_make_bio_pair()\fR and
270 \fIBIO_set_write_buf_size()\fR to create a connected pair of BIOs \fBbio1\fR, \fBbio2\fR
271 with write buffer sizes \fBwritebuf1\fR and \fBwritebuf2\fR. If either size is
272 zero then the default size is used.  \fIBIO_new_bio_pair()\fR does not check whether
273 \fBbio1\fR or \fBbio2\fR do point to some other BIO, the values are overwritten,
274 \fIBIO_free()\fR is not called.
275 .PP
276 \fIBIO_get_write_guarantee()\fR and \fIBIO_ctrl_get_write_guarantee()\fR return the maximum
277 length of data that can be currently written to the BIO. Writes larger than this
278 value will return a value from \fIBIO_write()\fR less than the amount requested or if the
279 buffer is full request a retry. \fIBIO_ctrl_get_write_guarantee()\fR is a function
280 whereas \fIBIO_get_write_guarantee()\fR is a macro.
281 .PP
282 \fIBIO_get_read_request()\fR and \fIBIO_ctrl_get_read_request()\fR return the
283 amount of data requested, or the buffer size if it is less, if the
284 last read attempt at the other half of the BIO pair failed due to an
285 empty buffer.  This can be used to determine how much data should be
286 written to the BIO so the next read will succeed: this is most useful
287 in TLS/SSL applications where the amount of data read is usually
288 meaningful rather than just a buffer size. After a successful read
289 this call will return zero.  It also will return zero once new data
290 has been written satisfying the read request or part of it.
291 Note that \fIBIO_get_read_request()\fR never returns an amount larger
292 than that returned by \fIBIO_get_write_guarantee()\fR.
293 .PP
294 \fIBIO_ctrl_reset_read_request()\fR can also be used to reset the value returned by
295 \fIBIO_get_read_request()\fR to zero.
296 .SH "NOTES"
297 Both halves of a BIO pair should be freed. That is even if one half is implicit
298 freed due to a \fIBIO_free_all()\fR or \fISSL_free()\fR call the other half needs to be freed.
299 .PP
300 When used in bidirectional applications (such as TLS/SSL) care should be taken to
301 flush any data in the write buffer. This can be done by calling \fIBIO_pending()\fR
302 on the other half of the pair and, if any data is pending, reading it and sending
303 it to the underlying transport. This must be done before any normal processing
304 (such as calling \fIselect()\fR ) due to a request and \fIBIO_should_read()\fR being true.
305 .PP
306 To see why this is important consider a case where a request is sent using
307 \fIBIO_write()\fR and a response read with \fIBIO_read()\fR, this can occur during an
308 TLS/SSL handshake for example. \fIBIO_write()\fR will succeed and place data in the write
309 buffer. \fIBIO_read()\fR will initially fail and \fIBIO_should_read()\fR will be true. If
310 the application then waits for data to be available on the underlying transport
311 before flushing the write buffer it will never succeed because the request was
312 never sent!
313 .SH "RETURN VALUES"
314 \fIBIO_new_bio_pair()\fR returns 1 on success, with the new BIOs available in
315 \fBbio1\fR and \fBbio2\fR, or 0 on failure, with NULL pointers stored into the
316 locations for \fBbio1\fR and \fBbio2\fR. Check the error stack for more information.
317 .PP
318 [XXXXX: More return values need to be added here]
319 .SH "EXAMPLE"
320 The BIO pair can be used to have full control over the network access of an
321 application. The application can call \fIselect()\fR on the socket as required
322 without having to go through the SSL\-interface.
323 .PP
324 .Vb 6
325 \& BIO *internal_bio, *network_bio;
326 \& ...
327 \& BIO_new_bio_pair(internal_bio, 0, network_bio, 0);
328 \& SSL_set_bio(ssl, internal_bio, internal_bio);
329 \& SSL_operations();
330 \& ...
331 .Ve
332 .Vb 9
333 \& application |   TLS-engine
334 \&    |        |
335 \&    +----------> SSL_operations()
336 \&             |     /\e    ||
337 \&             |     ||    \e/
338 \&             |   BIO-pair (internal_bio)
339 \&    +----------< BIO-pair (network_bio)
340 \&    |        |
341 \&  socket     |
342 .Ve
343 .Vb 4
344 \&  ...
345 \&  SSL_free(ssl);                /* implicitly frees internal_bio */
346 \&  BIO_free(network_bio);
347 \&  ...
348 .Ve
349 As the BIO pair will only buffer the data and never directly access the
350 connection, it behaves non-blocking and will return as soon as the write
351 buffer is full or the read buffer is drained. Then the application has to
352 flush the write buffer and/or fill the read buffer.
353 .PP
354 Use the \fIBIO_ctrl_pending()\fR, to find out whether data is buffered in the BIO
355 and must be transfered to the network. Use \fIBIO_ctrl_get_read_request()\fR to
356 find out, how many bytes must be written into the buffer before the
357 \fISSL_operation()\fR can successfully be continued.
358 .SH "WARNING"
359 As the data is buffered, \fISSL_operation()\fR may return with a ERROR_SSL_WANT_READ
360 condition, but there is still data in the write buffer. An application must
361 not rely on the error value of \fISSL_operation()\fR but must assure that the
362 write buffer is always flushed first. Otherwise a deadlock may occur as
363 the peer might be waiting for the data before being able to continue.
364 .SH "SEE ALSO"
365 SSL_set_bio(3), ssl(3), bio(3),
366 BIO_should_retry(3), BIO_read(3)
367
368 .rn }` ''
369 .IX Title "BIO_s_bio 3"
370 .IX Name "BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr, 
371 BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
372 BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
373 BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request - BIO pair BIO"
374
375 .IX Header "NAME"
376
377 .IX Header "SYNOPSIS"
378
379 .IX Header "DESCRIPTION"
380
381 .IX Header "NOTES"
382
383 .IX Header "RETURN VALUES"
384
385 .IX Header "EXAMPLE"
386
387 .IX Header "WARNING"
388
389 .IX Header "SEE ALSO"
390