BIO_new_bio_pair.pod 3.3 KB

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