BIO_should_retry.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. =pod
  2. =head1 NAME
  3. BIO_should_retry, 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 retry functions
  6. =head1 SYNOPSIS
  7. #include <openssl/bio.h>
  8. #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
  9. #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
  10. #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
  11. #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
  12. #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
  13. #define BIO_FLAGS_READ 0x01
  14. #define BIO_FLAGS_WRITE 0x02
  15. #define BIO_FLAGS_IO_SPECIAL 0x04
  16. #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
  17. #define BIO_FLAGS_SHOULD_RETRY 0x08
  18. BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
  19. int BIO_get_retry_reason(BIO *bio);
  20. =head1 DESCRIPTION
  21. These functions determine why a BIO is not able to read or write data.
  22. They will typically be called after a failed BIO_read() or BIO_write()
  23. call.
  24. BIO_should_retry() is true if the call that produced this condition
  25. should then be retried at a later time.
  26. If BIO_should_retry() is false then the cause is an error condition.
  27. BIO_should_read() is true if the cause of the condition is that a BIO
  28. needs to read data.
  29. BIO_should_write() is true if the cause of the condition is that a BIO
  30. needs to read data.
  31. BIO_should_io_special() is true if some "special" condition, that is a
  32. reason other than reading or writing is the cause of the condition.
  33. BIO_retry_type() returns a mask of the cause of a retry condition
  34. consisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
  35. B<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
  36. these.
  37. BIO_get_retry_BIO() determines the precise reason for the special
  38. condition, it returns the BIO that caused this condition and if
  39. B<reason> is not NULL it contains the reason code. The meaning of
  40. the reason code and the action that should be taken depends on
  41. the type of BIO that resulted in this condition.
  42. BIO_get_retry_reason() returns the reason for a special condition if
  43. passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
  44. =head1 NOTES
  45. If BIO_should_retry() returns false then the precise "error condition"
  46. depends on the BIO type that caused it and the return code of the BIO
  47. operation. For example if a call to BIO_read() on a socket BIO returns
  48. 0 and BIO_should_retry() is false then the cause will be that the
  49. connection closed. A similar condition on a file BIO will mean that it
  50. has reached EOF. Some BIO types may place additional information on
  51. the error queue. For more details see the individual BIO type manual
  52. pages.
  53. If the underlying I/O structure is in a blocking mode almost all current
  54. BIO types will not request a retry, because the underlying I/O
  55. calls will not. If the application knows that the BIO type will never
  56. signal a retry then it need not call BIO_should_retry() after a failed
  57. BIO I/O call. This is typically done with file BIOs.
  58. SSL BIOs are the only current exception to this rule: they can request a
  59. retry even if the underlying I/O structure is blocking, if a handshake
  60. occurs during a call to BIO_read(). An application can retry the failed
  61. call immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
  62. on the underlying SSL structure.
  63. While an application may retry a failed non blocking call immediately
  64. this is likely to be very inefficient because the call will fail
  65. repeatedly until data can be processed or is available. An application
  66. will normally wait until the necessary condition is satisfied. How
  67. this is done depends on the underlying I/O structure.
  68. For example if the cause is ultimately a socket and BIO_should_read()
  69. is true then a call to select() may be made to wait until data is
  70. available and then retry the BIO operation. By combining the retry
  71. conditions of several non blocking BIOs in a single select() call
  72. it is possible to service several BIOs in a single thread, though
  73. the performance may be poor if SSL BIOs are present because long delays
  74. can occur during the initial handshake process.
  75. It is possible for a BIO to block indefinitely if the underlying I/O
  76. structure cannot process or return any data. This depends on the behaviour of
  77. the platforms I/O functions. This is often not desirable: one solution
  78. is to use non blocking I/O and use a timeout on the select() (or
  79. equivalent) call.
  80. =head1 BUGS
  81. The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
  82. that is they cannot retry after a partial read or write. This is usually
  83. worked around by only passing the relevant data to ASN1 functions when
  84. the entire structure can be read or written.
  85. =head1 SEE ALSO
  86. TBA