MCPcopy Create free account
hub / github.com/boostorg/asio / async_write_message

Function async_write_message

example/cpp20/operations/composed_1.cpp:34–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 boost::asio::completion_token_for<void(boost::system::error_code, std::size_t)>
33 CompletionToken>
34auto async_write_message(tcp::socket& socket,
35 const char* message, CompletionToken&& token)
36 // The return type of the initiating function is deduced from the combination
37 // of:
38 //
39 // - the CompletionToken type,
40 // - the completion handler signature, and
41 // - the asynchronous operation's initiation function object.
42 //
43 // When the completion token is a simple callback, the return type is void.
44 // However, when the completion token is boost::asio::yield_context (used for
45 // stackful coroutines) the return type would be std::size_t, and when the
46 // completion token is boost::asio::use_future it would be std::future<std::size_t>.
47 // When the completion token is boost::asio::deferred, the return type differs for
48 // each asynchronous operation.
49 //
50 // In C++20 we can omit the return type as it is automatically deduced from
51 // the return type of our underlying asynchronous operation.
52{
53 // When delegating to the underlying operation we must take care to perfectly
54 // forward the completion token. This ensures that our operation works
55 // correctly with move-only function objects as callbacks, as well as other
56 // completion token types.
57 return boost::asio::async_write(socket,
58 boost::asio::buffer(message, std::strlen(message)),
59 std::forward<CompletionToken>(token));
60}
61
62//------------------------------------------------------------------------------
63

Callers 3

test_callbackFunction · 0.70
test_deferredFunction · 0.70
test_futureFunction · 0.70

Calls 2

async_writeFunction · 0.85
bufferFunction · 0.85

Tested by 3

test_callbackFunction · 0.56
test_deferredFunction · 0.56
test_futureFunction · 0.56