diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d46800..726a4454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 161: * Don't copy the handler in write_some_op +* Add move-only handler tests -------------------------------------------------------------------------------- diff --git a/include/boost/beast/http/read.hpp b/include/boost/beast/http/read.hpp index 4f159aec..33698762 100644 --- a/include/boost/beast/http/read.hpp +++ b/include/boost/beast/http/read.hpp @@ -731,8 +731,8 @@ read( The object must remain valid at least until the handler is called; ownership is not transferred. - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. + @param handler Invoked when the operation completes. + The handler may be moved or copied as needed. The equivalent function signature of the handler must be: @code void handler( error_code const& error, // result of operation, diff --git a/test/beast/websocket/accept.cpp b/test/beast/websocket/accept.cpp index 18c3cf08..fb513031 100644 --- a/test/beast/websocket/accept.cpp +++ b/test/beast/websocket/accept.cpp @@ -610,10 +610,19 @@ public: ); } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_accept(move_only_handler{}); + } + void run() override { testAccept(); + testMoveOnly(); } }; diff --git a/test/beast/websocket/close.cpp b/test/beast/websocket/close.cpp index bd70e059..7e01489f 100644 --- a/test/beast/websocket/close.cpp +++ b/test/beast/websocket/close.cpp @@ -622,12 +622,21 @@ public: asio_handler_is_continuation(&op); } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_close({}, move_only_handler{}); + } + void run() override { testClose(); testSuspend(); testContHook(); + testMoveOnly(); } }; diff --git a/test/beast/websocket/handshake.cpp b/test/beast/websocket/handshake.cpp index 48ef70af..348a8853 100644 --- a/test/beast/websocket/handshake.cpp +++ b/test/beast/websocket/handshake.cpp @@ -484,6 +484,14 @@ public: "permessage-deflate"); } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_handshake("", "", move_only_handler{}); + } + void run() override { @@ -491,6 +499,7 @@ public: testExtRead(); testExtWrite(); testExtNegotiate(); + testMoveOnly(); } }; diff --git a/test/beast/websocket/ping.cpp b/test/beast/websocket/ping.cpp index 25e0a09f..12b06097 100644 --- a/test/beast/websocket/ping.cpp +++ b/test/beast/websocket/ping.cpp @@ -435,12 +435,21 @@ public: asio_handler_is_continuation(&op); } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_ping({}, move_only_handler{}); + } + void run() override { testPing(); testSuspend(); testContHook(); + testMoveOnly(); } }; diff --git a/test/beast/websocket/read2.cpp b/test/beast/websocket/read2.cpp index 9d12f535..b477486e 100644 --- a/test/beast/websocket/read2.cpp +++ b/test/beast/websocket/read2.cpp @@ -639,6 +639,16 @@ public: } } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_read_some( + boost::asio::mutable_buffer{}, + move_only_handler{}); + } + void run() override { @@ -649,6 +659,7 @@ public: testIssue954(); testIssueBF1(); testIssueBF2(); + testMoveOnly(); } }; diff --git a/test/beast/websocket/test.hpp b/test/beast/websocket/test.hpp index 579c6b5b..c9f16b43 100644 --- a/test/beast/websocket/test.hpp +++ b/test/beast/websocket/test.hpp @@ -42,6 +42,19 @@ public: using ws_type = websocket::stream; + struct move_only_handler + { + move_only_handler() = default; + move_only_handler(move_only_handler&&) = default; + move_only_handler(move_only_handler const&) = delete; + + template + void + operator()(Args&&...) const + { + } + }; + enum class kind { sync, diff --git a/test/beast/websocket/write.cpp b/test/beast/websocket/write.cpp index 6451df68..f5d06b7f 100644 --- a/test/beast/websocket/write.cpp +++ b/test/beast/websocket/write.cpp @@ -631,6 +631,16 @@ public: asio_handler_is_continuation(&op); } + void + testMoveOnly() + { + boost::asio::io_context ioc; + stream ws{ioc}; + ws.async_write_some( + true, boost::asio::const_buffer{}, + move_only_handler{}); + } + void run() override { @@ -639,6 +649,7 @@ public: testAsyncWriteFrame(); testIssue300(); testContHook(); + testMoveOnly(); } };