08_notes.qbk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Notes]
  8. Because calls to read data may return a variable amount of bytes, the
  9. interface to calls that read data require an object that meets the requirements
  10. of __DynamicBuffer__. This concept is modeled on __streambuf__.
  11. The implementation does not perform queueing or buffering of messages. If
  12. desired, these features should be provided by callers. The impact of this
  13. design is that library users are in full control of the allocation strategy
  14. used to store data and the back-pressure applied on the read and write side
  15. of the underlying TCP/IP connection.
  16. [heading Asynchronous Operations]
  17. Asynchronous versions are available for all functions:
  18. [code_websocket_8_1]
  19. Calls to asynchronous initiation functions support the extensible asynchronous
  20. model developed by the Boost.Asio author, allowing for traditional completion
  21. handlers, stackful or stackless coroutines, and even futures:
  22. [code_websocket_8_1f]
  23. The example programs that come with the library demonstrate the usage of
  24. websocket stream operations with all asynchronous varieties.
  25. [heading The io_context]
  26. The creation and operation of the __io_context__ associated with the
  27. underlying stream is left to the callers, permitting any implementation
  28. strategy including one that does not require threads for environments
  29. where threads are unavailable. Beast WebSocket itself does not use
  30. or require threads.
  31. [heading Thread Safety]
  32. Like a regular __Asio__ socket, a
  33. [link beast.ref.boost__beast__websocket__stream `stream`]
  34. is not thread safe. Callers are responsible for synchronizing operations on
  35. the socket using an implicit or explicit strand, as per the Asio documentation.
  36. The websocket stream asynchronous interface supports one of each of the
  37. following operations to be active at the same time:
  38. * [link beast.ref.boost__beast__websocket__stream.async_read `async_read`] or [link beast.ref.boost__beast__websocket__stream.async_read_some `async_read_some`]
  39. * [link beast.ref.boost__beast__websocket__stream.async_write `async_write`] or [link beast.ref.boost__beast__websocket__stream.async_write_some `async_write_some`]
  40. * [link beast.ref.boost__beast__websocket__stream.async_ping `async_ping`] or [link beast.ref.boost__beast__websocket__stream.async_pong `async_pong`]
  41. * [link beast.ref.boost__beast__websocket__stream.async_close `async_close`]
  42. For example, the following code is produces undefined behavior, because the
  43. program is attempting to perform two simultaneous reads:
  44. [code_websocket_8_2]
  45. However, this code is correct:
  46. [code_websocket_8_3]
  47. The implementation uses composed asynchronous operations; although
  48. some individual operations can perform both reads and writes, this
  49. behavior is coordinated internally to make sure the underlying stream
  50. is operated in a safe fashion. This allows an asynchronous read operation
  51. to respond to a received ping frame even while a user-initiated call to
  52. asynchronous write is active.
  53. [endsect]