diff --git a/CHANGELOG.md b/CHANGELOG.md index 71598cef..42e695d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 162: + +* Add asio_handler_invoke overloads for stream algorithms + +-------------------------------------------------------------------------------- + Version 161: * Don't copy the handler in write_some_op diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fc6500d..8785adbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,9 @@ get_filename_component (BOOST_ROOT ../../ ABSOLUTE) # VFALCO I want static but "b2 stage" builds a minimal set which excludes static add_definitions (-DBOOST_ALL_STATIC_LINK=1) -add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) +# Some of the tests use deprecated APIs +#add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) + add_definitions (-DBOOST_ASIO_DISABLE_BOOST_ARRAY=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_BIND=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_DATE_TIME=1) diff --git a/Jamfile b/Jamfile index af4af006..e42f0804 100644 --- a/Jamfile +++ b/Jamfile @@ -86,7 +86,7 @@ project /boost/beast BOOST_ASIO_DISABLE_BOOST_BIND=1 BOOST_ASIO_DISABLE_BOOST_DATE_TIME=1 BOOST_ASIO_DISABLE_BOOST_REGEX=1 - BOOST_ASIO_NO_DEPRECATED=1 + #BOOST_ASIO_NO_DEPRECATED=1 # some tests use deprecated strand BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 msvc:"/bigobj" msvc:_SCL_SECURE_NO_WARNINGS=1 diff --git a/doc/qbk/09_releases.qbk b/doc/qbk/09_releases.qbk index fa23865f..05341101 100644 --- a/doc/qbk/09_releases.qbk +++ b/doc/qbk/09_releases.qbk @@ -116,6 +116,8 @@ to update to the latest Boost release. * ([issue 1043]) Examples clear the HTTP message before reading +* ([issue 1012]) Add asio_handler_invoke overloads for stream algorithms + [*API Changes] * Remove unintended public members of diff --git a/include/boost/beast/core/detail/bind_handler.hpp b/include/boost/beast/core/detail/bind_handler.hpp index c103de92..48046df9 100644 --- a/include/boost/beast/core/detail/bind_handler.hpp +++ b/include/boost/beast/core/detail/bind_handler.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -153,6 +154,14 @@ public: return asio_handler_is_continuation(std::addressof(h->h_)); } + template + friend + void asio_handler_invoke(Function&& f, bound_handler* h) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(h->h_)); + } + template void operator()(Values&&... values) diff --git a/include/boost/beast/core/impl/buffered_read_stream.ipp b/include/boost/beast/core/impl/buffered_read_stream.ipp index 09f76345..1ae76b4d 100644 --- a/include/boost/beast/core/impl/buffered_read_stream.ipp +++ b/include/boost/beast/core/impl/buffered_read_stream.ipp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,14 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template diff --git a/include/boost/beast/http/impl/file_body_win32.ipp b/include/boost/beast/http/impl/file_body_win32.ipp index a0d8e606..627401f5 100644 --- a/include/boost/beast/http/impl/file_body_win32.ipp +++ b/include/boost/beast/http/impl/file_body_win32.ipp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -393,6 +394,14 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, write_some_win32_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template< diff --git a/include/boost/beast/http/impl/read.ipp b/include/boost/beast/http/impl/read.ipp index 4a847a2a..28ff0a3c 100644 --- a/include/boost/beast/http/impl/read.ipp +++ b/include/boost/beast/http/impl/read.ipp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,14 @@ public: asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; templateh_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; templated_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, read_msg_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->d_.handler())); + } }; template #include #include +#include #include #include #include @@ -112,6 +113,14 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, write_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template< @@ -246,6 +255,14 @@ public: asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, write_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template< @@ -360,6 +377,14 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, write_msg_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->d_.handler())); + } }; template #include #include +#include #include #include #include @@ -103,6 +104,14 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, response_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->d_.handler())); + } }; template @@ -203,6 +212,14 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, accept_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->d_.handler())); + } }; template diff --git a/include/boost/beast/websocket/impl/close.ipp b/include/boost/beast/websocket/impl/close.ipp index 052ffe50..7b0e1ff6 100644 --- a/include/boost/beast/websocket/impl/close.ipp +++ b/include/boost/beast/websocket/impl/close.ipp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -107,6 +108,15 @@ public: return op->d_->cont || asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, close_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, + std::addressof(op->d_.handler())); + } }; template diff --git a/include/boost/beast/websocket/impl/handshake.ipp b/include/boost/beast/websocket/impl/handshake.ipp index 644ca5c2..8e33e1a8 100644 --- a/include/boost/beast/websocket/impl/handshake.ipp +++ b/include/boost/beast/websocket/impl/handshake.ipp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,15 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, handshake_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, + std::addressof(op->d_.handler())); + } }; template diff --git a/include/boost/beast/websocket/impl/ping.ipp b/include/boost/beast/websocket/impl/ping.ipp index 07abcedd..c7deb9c3 100644 --- a/include/boost/beast/websocket/impl/ping.ipp +++ b/include/boost/beast/websocket/impl/ping.ipp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,15 @@ public: return asio_handler_is_continuation( std::addressof(op->d_.handler())); } + + template + friend + void asio_handler_invoke(Function&& f, ping_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke( + f, std::addressof(op->d_.handler())); + } }; template diff --git a/include/boost/beast/websocket/impl/read.ipp b/include/boost/beast/websocket/impl/read.ipp index 27c659e6..1dfbd01e 100644 --- a/include/boost/beast/websocket/impl/read.ipp +++ b/include/boost/beast/websocket/impl/read.ipp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,14 @@ public: return op->cont_ || asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template @@ -765,6 +774,14 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template diff --git a/include/boost/beast/websocket/impl/teardown.ipp b/include/boost/beast/websocket/impl/teardown.ipp index f5b572e4..add6b277 100644 --- a/include/boost/beast/websocket/impl/teardown.ipp +++ b/include/boost/beast/websocket/impl/teardown.ipp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,22 @@ public: operator()( error_code ec = {}, std::size_t bytes_transferred = 0); + + friend + bool asio_handler_is_continuation(teardown_tcp_op* op) + { + using boost::asio::asio_handler_is_continuation; + return asio_handler_is_continuation( + std::addressof(op->h_)); + } + + template + friend + void asio_handler_invoke(Function&& f, teardown_tcp_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template diff --git a/include/boost/beast/websocket/impl/write.ipp b/include/boost/beast/websocket/impl/write.ipp index 5d4a9d68..d12f2f9e 100644 --- a/include/boost/beast/websocket/impl/write.ipp +++ b/include/boost/beast/websocket/impl/write.ipp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -207,6 +208,15 @@ public: return op->cont_ || asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, write_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke( + f, std::addressof(op->h_)); + } }; template diff --git a/test/beast/core/bind_handler.cpp b/test/beast/core/bind_handler.cpp index 481ee744..203c4bdb 100644 --- a/test/beast/core/bind_handler.cpp +++ b/test/beast/core/bind_handler.cpp @@ -11,7 +11,10 @@ #include #include +#include #include +#include +#include #include namespace boost { @@ -56,6 +59,28 @@ public: bind_handler(handler{}, ph::_1, ph::_2)(1, "hello"); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + boost::asio::post(ioc.get_executor(), + s.wrap(copyable_handler{})); + } + void run() override { @@ -64,6 +89,7 @@ public: std::placeholders::_1), 42); f(); testPlaceholders(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/core/buffered_read_stream.cpp b/test/beast/core/buffered_read_stream.cpp index 010233ad..bbdbb5a0 100644 --- a/test/beast/core/buffered_read_stream.cpp +++ b/test/beast/core/buffered_read_stream.cpp @@ -15,8 +15,10 @@ #include #include #include +#include #include #include +#include #include namespace boost { @@ -206,6 +208,30 @@ public: BEAST_EXPECT(n < limit); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + buffered_read_stream< + test::stream&, multi_buffer> brs(ts); + brs.async_read_some(boost::asio::mutable_buffer{}, + s.wrap(copyable_handler{})); + } + void run() override { testSpecialMembers(); @@ -214,6 +240,7 @@ public: testRead(yield);}); testAsyncLoop(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/http/read.cpp b/test/beast/http/read.cpp index e2aea0bd..b207ab59 100644 --- a/test/beast/http/read.cpp +++ b/test/beast/http/read.cpp @@ -21,7 +21,8 @@ #include #include #include -#include +#include +#include #include namespace boost { @@ -480,6 +481,47 @@ public: }); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request_parser p; + async_read_some(ts, b, p, s.wrap(copyable_handler{})); + } + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request_parser p; + async_read(ts, b, p, s.wrap(copyable_handler{})); + } + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request m; + async_read(ts, b, m, s.wrap(copyable_handler{})); + } + } + void run() override { @@ -502,6 +544,7 @@ public: testIoService(); testRegression430(); testReadGrind(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index 2b81ff22..f7666ce0 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include @@ -857,6 +859,49 @@ public: ioc.run(); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request m; + request_serializer sr{m}; + async_write_some(ts, sr, s.wrap(copyable_handler{})); + } + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request m; + request_serializer sr{m}; + async_write(ts, sr, s.wrap(copyable_handler{})); + } + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + test::stream ts{ioc}; + flat_buffer b; + request m; + async_write(ts, m, s.wrap(copyable_handler{})); + } + } + void run() override { @@ -878,6 +923,7 @@ public: testWriteStream>(yield); testWriteStream>(yield); }); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/accept.cpp b/test/beast/websocket/accept.cpp index fb513031..9f654595 100644 --- a/test/beast/websocket/accept.cpp +++ b/test/beast/websocket/accept.cpp @@ -12,6 +12,9 @@ #include "test.hpp" +#include +#include + namespace boost { namespace beast { namespace websocket { @@ -618,11 +621,33 @@ public: ws.async_accept(move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + ws.async_accept(s.wrap(copyable_handler{})); + } + void run() override { testAccept(); testMoveOnly(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/close.cpp b/test/beast/websocket/close.cpp index 7e01489f..0e5f26c8 100644 --- a/test/beast/websocket/close.cpp +++ b/test/beast/websocket/close.cpp @@ -12,6 +12,9 @@ #include "test.hpp" +#include +#include + namespace boost { namespace beast { namespace websocket { @@ -630,6 +633,27 @@ public: ws.async_close({}, move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + ws.async_close({}, s.wrap(copyable_handler{})); + } + void run() override { @@ -637,6 +661,7 @@ public: testSuspend(); testContHook(); testMoveOnly(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/handshake.cpp b/test/beast/websocket/handshake.cpp index 348a8853..61a861f7 100644 --- a/test/beast/websocket/handshake.cpp +++ b/test/beast/websocket/handshake.cpp @@ -12,6 +12,9 @@ #include "test.hpp" +#include +#include + namespace boost { namespace beast { namespace websocket { @@ -492,6 +495,27 @@ public: ws.async_handshake("", "", move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + ws.async_handshake("localhost", "/", s.wrap(copyable_handler{})); + } + void run() override { @@ -500,6 +524,7 @@ public: testExtWrite(); testExtNegotiate(); testMoveOnly(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/ping.cpp b/test/beast/websocket/ping.cpp index 12b06097..3ba7d15c 100644 --- a/test/beast/websocket/ping.cpp +++ b/test/beast/websocket/ping.cpp @@ -12,6 +12,9 @@ #include "test.hpp" +#include +#include + namespace boost { namespace beast { namespace websocket { @@ -443,6 +446,27 @@ public: ws.async_ping({}, move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + ws.async_ping({}, s.wrap(copyable_handler{})); + } + void run() override { @@ -450,6 +474,7 @@ public: testSuspend(); testContHook(); testMoveOnly(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/read2.cpp b/test/beast/websocket/read2.cpp index b477486e..fab35569 100644 --- a/test/beast/websocket/read2.cpp +++ b/test/beast/websocket/read2.cpp @@ -12,6 +12,8 @@ #include "test.hpp" +#include +#include #include namespace boost { @@ -649,6 +651,30 @@ public: move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + flat_buffer b; + ws.async_read(b, s.wrap(copyable_handler{})); + } + } + void run() override { @@ -660,6 +686,7 @@ public: testIssueBF1(); testIssueBF2(); testMoveOnly(); + testAsioHandlerInvoke(); } }; diff --git a/test/beast/websocket/write.cpp b/test/beast/websocket/write.cpp index f5d06b7f..f3a31819 100644 --- a/test/beast/websocket/write.cpp +++ b/test/beast/websocket/write.cpp @@ -10,6 +10,9 @@ // Test that header file is self-contained. #include +#include +#include + #include "test.hpp" namespace boost { @@ -641,6 +644,31 @@ public: move_only_handler{}); } + struct copyable_handler + { + template + void + operator()(Args&&...) const + { + } + }; + + void + testAsioHandlerInvoke() + { + // make sure things compile, also can set a + // breakpoint in asio_handler_invoke to make sure + // it is instantiated. + { + boost::asio::io_context ioc; + boost::asio::io_service::strand s{ioc}; + stream ws{ioc}; + flat_buffer b; + ws.async_write(boost::asio::const_buffer{}, + s.wrap(copyable_handler{})); + } + } + void run() override { diff --git a/test/extras/include/boost/beast/test/stream.hpp b/test/extras/include/boost/beast/test/stream.hpp index 8a2730d7..58c0ef43 100644 --- a/test/extras/include/boost/beast/test/stream.hpp +++ b/test/extras/include/boost/beast/test/stream.hpp @@ -432,9 +432,13 @@ read_some(MutableBufferSequence const& buffers, "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(buffer_size(buffers) > 0); if(in_->fc && in_->fc->fail(ec)) return 0; + if(buffer_size(buffers) == 0) + { + ec.clear(); + return 0; + } std::unique_lock lock{in_->m}; BOOST_ASSERT(! in_->op); in_->cv.wait(lock, @@ -478,7 +482,6 @@ async_read_some( "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(buffer_size(buffers) > 0); BOOST_BEAST_HANDLER_INIT( ReadHandler, void(error_code, std::size_t)); if(in_->fc)