Search code examples
boost-beast

about boost beast websocket api : async_close, async_write


I have read the official document.I'm confused that the document conflict itself. Here is the document picked from the official:

However, this code is well-formed:

ws.async_read(b, [](error_code, std::size_t){});

ws.async_write(b.data(), [](error_code, std::size_t){});

ws.async_ping({}, {});

ws.async_close({}, {});

and here is another snippet:

This operation is implemented in terms of one or more calls to the next layer's async_write_some functions, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as websocket::stream::async_write, websocket::stream::async_write_some, or websocket::stream::async_close).

so, which one should I trust?


Solution

  • This part is correct:

    https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/using_websocket/notes.html#beast.using_websocket.notes.thread_safety

    The other text needs to be updated.