06_timeouts.qbk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. [/
  2. Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. Official repository: https://github.com/boostorg/beast
  6. ]
  7. [/-----------------------------------------------------------------------------]
  8. [section:timeouts Timeouts]
  9. While
  10. [link beast.ref.boost__beast__basic_stream `basic_stream`] and
  11. [link beast.ref.boost__beast__basic_stream `tcp_stream`] support timeouts on
  12. general logical operations, the websocket stream has a more sophisticated timeout
  13. mechanism built-in which may be enabled and configured. The timeout features
  14. of the TCP or basic stream should not be used when working with a websocket
  15. stream. The interface to these timeout features is show in this table.
  16. [table WebSocket Timeout Interface
  17. [[Name][Description]]
  18. [[
  19. [link beast.ref.boost__beast__websocket__stream_base__timeout `stream_base::timeout`]
  20. ][
  21. This represents configured timeout settings for a websocket stream.
  22. ]]
  23. [[
  24. [link beast.ref.boost__beast__websocket__stream_base__timeout.suggested `stream_base::timeout::suggested`]
  25. ][
  26. This function returns the suggested timeout settings for a given role
  27. (client or server).
  28. ]]
  29. [[
  30. [link beast.ref.boost__beast__websocket__stream.set_option `stream::set_option`]
  31. ][
  32. This function sets timeout and other options on the stream.
  33. ]]
  34. ]
  35. There are three timeout settings which may be set independently on the stream:
  36. [table WebSocket Timeout Interface (2)
  37. [[Name][Type][Description]]
  38. [
  39. [[link beast.ref.boost__beast__websocket__stream_base__timeout.handshake_timeout `timeout::handshake_timeout`]]
  40. [`duration`]
  41. [
  42. This is the amount of time after which a handshake will time out.
  43. The handshake timeout applies to client handshakes, server handshakes,
  44. as well as the websocket closing handshake performed when either
  45. end of the connection wish to shut down.
  46. The value returned by
  47. [link beast.ref.boost__beast__websocket__stream_base.none `stream_base::none()`]
  48. may be assigned to disable this timeout.
  49. ]
  50. ][
  51. [[link beast.ref.boost__beast__websocket__stream_base__timeout.idle_timeout `timeout::idle_timeout`]]
  52. [`duration`]
  53. [
  54. If no data is received from the peer for a time equal to the idle
  55. timeout, then the connection will time out.
  56. The value returned by
  57. [link beast.ref.boost__beast__websocket__stream_base.none `stream_base::none()`]
  58. may be assigned to disable this timeout.
  59. ]
  60. ][
  61. [[link beast.ref.boost__beast__websocket__stream_base__timeout.keep_alive_pings `timeout::keep_alive_pings`]]
  62. [`bool`]
  63. [
  64. If the idle timeout is enabled, then the value of this setting
  65. controls whether or not a ping frame will be sent to the peer if
  66. no data is received for half of the idle timeout interval.
  67. ]
  68. ]
  69. ]
  70. By default, timeouts on websocket streams are disabled. The easiest way
  71. to turn them on is to set the suggested timeout settings on the stream.
  72. [code_websocket_6_1]
  73. For manual control over the settings, a timeout options object may be
  74. constructed. Here we enable only the handshake timeout.
  75. [code_websocket_6_2]
  76. Timeout notifications are delivered to the caller by invoking the completion
  77. handler for an outstanding asynchronous read operation with the error code
  78. [link beast.ref.boost__beast__error `error::timeout`]. The implementation
  79. will close the socket or stream before delivering this error. It is not
  80. necessary to manually shut down the connection, as it will already be shut
  81. down. A read operation must be outstanding for the error to be delivered.
  82. [code_websocket_6_3]
  83. [note
  84. Websocket timeout features are available only when using asynchronous I/O.
  85. ]
  86. The timeouts on the websocket stream are incompatible with the timeouts
  87. used in the `tcp_stream`. When constructing a websocket stream from a tcp
  88. stream that has timeouts enabled, the timeout should be disabled first before
  89. constructing the websocket stream, as shown.
  90. [code_websocket_6_4]
  91. [endsect]