async_echo supports move-only handlers

fix #1420
This commit is contained in:
Vinnie Falco
2019-02-02 10:20:38 -08:00
parent e0db595760
commit 599104c16a
2 changed files with 15 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
Version 209:
* Faster http::string_to_field
* async_echo supports move-only handlers
--------------------------------------------------------------------------------

View File

@@ -277,7 +277,7 @@ async_echo(AsyncStream& stream, CompletionToken&& token)
BOOST_ASIO_HANDLER_TYPE(
CompletionToken, void(boost::beast::error_code))>{
stream,
init.completion_handler}(boost::beast::error_code{}, 0);
std::move(init.completion_handler)}({}, 0);
// This hook lets the caller see a return value when appropriate.
// For example this might return std::future<error_code> if
@@ -289,6 +289,18 @@ async_echo(AsyncStream& stream, CompletionToken&& token)
//]
struct move_only_handler
{
move_only_handler(move_only_handler&&) = default;
move_only_handler(move_only_handler const&) = delete;
void operator()(boost::beast::error_code ec)
{
if(ec)
std::cerr << ": " << ec.message() << std::endl;
}
};
int main(int argc, char** argv)
{
if(argc != 3)
@@ -317,12 +329,7 @@ int main(int argc, char** argv)
acceptor.bind(ep);
acceptor.listen();
acceptor.accept(sock);
async_echo(sock,
[&](boost::beast::error_code ec)
{
if(ec)
std::cerr << argv[0] << ": " << ec.message() << std::endl;
});
async_echo(sock, move_only_handler{});
ioc.run();
return EXIT_SUCCESS;
}