Commit manual pages after running 'man-update' and add new manual pages.
[dragonfly.git] / secure / lib / libcrypto / man / BIO_s_bio.3
CommitLineData
74dab6c2
JR
1.rn '' }`
2''' $RCSfile$$Revision$$Date$
3'''
4''' $Log$
5'''
6.de Sh
984263bc
MD
7.br
8.if t .Sp
9.ne 5
10.PP
11\fB\\$1\fR
12.PP
13..
74dab6c2 14.de Sp
984263bc
MD
15.if t .sp .5v
16.if n .sp
17..
74dab6c2 18.de Ip
984263bc
MD
19.br
20.ie \\n(.$>=3 .ne \\$3
21.el .ne 3
22.IP "\\$1" \\$2
23..
74dab6c2 24.de Vb
984263bc
MD
25.ft CW
26.nf
27.ne \\$1
28..
74dab6c2 29.de Ve
984263bc
MD
30.ft R
31
32.fi
33..
74dab6c2
JR
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'''
984263bc 40.tr \(*W-|\(bv\*(Tr
984263bc 41.ie n \{\
74dab6c2
JR
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' '
984263bc
MD
62'br\}
63.el\{\
74dab6c2
JR
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
984263bc 79'br\}
74dab6c2
JR
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"
984263bc 92..
74dab6c2
JR
93.nr % 0
94.rr F
984263bc 95.\}
74dab6c2
JR
96.TH BIO_s_bio 3 "0.9.7d" "2/Sep/2004" "OpenSSL"
97.UC
98.if n .hy 0
984263bc 99.if n .na
74dab6c2
JR
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
984263bc 112.bd B 3
74dab6c2 113. \" fudge factors for nroff and troff
984263bc 114.if n \{\
74dab6c2
JR
115. ds #H 0
116. ds #V .8m
117. ds #F .3m
118. ds #[ \f1
119. ds #] \fP
984263bc
MD
120.\}
121.if t \{\
74dab6c2
JR
122. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
123. ds #V .6m
124. ds #F 0
125. ds #[ \&
126. ds #] \&
984263bc 127.\}
74dab6c2 128. \" simple accents for nroff and troff
984263bc 129.if n \{\
74dab6c2
JR
130. ds ' \&
131. ds ` \&
132. ds ^ \&
133. ds , \&
134. ds ~ ~
135. ds ? ?
136. ds ! !
137. ds /
138. ds q
984263bc
MD
139.\}
140.if t \{\
74dab6c2
JR
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'
984263bc 150.\}
74dab6c2 151. \" troff and (daisy-wheel) nroff accents
984263bc
MD
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'
74dab6c2
JR
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'\*(#]
984263bc
MD
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
74dab6c2
JR
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
984263bc
MD
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'
74dab6c2 170. \" for low resolution devices (crt and lpr)
984263bc
MD
171.if \n(.H>23 .if \n(.V>19 \
172\{\
74dab6c2
JR
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
984263bc
MD
188.\}
189.rm #[ #] #H #V #F C
984263bc
MD
190.SH "NAME"
191BIO_s_bio, BIO_make_bio_pair, BIO_destroy_bio_pair, BIO_shutdown_wr,
192BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
193BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
74dab6c2 194BIO_ctrl_get_read_request, BIO_ctrl_reset_read_request \- BIO pair BIO
984263bc 195.SH "SYNOPSIS"
74dab6c2 196.PP
984263bc
MD
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"
74dab6c2 229\fIBIO_s_bio()\fR returns the method for a BIO pair. A BIO pair is a pair of source/sink
984263bc
MD
230BIOs where data written to either half of the pair is buffered and can be read from
231the other half. Both halves must usually by handled by the same application thread
232since no locking is done on the internal data structures.
233.PP
74dab6c2
JR
234Since BIO chains typically end in a source/sink BIO it is possible to make this
235one half of a BIO pair and have all the data processed by the chain under application
984263bc
MD
236control.
237.PP
74dab6c2 238One typical use of BIO pairs is to place TLS/SSL I/O under application control, this
984263bc 239can be used when the application wishes to use a non standard transport for
74dab6c2 240TLS/SSL or the normal socket routines are inappropriate.
984263bc
MD
241.PP
242Calls to \fIBIO_read()\fR will read data from the buffer or request a retry if no
243data is available.
244.PP
245Calls to \fIBIO_write()\fR will place data in the buffer or request a retry if the
246buffer is full.
247.PP
248The standard calls \fIBIO_ctrl_pending()\fR and \fIBIO_ctrl_wpending()\fR can be used to
249determine the amount of pending data in the read or write buffer.
250.PP
74dab6c2 251\fIBIO_reset()\fR clears any data in the write buffer.
984263bc 252.PP
74dab6c2 253\fIBIO_make_bio_pair()\fR joins two separate BIOs into a connected pair.
984263bc 254.PP
74dab6c2 255\fIBIO_destroy_pair()\fR destroys the association between two connected BIOs. Freeing
984263bc
MD
256up any half of the pair will automatically destroy the association.
257.PP
74dab6c2
JR
258\fIBIO_shutdown_wr()\fR is used to close down a BIO \fBb\fR. After this call no further
259writes on BIO \fBb\fR are allowed (they will return an error). Reads on the other
260half of the pair will return any pending data or EOF when all pending data has
984263bc
MD
261been read.
262.PP
74dab6c2 263\fIBIO_set_write_buf_size()\fR sets the write buffer size of BIO \fBb\fR to \fBsize\fR.
984263bc 264If the size is not initialized a default value is used. This is currently
74dab6c2 26517K, sufficient for a maximum size TLS record.
984263bc 266.PP
74dab6c2 267\fIBIO_get_write_buf_size()\fR returns the size of the write buffer.
984263bc 268.PP
74dab6c2
JR
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
984263bc
MD
271with write buffer sizes \fBwritebuf1\fR and \fBwritebuf2\fR. If either size is
272zero then the default size is used. \fIBIO_new_bio_pair()\fR does not check whether
74dab6c2
JR
273\fBbio1\fR or \fBbio2\fR do point to some other BIO, the values are overwritten,
274\fIBIO_free()\fR is not called.
984263bc 275.PP
74dab6c2
JR
276\fIBIO_get_write_guarantee()\fR and \fIBIO_ctrl_get_write_guarantee()\fR return the maximum
277length of data that can be currently written to the BIO. Writes larger than this
984263bc
MD
278value will return a value from \fIBIO_write()\fR less than the amount requested or if the
279buffer is full request a retry. \fIBIO_ctrl_get_write_guarantee()\fR is a function
280whereas \fIBIO_get_write_guarantee()\fR is a macro.
281.PP
74dab6c2 282\fIBIO_get_read_request()\fR and \fIBIO_ctrl_get_read_request()\fR return the
984263bc 283amount of data requested, or the buffer size if it is less, if the
74dab6c2 284last read attempt at the other half of the BIO pair failed due to an
984263bc 285empty buffer. This can be used to determine how much data should be
74dab6c2
JR
286written to the BIO so the next read will succeed: this is most useful
287in TLS/SSL applications where the amount of data read is usually
984263bc
MD
288meaningful rather than just a buffer size. After a successful read
289this call will return zero. It also will return zero once new data
290has been written satisfying the read request or part of it.
291Note that \fIBIO_get_read_request()\fR never returns an amount larger
292than that returned by \fIBIO_get_write_guarantee()\fR.
293.PP
74dab6c2
JR
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.
984263bc 296.SH "NOTES"
74dab6c2 297Both halves of a BIO pair should be freed. That is even if one half is implicit
984263bc
MD
298freed due to a \fIBIO_free_all()\fR or \fISSL_free()\fR call the other half needs to be freed.
299.PP
74dab6c2 300When used in bidirectional applications (such as TLS/SSL) care should be taken to
984263bc
MD
301flush any data in the write buffer. This can be done by calling \fIBIO_pending()\fR
302on the other half of the pair and, if any data is pending, reading it and sending
303it 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
306To see why this is important consider a case where a request is sent using
74dab6c2
JR
307\fIBIO_write()\fR and a response read with \fIBIO_read()\fR, this can occur during an
308TLS/SSL handshake for example. \fIBIO_write()\fR will succeed and place data in the write
984263bc
MD
309buffer. \fIBIO_read()\fR will initially fail and \fIBIO_should_read()\fR will be true. If
310the application then waits for data to be available on the underlying transport
311before flushing the write buffer it will never succeed because the request was
312never sent!
313.SH "RETURN VALUES"
74dab6c2
JR
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
984263bc
MD
316locations for \fBbio1\fR and \fBbio2\fR. Check the error stack for more information.
317.PP
74dab6c2 318[XXXXX: More return values need to be added here]
984263bc 319.SH "EXAMPLE"
74dab6c2 320The BIO pair can be used to have full control over the network access of an
984263bc 321application. The application can call \fIselect()\fR on the socket as required
74dab6c2 322without having to go through the SSL\-interface.
984263bc
MD
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
74dab6c2 349As the BIO pair will only buffer the data and never directly access the
984263bc
MD
350connection, it behaves non-blocking and will return as soon as the write
351buffer is full or the read buffer is drained. Then the application has to
352flush the write buffer and/or fill the read buffer.
353.PP
74dab6c2 354Use the \fIBIO_ctrl_pending()\fR, to find out whether data is buffered in the BIO
984263bc
MD
355and must be transfered to the network. Use \fIBIO_ctrl_get_read_request()\fR to
356find out, how many bytes must be written into the buffer before the
74dab6c2 357\fISSL_operation()\fR can successfully be continued.
984263bc 358.SH "WARNING"
74dab6c2 359As the data is buffered, \fISSL_operation()\fR may return with a ERROR_SSL_WANT_READ
984263bc
MD
360condition, but there is still data in the write buffer. An application must
361not rely on the error value of \fISSL_operation()\fR but must assure that the
362write buffer is always flushed first. Otherwise a deadlock may occur as
363the peer might be waiting for the data before being able to continue.
364.SH "SEE ALSO"
984263bc
MD
365SSL_set_bio(3), ssl(3), bio(3),
366BIO_should_retry(3), BIO_read(3)
74dab6c2
JR
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,
371BIO_set_write_buf_size, BIO_get_write_buf_size, BIO_new_bio_pair,
372BIO_get_write_guarantee, BIO_ctrl_get_write_guarantee, BIO_get_read_request,
373BIO_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