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