bio_new_bio_pair.pod

来自「一个用于点对点传输加密的工具包源码」· POD 代码 · 共 103 行

POD
103
字号
=pod=head1 NAMEBIO_new_bio_pair - create a new BIO pair=head1 SYNOPSIS #include <openssl/bio.h> int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, BIO **bio2, size_t writebuf2);=head1 DESCRIPTIONBIO_new_bio_pair() creates a buffering BIO pair. It has two endpoints betweendata can be buffered. Its typical use is to connect one endpoint as underlyinginput/output BIO to an SSL and access the other one controlled by the programinstead of accessing the network connection directly.The two new BIOs B<bio1> and B<bio2> are symmetric with respect to theirfunctionality. The size of their buffers is determined by B<writebuf1> andB<writebuf2>. If the size give is 0, the default size is used.BIO_new_bio_pair() does not check whether B<bio1> or B<bio2> do point tosome other BIO, the values are overwritten, BIO_free() is not called.The two BIOs, even though forming a BIO pair and must be BIO_free()'edseparately. This can be of importance, as some SSL-functions like SSL_set_bio()or SSL_free() call BIO_free() implicitly, so that the peer-BIO is leftuntouched and must also be BIO_free()'ed.=head1 EXAMPLEThe BIO pair can be used to have full control over the network access of anapplication. The application can call select() on the socket as requiredwithout having to go through the SSL-interface. BIO *internal_bio, *network_bio; ... BIO_new_bio_pair(internal_bio, 0, network_bio, 0); SSL_set_bio(ssl, internal_bio); SSL_operations(); ... application |   TLS-engine    |        |    +----------> SSL_operations()             |     /\    ||             |     ||    \/             |   BIO-pair (internal_bio)    +----------< BIO-pair (network_bio)    |        |  socket     |  ...  SSL_free(ssl);		/* implicitly frees internal_bio */  BIO_free(network_bio);  ...As the BIO pair will only buffer the data and never directly access theconnection, it behaves non-blocking and will return as soon as the writebuffer is full or the read buffer is drained. Then the application has toflush the write buffer and/or fill the read buffer.Use the BIO_ctrl_pending(), to find out whether data is buffered in the BIOand must be transfered to the network. Use BIO_ctrl_get_read_request() tofind out, how many bytes must be written into the buffer before theSSL_operation() can successfully be continued.=head1 IMPORTANTAs the data is buffered, SSL_operation() may return with a ERROR_SSL_WANT_READcondition, but there is still data in the write buffer. An application mustnot rely on the error value of SSL_operation() but must assure that thewrite buffer is always flushed first. Otherwise a deadlock may occur asthe peer might be waiting for the data before being able to continue.=head1 RETURN VALUESThe following return values can occur:=over 4=item 1The BIO pair was created successfully. The new BIOs are available inB<bio1> and B<bio2>.=item 0The operation failed. The NULL pointer is stored into the locations forB<bio1> and B<bio2>. Check the error stack for more information.=back=head1 SEE ALSOL<SSL_set_bio(3)|SSL_set_bio(3)>, L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>,L<BIO_ctrl_pending(3)|BIO_ctrl_pending(3)>,L<BIO_ctrl_get_read_request(3)|BIO_ctrl_get_read_request(3)>=cut

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?