BIO_should_retry.pod 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. =pod
  2. =head1 NAME
  3. BIO_should_read, BIO_should_write,
  4. BIO_should_io_special, BIO_retry_type, BIO_should_retry,
  5. BIO_get_retry_BIO, BIO_get_retry_reason, BIO_set_retry_reason - BIO retry
  6. functions
  7. =head1 SYNOPSIS
  8. #include <openssl/bio.h>
  9. int BIO_should_read(BIO *b);
  10. int BIO_should_write(BIO *b);
  11. int BIO_should_io_special(iBIO *b);
  12. int BIO_retry_type(BIO *b);
  13. int BIO_should_retry(BIO *b);
  14. BIO *BIO_get_retry_BIO(BIO *bio, int *reason);
  15. int BIO_get_retry_reason(BIO *bio);
  16. void BIO_set_retry_reason(BIO *bio, int reason);
  17. =head1 DESCRIPTION
  18. These functions determine why a BIO is not able to read or write data.
  19. They will typically be called after a failed BIO_read_ex() or BIO_write_ex()
  20. call.
  21. BIO_should_retry() is true if the call that produced this condition
  22. should then be retried at a later time.
  23. If BIO_should_retry() is false then the cause is an error condition.
  24. BIO_should_read() is true if the cause of the condition is that a BIO
  25. needs to read data.
  26. BIO_should_write() is true if the cause of the condition is that a BIO
  27. needs to read data.
  28. BIO_should_io_special() is true if some "special" condition, that is a
  29. reason other than reading or writing is the cause of the condition.
  30. BIO_retry_type() returns a mask of the cause of a retry condition
  31. consisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
  32. B<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
  33. these.
  34. BIO_get_retry_BIO() determines the precise reason for the special
  35. condition, it returns the BIO that caused this condition and if
  36. B<reason> is not NULL it contains the reason code. The meaning of
  37. the reason code and the action that should be taken depends on
  38. the type of BIO that resulted in this condition.
  39. BIO_get_retry_reason() returns the reason for a special condition if
  40. passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
  41. BIO_set_retry_reason() sets the retry reason for a special condition for a given
  42. BIO. This would usually only be called by BIO implementations.
  43. =head1 NOTES
  44. BIO_should_read(), BIO_should_write(), BIO_should_io_special(),
  45. BIO_retry_type(), and BIO_should_retry(), are implemented as macros.
  46. If BIO_should_retry() returns false then the precise "error condition"
  47. depends on the BIO type that caused it and the return code of the BIO
  48. operation. For example if a call to BIO_read_ex() on a socket BIO returns
  49. 0 and BIO_should_retry() is false then the cause will be that the
  50. connection closed. A similar condition on a file BIO will mean that it
  51. has reached EOF. Some BIO types may place additional information on
  52. the error queue. For more details see the individual BIO type manual
  53. pages.
  54. If the underlying I/O structure is in a blocking mode almost all current
  55. BIO types will not request a retry, because the underlying I/O
  56. calls will not. If the application knows that the BIO type will never
  57. signal a retry then it need not call BIO_should_retry() after a failed
  58. BIO I/O call. This is typically done with file BIOs.
  59. SSL BIOs are the only current exception to this rule: they can request a
  60. retry even if the underlying I/O structure is blocking, if a handshake
  61. occurs during a call to BIO_read(). An application can retry the failed
  62. call immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
  63. on the underlying SSL structure.
  64. While an application may retry a failed non blocking call immediately
  65. this is likely to be very inefficient because the call will fail
  66. repeatedly until data can be processed or is available. An application
  67. will normally wait until the necessary condition is satisfied. How
  68. this is done depends on the underlying I/O structure.
  69. For example if the cause is ultimately a socket and BIO_should_read()
  70. is true then a call to select() may be made to wait until data is
  71. available and then retry the BIO operation. By combining the retry
  72. conditions of several non blocking BIOs in a single select() call
  73. it is possible to service several BIOs in a single thread, though
  74. the performance may be poor if SSL BIOs are present because long delays
  75. can occur during the initial handshake process.
  76. It is possible for a BIO to block indefinitely if the underlying I/O
  77. structure cannot process or return any data. This depends on the behaviour of
  78. the platforms I/O functions. This is often not desirable: one solution
  79. is to use non blocking I/O and use a timeout on the select() (or
  80. equivalent) call.
  81. =head1 BUGS
  82. The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
  83. that is they cannot retry after a partial read or write. This is usually
  84. worked around by only passing the relevant data to ASN1 functions when
  85. the entire structure can be read or written.
  86. =head1 RETURN VALUES
  87. BIO_should_read(), BIO_should_write(), BIO_should_io_special(), and
  88. BIO_should_retry() return either 1 or 0 based on the actual conditions
  89. of the B<BIO>.
  90. BIO_retry_type() returns a flag combination presenting the cause of a retry
  91. condition or false if there is no retry condition.
  92. BIO_get_retry_BIO() returns a valid B<BIO> structure.
  93. BIO_get_retry_reason() returns the reason for a special condition.
  94. =head1 SEE ALSO
  95. L<bio>
  96. =head1 HISTORY
  97. The BIO_get_retry_reason() and BIO_set_retry_reason() functions were added in
  98. OpenSSL 1.1.0.
  99. =head1 COPYRIGHT
  100. Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
  101. Licensed under the OpenSSL license (the "License"). You may not use
  102. this file except in compliance with the License. You can obtain a copy
  103. in the file LICENSE in the source distribution or at
  104. L<https://www.openssl.org/source/license.html>.
  105. =cut