BIO_should_retry.pod 5.6 KB

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