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

Function async_write_message

example/cpp11/operations/composed_1.cpp:32–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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