Typo.
[openssl.git] / doc / crypto / BIO_new_bio_pair.pod
1 =pod
2
3 =head1 NAME
4
5 BIO_new_bio_pair - create a new BIO pair
6
7 =head1 SYNOPSIS
8
9  #include <openssl/bio.h>
10
11  int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2);
12
13 =head1 DESCRIPTION
14
15 BIO_new_bio_pair() creates a buffering BIO pair based on the
16 L<SSL_set_bio(3)|SSL_set_bio(3)> method. The BIO pair has two endpoints between which
17 data can be buffered. Its typical use is to connect one endpoint as underlying
18 input/output BIO to an SSL and access the other one controlled by the program
19 instead of accessing the network connection directly.
20
21 The two new BIOs B<bio1> and B<bio2> are symmetric with respect to their
22 functionality. The size of their buffers is determined by B<writebuf1> and
23 B<writebuf2>. If the size give is 0, the default size is used.
24
25 BIO_new_bio_pair() does not check whether B<bio1> or B<bio2> do point to
26 some other BIO, the values are overwritten, BIO_free() is not called.
27
28 The two BIOs, even though forming a BIO pair and must be BIO_free()'ed
29 separately. This can be of importance, as some SSL-functions like SSL_set_bio()
30 or SSL_free() call BIO_free() implicitly, so that the peer-BIO is left
31 untouched and must also be BIO_free()'ed.
32
33 =head1 EXAMPLE
34
35 The BIO pair can be used to have full control over the network access of an
36 application. The application can call select() on the socket as required
37 without having to go through the SSL-interface.
38
39  BIO *internal_bio, *network_bio;
40  ...
41  BIO_new_bio_pair(internal_bio, 0, network_bio, 0);
42  SSL_set_bio(ssl, internal_bio, internal_bio);
43  SSL_operations();
44  ...
45
46  application |   TLS-engine
47     |        |
48     +----------> SSL_operations()
49              |     /\    ||
50              |     ||    \/
51              |   BIO-pair (internal_bio)
52     +----------< BIO-pair (network_bio)
53     |        |
54   socket     |
55
56   ...
57   SSL_free(ssl);                /* implicitly frees internal_bio */
58   BIO_free(network_bio);
59   ...
60
61 As the BIO pair will only buffer the data and never directly access the
62 connection, it behaves non-blocking and will return as soon as the write
63 buffer is full or the read buffer is drained. Then the application has to
64 flush the write buffer and/or fill the read buffer.
65
66 Use the BIO_ctrl_pending(), to find out whether data is buffered in the BIO
67 and must be transfered to the network. Use BIO_ctrl_get_read_request() to
68 find out, how many bytes must be written into the buffer before the
69 SSL_operation() can successfully be continued.
70
71 =head1 WARNING
72
73 As the data is buffered, SSL_operation() may return with a ERROR_SSL_WANT_READ
74 condition, but there is still data in the write buffer. An application must
75 not rely on the error value of SSL_operation() but must assure that the
76 write buffer is always flushed first. Otherwise a deadlock may occur as
77 the peer might be waiting for the data before being able to continue.
78
79 =head1 RETURN VALUES
80
81 The following return values can occur:
82
83 =over 4
84
85 =item 1
86
87 The BIO pair was created successfully. The new BIOs are available in
88 B<bio1> and B<bio2>.
89
90 =item 0
91
92 The operation failed. The NULL pointer is stored into the locations for
93 B<bio1> and B<bio2>. Check the error stack for more information.
94
95 =back
96
97 =head1 SEE ALSO
98
99 L<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,
100 L<BIO_ctrl_pending(3)|BIO_ctrl_pending(3)>,
101 L<BIO_ctrl_get_read_request(3)|BIO_ctrl_get_read_request(3)>
102
103 =cut