07_teardown.qbk 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. [section Teardown]
  8. The WebSocket protocol requirements described in rfc6455 section 7.1.1
  9. outline an operation described as
  10. [@https://tools.ietf.org/html/rfc6455#section-7.1.1 ['Close the WebSocket Connection]].
  11. This operation cleanly discards bytes remaining at receiving endpoints
  12. and also closes the underlying TCP/IP connection. Orderly shutdowns are
  13. always preferred; for TLS or SSL streams, a protocol-level shutdown is
  14. desired. This presents a small issue for the
  15. [link beast.ref.boost__beast__websocket__stream `stream`]
  16. implementation: the stream's `NextLayer` template type requires only
  17. __SyncStream__ or __AsyncStream__, but those concepts do not support
  18. the operations to shut down the connection.
  19. To enable the implementation to perform the shutdown components of the
  20. close operation, the library exposes two customization points expressed
  21. as free functions associated with the next layer type:
  22. * [link beast.ref.boost__beast__websocket__teardown `teardown`]: Overloads
  23. of this function drain and shut down a stream synchronously.
  24. * [link beast.ref.boost__beast__websocket__teardown `async_teardown`]:
  25. Overloads of this function drain and shut down a stream asynchronously.
  26. The implementation provides suitable overloads of the teardown
  27. customization points when websocket streams are instantiated using the
  28. Asio types __socket__ or __ssl_stream__ for the next layer. In this
  29. case no user action is required. However, when the websocket stream is
  30. instantiated for a user-defined type, compile errors will result if the
  31. customization points are not provided for the user defined type.
  32. Furthermore, user-defined types that wrap one of the Asio objects
  33. mentioned earlier may wish to invoke a teardown customization point
  34. for the wrapped object. This is how those tasks are accomplished.
  35. [heading User-defined Teardown]
  36. To provide overloads of teardown for a user-defined type, simply declare
  37. the two free functions with the correct signature, accepting a reference
  38. to the user-defined type as the stream parameter:
  39. [code_websocket_7_1]
  40. When the implementation invokes the asynchronous teardown function, it
  41. always uses an invokable completion handler. It is not necessary
  42. to specify the return type customization when creating user-defined
  43. overloads of `async_teardown`.
  44. [heading Invoking Teardown]
  45. To invoke the customization point, first bring the default implementation
  46. into scope with a `using` statement. Then call the customization point
  47. without namespace qualification, allowing argument-dependent lookup to
  48. take effect:
  49. [code_websocket_7_2]
  50. [endsect]