From d25fa4e5dd21ed81427934d6192ceb3a8805b02a Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Wed, 1 Oct 2014 20:58:51 +1000 Subject: [PATCH] Enable move-only handlers. All async operations and executor operations support move-only handlers. However, the io_service::post(), io_service::dispatch(), io_service::strand::post() and io_service::strand::dispatch() functions still require copyable handlers. --- asio/include/asio/basic_socket.hpp | 3 +- asio/include/asio/detail/bind_handler.hpp | 435 ++---------------- .../asio/detail/handler_type_requirements.hpp | 62 +-- asio/include/asio/detail/work_dispatcher.hpp | 15 + .../asio/impl/buffered_read_stream.hpp | 2 +- .../asio/impl/buffered_write_stream.hpp | 4 +- .../tests/unit/archetypes/async_result.hpp | 6 + asio/src/tests/unit/ip/icmp.cpp | 91 ++-- asio/src/tests/unit/ip/tcp.cpp | 139 ++++-- asio/src/tests/unit/ip/udp.cpp | 106 +++-- asio/src/tests/unit/read.cpp | 15 +- asio/src/tests/unit/read_at.cpp | 15 +- asio/src/tests/unit/read_until.cpp | 15 +- asio/src/tests/unit/serial_port.cpp | 28 +- asio/src/tests/unit/system_timer.cpp | 17 +- asio/src/tests/unit/write.cpp | 15 +- asio/src/tests/unit/write_at.cpp | 15 +- 17 files changed, 398 insertions(+), 585 deletions(-) diff --git a/asio/include/asio/basic_socket.hpp b/asio/include/asio/basic_socket.hpp index c2b50e94..3b6cebea 100644 --- a/asio/include/asio/basic_socket.hpp +++ b/asio/include/asio/basic_socket.hpp @@ -22,6 +22,7 @@ #include "asio/detail/throw_error.hpp" #include "asio/detail/type_traits.hpp" #include "asio/error.hpp" +#include "asio/post.hpp" #include "asio/socket_base.hpp" #include "asio/detail/push_options.hpp" @@ -747,7 +748,7 @@ public: async_completion init(handler); - this->get_service().get_io_service().post( + asio::post(this->get_executor(), asio::detail::bind_handler( ASIO_MOVE_CAST(ASIO_HANDLER_TYPE( ConnectHandler, void (asio::error_code)))( diff --git a/asio/include/asio/detail/bind_handler.hpp b/asio/include/asio/detail/bind_handler.hpp index 1747777b..0148eec2 100644 --- a/asio/include/asio/detail/bind_handler.hpp +++ b/asio/include/asio/detail/bind_handler.hpp @@ -31,8 +31,8 @@ template class binder1 { public: - binder1(const Handler& handler, const Arg1& arg1) - : handler_(handler), + binder1(int, ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1) + : handler_(ASIO_MOVE_CAST(Handler)(handler)), arg1_(arg1) { } @@ -43,6 +43,20 @@ public: { } +#if defined(ASIO_HAS_MOVE) + binder1(const binder1& other) + : handler_(other.handler_), + arg1_(other.arg1_) + { + } + + binder1(binder1&& other) + : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)), + arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)) + { + } +#endif // defined(ASIO_HAS_MOVE) + void operator()() { handler_(static_cast(arg1_)); @@ -99,18 +113,20 @@ inline void asio_handler_invoke(const Function& function, } template -inline binder1 bind_handler(Handler handler, - const Arg1& arg1) +inline binder1 bind_handler( + ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1) { - return binder1(handler, arg1); + return binder1(0, + ASIO_MOVE_CAST(Handler)(handler), arg1); } template class binder2 { public: - binder2(const Handler& handler, const Arg1& arg1, const Arg2& arg2) - : handler_(handler), + binder2(int, ASIO_MOVE_ARG(Handler) handler, + const Arg1& arg1, const Arg2& arg2) + : handler_(ASIO_MOVE_CAST(Handler)(handler)), arg1_(arg1), arg2_(arg2) { @@ -123,6 +139,22 @@ public: { } +#if defined(ASIO_HAS_MOVE) + binder2(const binder2& other) + : handler_(other.handler_), + arg1_(other.arg1_), + arg2_(other.arg2_) + { + } + + binder2(binder2&& other) + : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)), + arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)), + arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)) + { + } +#endif // defined(ASIO_HAS_MOVE) + void operator()() { handler_(static_cast(arg1_), @@ -181,306 +213,11 @@ inline void asio_handler_invoke(const Function& function, } template -inline binder2 bind_handler(Handler handler, - const Arg1& arg1, const Arg2& arg2) +inline binder2 bind_handler( + ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1, const Arg2& arg2) { - return binder2(handler, arg1, arg2); -} - -template -class binder3 -{ -public: - binder3(const Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3) - : handler_(handler), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3) - { - } - - binder3(Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3) - : handler_(ASIO_MOVE_CAST(Handler)(handler)), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3) - { - } - - void operator()() - { - handler_(static_cast(arg1_), - static_cast(arg2_), - static_cast(arg3_)); - } - - void operator()() const - { - handler_(arg1_, arg2_, arg3_); - } - -//private: - Handler handler_; - Arg1 arg1_; - Arg2 arg2_; - Arg3 arg3_; -}; - -template -inline void* asio_handler_allocate(std::size_t size, - binder3* this_handler) -{ - return asio_handler_alloc_helpers::allocate( - size, this_handler->handler_); -} - -template -inline void asio_handler_deallocate(void* pointer, std::size_t size, - binder3* this_handler) -{ - asio_handler_alloc_helpers::deallocate( - pointer, size, this_handler->handler_); -} - -template -inline bool asio_handler_is_continuation( - binder3* this_handler) -{ - return asio_handler_cont_helpers::is_continuation( - this_handler->handler_); -} - -template -inline void asio_handler_invoke(Function& function, - binder3* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline void asio_handler_invoke(const Function& function, - binder3* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline binder3 bind_handler(Handler handler, - const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) -{ - return binder3(handler, arg1, arg2, arg3); -} - -template -class binder4 -{ -public: - binder4(const Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4) - : handler_(handler), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3), - arg4_(arg4) - { - } - - binder4(Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4) - : handler_(ASIO_MOVE_CAST(Handler)(handler)), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3), - arg4_(arg4) - { - } - - void operator()() - { - handler_(static_cast(arg1_), - static_cast(arg2_), - static_cast(arg3_), - static_cast(arg4_)); - } - - void operator()() const - { - handler_(arg1_, arg2_, arg3_, arg4_); - } - -//private: - Handler handler_; - Arg1 arg1_; - Arg2 arg2_; - Arg3 arg3_; - Arg4 arg4_; -}; - -template -inline void* asio_handler_allocate(std::size_t size, - binder4* this_handler) -{ - return asio_handler_alloc_helpers::allocate( - size, this_handler->handler_); -} - -template -inline void asio_handler_deallocate(void* pointer, std::size_t size, - binder4* this_handler) -{ - asio_handler_alloc_helpers::deallocate( - pointer, size, this_handler->handler_); -} - -template -inline bool asio_handler_is_continuation( - binder4* this_handler) -{ - return asio_handler_cont_helpers::is_continuation( - this_handler->handler_); -} - -template -inline void asio_handler_invoke(Function& function, - binder4* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline void asio_handler_invoke(const Function& function, - binder4* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline binder4 bind_handler( - Handler handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4) -{ - return binder4(handler, arg1, arg2, arg3, - arg4); -} - -template -class binder5 -{ -public: - binder5(const Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) - : handler_(handler), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3), - arg4_(arg4), - arg5_(arg5) - { - } - - binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) - : handler_(ASIO_MOVE_CAST(Handler)(handler)), - arg1_(arg1), - arg2_(arg2), - arg3_(arg3), - arg4_(arg4), - arg5_(arg5) - { - } - - void operator()() - { - handler_(static_cast(arg1_), - static_cast(arg2_), - static_cast(arg3_), - static_cast(arg4_), - static_cast(arg5_)); - } - - void operator()() const - { - handler_(arg1_, arg2_, arg3_, arg4_, arg5_); - } - -//private: - Handler handler_; - Arg1 arg1_; - Arg2 arg2_; - Arg3 arg3_; - Arg4 arg4_; - Arg5 arg5_; -}; - -template -inline void* asio_handler_allocate(std::size_t size, - binder5* this_handler) -{ - return asio_handler_alloc_helpers::allocate( - size, this_handler->handler_); -} - -template -inline void asio_handler_deallocate(void* pointer, std::size_t size, - binder5* this_handler) -{ - asio_handler_alloc_helpers::deallocate( - pointer, size, this_handler->handler_); -} - -template -inline bool asio_handler_is_continuation( - binder5* this_handler) -{ - return asio_handler_cont_helpers::is_continuation( - this_handler->handler_); -} - -template -inline void asio_handler_invoke(Function& function, - binder5* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline void asio_handler_invoke(const Function& function, - binder5* this_handler) -{ - asio_handler_invoke_helpers::invoke( - function, this_handler->handler_); -} - -template -inline binder5 bind_handler( - Handler handler, const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) -{ - return binder5(handler, arg1, arg2, - arg3, arg4, arg5); + return binder2(0, + ASIO_MOVE_CAST(Handler)(handler), arg1, arg2); } } // namespace detail @@ -509,49 +246,6 @@ struct associated_allocator, Allocator> } }; -template -struct associated_allocator, - Allocator> -{ - typedef typename associated_allocator::type type; - - static type get(const detail::binder3& h, - const Allocator& a = Allocator()) ASIO_NOEXCEPT - { - return associated_allocator::get(h.handler_, a); - } -}; - -template -struct associated_allocator, - Allocator> -{ - typedef typename associated_allocator::type type; - - static type get(const detail::binder4& h, - const Allocator& a = Allocator()) ASIO_NOEXCEPT - { - return associated_allocator::get(h.handler_, a); - } -}; - -template -struct associated_allocator< - detail::binder5, Allocator> -{ - typedef typename associated_allocator::type type; - - static type get( - const detail::binder5& h, - const Allocator& a = Allocator()) ASIO_NOEXCEPT - { - return associated_allocator::get(h.handler_, a); - } -}; - template struct associated_executor, Executor> { @@ -576,49 +270,6 @@ struct associated_executor, Executor> } }; -template -struct associated_executor, - Executor> -{ - typedef typename associated_executor::type type; - - static type get(const detail::binder3& h, - const Executor& ex = Executor()) ASIO_NOEXCEPT - { - return associated_executor::get(h.handler_, ex); - } -}; - -template -struct associated_executor, - Executor> -{ - typedef typename associated_executor::type type; - - static type get(const detail::binder4& h, - const Executor& ex = Executor()) ASIO_NOEXCEPT - { - return associated_executor::get(h.handler_, ex); - } -}; - -template -struct associated_executor< - detail::binder5, Executor> -{ - typedef typename associated_executor::type type; - - static type get( - const detail::binder5& h, - const Executor& ex = Executor()) ASIO_NOEXCEPT - { - return associated_executor::get(h.handler_, ex); - } -}; - } // namespace asio #include "asio/detail/pop_options.hpp" diff --git a/asio/include/asio/detail/handler_type_requirements.hpp b/asio/include/asio/detail/handler_type_requirements.hpp index fdf3a55d..319bb83f 100644 --- a/asio/include/asio/detail/handler_type_requirements.hpp +++ b/asio/include/asio/detail/handler_type_requirements.hpp @@ -71,19 +71,19 @@ namespace detail { # if defined(ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT) template -auto zero_arg_handler_test(Handler h, void*) +auto zero_arg_copyable_handler_test(Handler h, void*) -> decltype( sizeof(Handler(static_cast(h))), ((h)()), char(0)); template -char (&zero_arg_handler_test(Handler, ...))[2]; +char (&zero_arg_copyable_handler_test(Handler, ...))[2]; template auto one_arg_handler_test(Handler h, Arg1* a1) -> decltype( - sizeof(Handler(static_cast(h))), + sizeof(Handler(ASIO_MOVE_CAST(Handler)(h))), ((h)(*a1)), char(0)); @@ -93,7 +93,7 @@ char (&one_arg_handler_test(Handler h, ...))[2]; template auto two_arg_handler_test(Handler h, Arg1* a1, Arg2* a2) -> decltype( - sizeof(Handler(static_cast(h))), + sizeof(Handler(ASIO_MOVE_CAST(Handler)(h))), ((h)(*a1, *a2)), char(0)); @@ -113,6 +113,13 @@ template T& lvref(); template T& lvref(T); template const T& clvref(); template const T& clvref(T); +#if defined(ASIO_HAS_MOVE) +template T rvref(); +template T rvref(T); +#else // defined(ASIO_HAS_MOVE) +template const T& rvref(); +template const T& rvref(T); +#endif // defined(ASIO_HAS_MOVE) template char argbyv(T); template @@ -127,7 +134,7 @@ struct handler_type_requirements void()) asio_true_handler_type; \ \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ - sizeof(asio::detail::zero_arg_handler_test( \ + sizeof(asio::detail::zero_arg_copyable_handler_test( \ asio::detail::clvref< \ asio_true_handler_type>(), 0)) == 1, \ "CompletionHandler type requirements not met") \ @@ -151,7 +158,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -160,7 +167,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -169,7 +176,6 @@ struct handler_type_requirements asio::detail::lvref()), \ char(0))> ASIO_UNUSED_TYPEDEF - #define ASIO_WRITE_HANDLER_CHECK( \ handler_type, handler) \ \ @@ -179,7 +185,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -188,7 +194,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -206,7 +212,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::one_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0))) == 1, \ "AcceptHandler type requirements not met") \ @@ -214,7 +220,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -231,7 +237,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::one_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0))) == 1, \ "ConnectHandler type requirements not met") \ @@ -239,7 +245,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -256,7 +262,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -265,7 +271,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -283,7 +289,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -292,7 +298,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -310,7 +316,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::one_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0))) == 1, \ "WaitHandler type requirements not met") \ @@ -318,7 +324,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -335,7 +341,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -344,7 +350,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -362,7 +368,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::one_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0))) == 1, \ "HandshakeHandler type requirements not met") \ @@ -370,7 +376,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -387,7 +393,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::two_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0), \ static_cast(0))) == 1, \ @@ -396,7 +402,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ @@ -414,7 +420,7 @@ struct handler_type_requirements \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::one_arg_handler_test( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast(0))) == 1, \ "ShutdownHandler type requirements not met") \ @@ -422,7 +428,7 @@ struct handler_type_requirements typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref< \ + asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ asio::detail::lvref< \ diff --git a/asio/include/asio/detail/work_dispatcher.hpp b/asio/include/asio/detail/work_dispatcher.hpp index 3ee4797d..c4124b9c 100644 --- a/asio/include/asio/detail/work_dispatcher.hpp +++ b/asio/include/asio/detail/work_dispatcher.hpp @@ -35,6 +35,21 @@ public: { } +#if defined(ASIO_HAS_MOVE) + work_dispatcher(const work_dispatcher& other) + : work_(other.work_), + handler_(other.handler_) + { + } + + work_dispatcher(work_dispatcher&& other) + : work_(ASIO_MOVE_CAST(executor_work< + typename associated_executor::type>)(other.work_)), + handler_(ASIO_MOVE_CAST(Handler)(other.handler_)) + { + } +#endif // defined(ASIO_HAS_MOVE) + void operator()() { typename associated_executor::type ex(work_.get_executor()); diff --git a/asio/include/asio/impl/buffered_read_stream.hpp b/asio/include/asio/impl/buffered_read_stream.hpp index 6ba81e3e..444d4552 100644 --- a/asio/include/asio/impl/buffered_read_stream.hpp +++ b/asio/include/asio/impl/buffered_read_stream.hpp @@ -232,7 +232,7 @@ namespace detail const MutableBufferSequence& buffers, ReadHandler& handler) : storage_(storage), buffers_(buffers), - handler_(handler) + handler_(ASIO_MOVE_CAST(ReadHandler)(handler)) { } diff --git a/asio/include/asio/impl/buffered_write_stream.hpp b/asio/include/asio/impl/buffered_write_stream.hpp index 43e7c285..ff36d01e 100644 --- a/asio/include/asio/impl/buffered_write_stream.hpp +++ b/asio/include/asio/impl/buffered_write_stream.hpp @@ -54,7 +54,7 @@ namespace detail buffered_flush_handler(detail::buffered_stream_storage& storage, WriteHandler& handler) : storage_(storage), - handler_(handler) + handler_(ASIO_MOVE_CAST(WriteHandler)(handler)) { } @@ -213,7 +213,7 @@ namespace detail const ConstBufferSequence& buffers, WriteHandler& handler) : storage_(storage), buffers_(buffers), - handler_(handler) + handler_(ASIO_MOVE_CAST(WriteHandler)(handler)) { } diff --git a/asio/src/tests/unit/archetypes/async_result.hpp b/asio/src/tests/unit/archetypes/async_result.hpp index 21169b14..3fefca48 100644 --- a/asio/src/tests/unit/archetypes/async_result.hpp +++ b/asio/src/tests/unit/archetypes/async_result.hpp @@ -35,6 +35,12 @@ struct concrete_handler void operator()(Arg1, Arg2) { } + +#if defined(ASIO_HAS_MOVE) + concrete_handler(concrete_handler&&) {} +private: + concrete_handler(const concrete_handler&); +#endif // defined(ASIO_HAS_MOVE) }; } // namespace archetypes diff --git a/asio/src/tests/unit/ip/icmp.cpp b/asio/src/tests/unit/ip/icmp.cpp index b903a292..ab2a8bf4 100644 --- a/asio/src/tests/unit/ip/icmp.cpp +++ b/asio/src/tests/unit/ip/icmp.cpp @@ -28,23 +28,44 @@ //------------------------------------------------------------------------------ // ip_icmp_socket_compile test -// ~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::icmp::socket compile and link correctly. Runtime failures are ignored. namespace ip_icmp_socket_compile { -void connect_handler(const asio::error_code&) +struct connect_handler { -} + connect_handler() {} + void operator()(const asio::error_code&) {} +#if defined(ASIO_HAS_MOVE) + connect_handler(connect_handler&&) {} +private: + connect_handler(const connect_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void send_handler(const asio::error_code&, std::size_t) +struct send_handler { -} + send_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + send_handler(send_handler&&) {} +private: + send_handler(const send_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void receive_handler(const asio::error_code&, std::size_t) +struct receive_handler { -} + receive_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + receive_handler(receive_handler&&) {} +private: + receive_handler(const receive_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -151,9 +172,9 @@ void test() socket1.connect(ip::icmp::endpoint(ip::icmp::v6(), 0), ec); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), - &connect_handler); + connect_handler()); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), - &connect_handler); + connect_handler()); int i1 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), lazy); @@ -207,12 +228,12 @@ void test() socket1.send(buffer(const_char_buffer), in_flags, ec); socket1.send(null_buffers(), in_flags, ec); - socket1.async_send(buffer(mutable_char_buffer), &send_handler); - socket1.async_send(buffer(const_char_buffer), &send_handler); - socket1.async_send(null_buffers(), &send_handler); - socket1.async_send(buffer(mutable_char_buffer), in_flags, &send_handler); - socket1.async_send(buffer(const_char_buffer), in_flags, &send_handler); - socket1.async_send(null_buffers(), in_flags, &send_handler); + socket1.async_send(buffer(mutable_char_buffer), send_handler()); + socket1.async_send(buffer(const_char_buffer), send_handler()); + socket1.async_send(null_buffers(), send_handler()); + socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); + socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); + socket1.async_send(null_buffers(), in_flags, send_handler()); int i3 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i3; int i4 = socket1.async_send(buffer(const_char_buffer), lazy); @@ -264,29 +285,29 @@ void test() ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec); socket1.async_send_to(buffer(mutable_char_buffer), - ip::icmp::endpoint(ip::icmp::v4(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::icmp::endpoint(ip::icmp::v6(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::icmp::endpoint(ip::icmp::v4(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::icmp::endpoint(ip::icmp::v6(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(null_buffers(), - ip::icmp::endpoint(ip::icmp::v4(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(null_buffers(), - ip::icmp::endpoint(ip::icmp::v6(), 0), &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), - ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), - ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, &send_handler); + ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); int i9 = socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i9; @@ -331,11 +352,11 @@ void test() socket1.receive(buffer(mutable_char_buffer), in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); - socket1.async_receive(buffer(mutable_char_buffer), &receive_handler); - socket1.async_receive(null_buffers(), &receive_handler); + socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); + socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, - &receive_handler); - socket1.async_receive(null_buffers(), in_flags, &receive_handler); + receive_handler()); + socket1.async_receive(null_buffers(), in_flags, receive_handler()); int i21 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i21; int i22 = socket1.async_receive(null_buffers(), lazy); @@ -355,13 +376,13 @@ void test() socket1.receive_from(null_buffers(), endpoint, in_flags, ec); socket1.async_receive_from(buffer(mutable_char_buffer), - endpoint, &receive_handler); + endpoint, receive_handler()); socket1.async_receive_from(null_buffers(), - endpoint, &receive_handler); + endpoint, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), - endpoint, in_flags, &receive_handler); + endpoint, in_flags, receive_handler()); socket1.async_receive_from(null_buffers(), - endpoint, in_flags, &receive_handler); + endpoint, in_flags, receive_handler()); int i25 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, lazy); (void)i25; diff --git a/asio/src/tests/unit/ip/tcp.cpp b/asio/src/tests/unit/ip/tcp.cpp index 34ce5096..d5d0ea9c 100644 --- a/asio/src/tests/unit/ip/tcp.cpp +++ b/asio/src/tests/unit/ip/tcp.cpp @@ -137,25 +137,60 @@ void test() namespace ip_tcp_socket_compile { -void connect_handler(const asio::error_code&) +struct connect_handler { -} + connect_handler() {} + void operator()(const asio::error_code&) {} +#if defined(ASIO_HAS_MOVE) + connect_handler(connect_handler&&) {} +private: + connect_handler(const connect_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void send_handler(const asio::error_code&, std::size_t) +struct send_handler { -} + send_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + send_handler(send_handler&&) {} +private: + send_handler(const send_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void receive_handler(const asio::error_code&, std::size_t) +struct receive_handler { -} + receive_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + receive_handler(receive_handler&&) {} +private: + receive_handler(const receive_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void write_some_handler(const asio::error_code&, std::size_t) +struct write_some_handler { -} + write_some_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + write_some_handler(write_some_handler&&) {} +private: + write_some_handler(const write_some_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void read_some_handler(const asio::error_code&, std::size_t) +struct read_some_handler { -} + read_some_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + read_some_handler(read_some_handler&&) {} +private: + read_some_handler(const read_some_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -277,9 +312,9 @@ void test() socket1.connect(ip::tcp::endpoint(ip::tcp::v6(), 0), ec); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v4(), 0), - &connect_handler); + connect_handler()); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v6(), 0), - &connect_handler); + connect_handler()); int i1 = socket1.async_connect(ip::tcp::endpoint(ip::tcp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::tcp::endpoint(ip::tcp::v6(), 0), lazy); @@ -339,16 +374,16 @@ void test() socket1.send(const_buffers, in_flags, ec); socket1.send(null_buffers(), in_flags, ec); - socket1.async_send(buffer(mutable_char_buffer), &send_handler); - socket1.async_send(buffer(const_char_buffer), &send_handler); - socket1.async_send(mutable_buffers, &send_handler); - socket1.async_send(const_buffers, &send_handler); - socket1.async_send(null_buffers(), &send_handler); - socket1.async_send(buffer(mutable_char_buffer), in_flags, &send_handler); - socket1.async_send(buffer(const_char_buffer), in_flags, &send_handler); - socket1.async_send(mutable_buffers, in_flags, &send_handler); - socket1.async_send(const_buffers, in_flags, &send_handler); - socket1.async_send(null_buffers(), in_flags, &send_handler); + socket1.async_send(buffer(mutable_char_buffer), send_handler()); + socket1.async_send(buffer(const_char_buffer), send_handler()); + socket1.async_send(mutable_buffers, send_handler()); + socket1.async_send(const_buffers, send_handler()); + socket1.async_send(null_buffers(), send_handler()); + socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); + socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); + socket1.async_send(mutable_buffers, in_flags, send_handler()); + socket1.async_send(const_buffers, in_flags, send_handler()); + socket1.async_send(null_buffers(), in_flags, send_handler()); int i3 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i3; int i4 = socket1.async_send(buffer(const_char_buffer), lazy); @@ -380,13 +415,13 @@ void test() socket1.receive(mutable_buffers, in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); - socket1.async_receive(buffer(mutable_char_buffer), &receive_handler); - socket1.async_receive(mutable_buffers, &receive_handler); - socket1.async_receive(null_buffers(), &receive_handler); + socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); + socket1.async_receive(mutable_buffers, receive_handler()); + socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, - &receive_handler); - socket1.async_receive(mutable_buffers, in_flags, &receive_handler); - socket1.async_receive(null_buffers(), in_flags, &receive_handler); + receive_handler()); + socket1.async_receive(mutable_buffers, in_flags, receive_handler()); + socket1.async_receive(null_buffers(), in_flags, receive_handler()); int i13 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i13; int i14 = socket1.async_receive(mutable_buffers, lazy); @@ -412,11 +447,11 @@ void test() socket1.write_some(const_buffers, ec); socket1.write_some(null_buffers(), ec); - socket1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); - socket1.async_write_some(buffer(const_char_buffer), &write_some_handler); - socket1.async_write_some(mutable_buffers, &write_some_handler); - socket1.async_write_some(const_buffers, &write_some_handler); - socket1.async_write_some(null_buffers(), &write_some_handler); + socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler()); + socket1.async_write_some(buffer(const_char_buffer), write_some_handler()); + socket1.async_write_some(mutable_buffers, write_some_handler()); + socket1.async_write_some(const_buffers, write_some_handler()); + socket1.async_write_some(null_buffers(), write_some_handler()); int i19 = socket1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i19; int i20 = socket1.async_write_some(buffer(const_char_buffer), lazy); @@ -435,9 +470,9 @@ void test() socket1.read_some(mutable_buffers, ec); socket1.read_some(null_buffers(), ec); - socket1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); - socket1.async_read_some(mutable_buffers, &read_some_handler); - socket1.async_read_some(null_buffers(), &read_some_handler); + socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler()); + socket1.async_read_some(mutable_buffers, read_some_handler()); + socket1.async_read_some(null_buffers(), read_some_handler()); int i24 = socket1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i24; int i25 = socket1.async_read_some(mutable_buffers, lazy); @@ -625,9 +660,16 @@ void test() namespace ip_tcp_acceptor_compile { -void accept_handler(const asio::error_code&) +struct accept_handler { -} + accept_handler() {} + void operator()(const asio::error_code&) {} +#if defined(ASIO_HAS_MOVE) + accept_handler(accept_handler&&) {} +private: + accept_handler(const accept_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -744,8 +786,8 @@ void test() acceptor1.accept(peer_socket, peer_endpoint); acceptor1.accept(peer_socket, peer_endpoint, ec); - acceptor1.async_accept(peer_socket, &accept_handler); - acceptor1.async_accept(peer_socket, peer_endpoint, &accept_handler); + acceptor1.async_accept(peer_socket, accept_handler()); + acceptor1.async_accept(peer_socket, peer_endpoint, accept_handler()); int i1 = acceptor1.async_accept(peer_socket, lazy); (void)i1; int i2 = acceptor1.async_accept(peer_socket, peer_endpoint, lazy); @@ -846,10 +888,17 @@ void test() namespace ip_tcp_resolver_compile { -void resolve_handler(const asio::error_code&, - asio::ip::tcp::resolver::iterator) +struct resolve_handler { -} + resolve_handler() {} + void operator()(const asio::error_code&, + asio::ip::tcp::resolver::iterator) {} +#if defined(ASIO_HAS_MOVE) + resolve_handler(resolve_handler&&) {} +private: + resolve_handler(const resolve_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -889,11 +938,11 @@ void test() ip::tcp::resolver::iterator iter4 = resolver.resolve(e, ec); (void)iter4; - resolver.async_resolve(q, &resolve_handler); + resolver.async_resolve(q, resolve_handler()); int i1 = resolver.async_resolve(q, lazy); (void)i1; - resolver.async_resolve(e, &resolve_handler); + resolver.async_resolve(e, resolve_handler()); int i2 = resolver.async_resolve(e, lazy); (void)i2; } diff --git a/asio/src/tests/unit/ip/udp.cpp b/asio/src/tests/unit/ip/udp.cpp index f8b62e0a..30ac1ddd 100644 --- a/asio/src/tests/unit/ip/udp.cpp +++ b/asio/src/tests/unit/ip/udp.cpp @@ -39,17 +39,38 @@ namespace ip_udp_socket_compile { -void connect_handler(const asio::error_code&) +struct connect_handler { -} + connect_handler() {} + void operator()(const asio::error_code&) {} +#if defined(ASIO_HAS_MOVE) + connect_handler(connect_handler&&) {} +private: + connect_handler(const connect_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void send_handler(const asio::error_code&, std::size_t) +struct send_handler { -} + send_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + send_handler(send_handler&&) {} +private: + send_handler(const send_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void receive_handler(const asio::error_code&, std::size_t) +struct receive_handler { -} + receive_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + receive_handler(receive_handler&&) {} +private: + receive_handler(const receive_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -159,9 +180,9 @@ void test() socket1.connect(ip::udp::endpoint(ip::udp::v6(), 0), ec); socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), - &connect_handler); + connect_handler()); socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), - &connect_handler); + connect_handler()); int i1 = socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), lazy); @@ -215,12 +236,12 @@ void test() socket1.send(buffer(const_char_buffer), in_flags, ec); socket1.send(null_buffers(), in_flags, ec); - socket1.async_send(buffer(mutable_char_buffer), &send_handler); - socket1.async_send(buffer(const_char_buffer), &send_handler); - socket1.async_send(null_buffers(), &send_handler); - socket1.async_send(buffer(mutable_char_buffer), in_flags, &send_handler); - socket1.async_send(buffer(const_char_buffer), in_flags, &send_handler); - socket1.async_send(null_buffers(), in_flags, &send_handler); + socket1.async_send(buffer(mutable_char_buffer), send_handler()); + socket1.async_send(buffer(const_char_buffer), send_handler()); + socket1.async_send(null_buffers(), send_handler()); + socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); + socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); + socket1.async_send(null_buffers(), in_flags, send_handler()); int i3 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i3; int i4 = socket1.async_send(buffer(const_char_buffer), lazy); @@ -272,29 +293,29 @@ void test() ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec); socket1.async_send_to(buffer(mutable_char_buffer), - ip::udp::endpoint(ip::udp::v4(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::udp::endpoint(ip::udp::v6(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::udp::endpoint(ip::udp::v4(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::udp::endpoint(ip::udp::v6(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(null_buffers(), - ip::udp::endpoint(ip::udp::v4(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(null_buffers(), - ip::udp::endpoint(ip::udp::v6(), 0), &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::udp::endpoint(ip::udp::v4(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), - ip::udp::endpoint(ip::udp::v6(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::udp::endpoint(ip::udp::v4(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), - ip::udp::endpoint(ip::udp::v6(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), - ip::udp::endpoint(ip::udp::v4(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), - ip::udp::endpoint(ip::udp::v6(), 0), in_flags, &send_handler); + ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); int i9 = socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i9; @@ -339,11 +360,11 @@ void test() socket1.receive(buffer(mutable_char_buffer), in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); - socket1.async_receive(buffer(mutable_char_buffer), &receive_handler); - socket1.async_receive(null_buffers(), &receive_handler); + socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); + socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, - &receive_handler); - socket1.async_receive(null_buffers(), in_flags, &receive_handler); + receive_handler()); + socket1.async_receive(null_buffers(), in_flags, receive_handler()); int i21 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i21; int i22 = socket1.async_receive(null_buffers(), lazy); @@ -363,13 +384,13 @@ void test() socket1.receive_from(null_buffers(), endpoint, in_flags, ec); socket1.async_receive_from(buffer(mutable_char_buffer), - endpoint, &receive_handler); + endpoint, receive_handler()); socket1.async_receive_from(null_buffers(), - endpoint, &receive_handler); + endpoint, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), - endpoint, in_flags, &receive_handler); + endpoint, in_flags, receive_handler()); socket1.async_receive_from(null_buffers(), - endpoint, in_flags, &receive_handler); + endpoint, in_flags, receive_handler()); int i25 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, lazy); (void)i25; @@ -470,10 +491,17 @@ void test() namespace ip_udp_resolver_compile { -void resolve_handler(const asio::error_code&, - asio::ip::udp::resolver::iterator) +struct resolve_handler { -} + resolve_handler() {} + void operator()(const asio::error_code&, + asio::ip::udp::resolver::iterator) {} +#if defined(ASIO_HAS_MOVE) + resolve_handler(resolve_handler&&) {} +private: + resolve_handler(const resolve_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -513,11 +541,11 @@ void test() ip::udp::resolver::iterator iter4 = resolver.resolve(e, ec); (void)iter4; - resolver.async_resolve(q, &resolve_handler); + resolver.async_resolve(q, resolve_handler()); int i1 = resolver.async_resolve(q, lazy); (void)i1; - resolver.async_resolve(e, &resolve_handler); + resolver.async_resolve(e, resolve_handler()); int i2 = resolver.async_resolve(e, lazy); (void)i2; } diff --git a/asio/src/tests/unit/read.cpp b/asio/src/tests/unit/read.cpp index 027b1ea9..e66c4fe6 100644 --- a/asio/src/tests/unit/read.cpp +++ b/asio/src/tests/unit/read.cpp @@ -20,6 +20,7 @@ #include #include "archetypes/async_result.hpp" #include "asio/io_service.hpp" +#include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" @@ -42,7 +43,7 @@ using namespace std; // For memcmp, memcpy and memset. class test_stream { public: - typedef asio::io_service io_service_type; + typedef asio::io_service::executor_type executor_type; test_stream(asio::io_service& io_service) : io_service_(io_service), @@ -52,9 +53,9 @@ public: { } - io_service_type& get_io_service() + executor_type get_executor() ASIO_NOEXCEPT { - return io_service_; + return io_service_.get_executor(); } void reset(const void* data, size_t length) @@ -117,12 +118,14 @@ public: void async_read_some(const Mutable_Buffers& buffers, Handler handler) { size_t bytes_transferred = read_some(buffers); - io_service_.post(asio::detail::bind_handler( - handler, asio::error_code(), bytes_transferred)); + asio::post(get_executor(), + asio::detail::bind_handler( + ASIO_MOVE_CAST(Handler)(handler), + asio::error_code(), bytes_transferred)); } private: - io_service_type& io_service_; + asio::io_service& io_service_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; diff --git a/asio/src/tests/unit/read_at.cpp b/asio/src/tests/unit/read_at.cpp index a4c8c2a6..b63cd2ea 100644 --- a/asio/src/tests/unit/read_at.cpp +++ b/asio/src/tests/unit/read_at.cpp @@ -19,6 +19,7 @@ #include #include "archetypes/async_result.hpp" #include "asio/io_service.hpp" +#include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" @@ -41,7 +42,7 @@ using namespace std; // For memcmp, memcpy and memset. class test_random_access_device { public: - typedef asio::io_service io_service_type; + typedef asio::io_service::executor_type executor_type; test_random_access_device(asio::io_service& io_service) : io_service_(io_service), @@ -50,9 +51,9 @@ public: { } - io_service_type& get_io_service() + executor_type get_executor() ASIO_NOEXCEPT { - return io_service_; + return io_service_.get_executor(); } void reset(const void* data, size_t length) @@ -120,12 +121,14 @@ public: const Mutable_Buffers& buffers, Handler handler) { size_t bytes_transferred = read_some_at(offset, buffers); - io_service_.post(asio::detail::bind_handler( - handler, asio::error_code(), bytes_transferred)); + asio::post(get_executor(), + asio::detail::bind_handler( + ASIO_MOVE_CAST(Handler)(handler), + asio::error_code(), bytes_transferred)); } private: - io_service_type& io_service_; + asio::io_service& io_service_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; diff --git a/asio/src/tests/unit/read_until.cpp b/asio/src/tests/unit/read_until.cpp index 70a415e0..f270202b 100644 --- a/asio/src/tests/unit/read_until.cpp +++ b/asio/src/tests/unit/read_until.cpp @@ -19,6 +19,7 @@ #include #include "archetypes/async_result.hpp" #include "asio/io_service.hpp" +#include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" @@ -31,7 +32,7 @@ class test_stream { public: - typedef asio::io_service io_service_type; + typedef asio::io_service::executor_type executor_type; test_stream(asio::io_service& io_service) : io_service_(io_service), @@ -41,9 +42,9 @@ public: { } - io_service_type& get_io_service() + executor_type get_executor() ASIO_NOEXCEPT { - return io_service_; + return io_service_.get_executor(); } void reset(const void* data, size_t length) @@ -85,12 +86,14 @@ public: void async_read_some(const Mutable_Buffers& buffers, Handler handler) { size_t bytes_transferred = read_some(buffers); - io_service_.post(asio::detail::bind_handler( - handler, asio::error_code(), bytes_transferred)); + asio::post(get_executor(), + asio::detail::bind_handler( + ASIO_MOVE_CAST(Handler)(handler), + asio::error_code(), bytes_transferred)); } private: - io_service_type& io_service_; + asio::io_service& io_service_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; diff --git a/asio/src/tests/unit/serial_port.cpp b/asio/src/tests/unit/serial_port.cpp index 0e4dd2c6..4fdcd6b4 100644 --- a/asio/src/tests/unit/serial_port.cpp +++ b/asio/src/tests/unit/serial_port.cpp @@ -30,13 +30,27 @@ namespace serial_port_compile { -void write_some_handler(const asio::error_code&, std::size_t) +struct write_some_handler { -} + write_some_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + write_some_handler(write_some_handler&&) {} +private: + write_some_handler(const write_some_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; -void read_some_handler(const asio::error_code&, std::size_t) +struct read_some_handler { -} + read_some_handler() {} + void operator()(const asio::error_code&, std::size_t) {} +#if defined(ASIO_HAS_MOVE) + read_some_handler(read_some_handler&&) {} +private: + read_some_handler(const read_some_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void test() { @@ -118,8 +132,8 @@ void test() port1.write_some(buffer(mutable_char_buffer), ec); port1.write_some(buffer(const_char_buffer), ec); - port1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); - port1.async_write_some(buffer(const_char_buffer), &write_some_handler); + port1.async_write_some(buffer(mutable_char_buffer), write_some_handler()); + port1.async_write_some(buffer(const_char_buffer), write_some_handler()); int i1 = port1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i1; int i2 = port1.async_write_some(buffer(const_char_buffer), lazy); @@ -128,7 +142,7 @@ void test() port1.read_some(buffer(mutable_char_buffer)); port1.read_some(buffer(mutable_char_buffer), ec); - port1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); + port1.async_read_some(buffer(mutable_char_buffer), read_some_handler()); int i3 = port1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i3; } diff --git a/asio/src/tests/unit/system_timer.cpp b/asio/src/tests/unit/system_timer.cpp index 021ee334..605d83ed 100644 --- a/asio/src/tests/unit/system_timer.cpp +++ b/asio/src/tests/unit/system_timer.cpp @@ -233,9 +233,16 @@ void system_timer_test() ASIO_CHECK(expected_end < end || expected_end == end); } -void timer_handler(const asio::error_code&) +struct timer_handler { -} + timer_handler() {} + void operator()(const asio::error_code&) {} +#if defined(ASIO_HAS_MOVE) + timer_handler(timer_handler&&) {} +private: + timer_handler(const timer_handler&); +#endif // defined(ASIO_HAS_MOVE) +}; void system_timer_cancel_test() { @@ -249,10 +256,10 @@ void system_timer_cancel_test() } } timers[50]; - timers[2].t.async_wait(&timer_handler); - timers[41].t.async_wait(&timer_handler); + timers[2].t.async_wait(timer_handler()); + timers[41].t.async_wait(timer_handler()); for (int i = 10; i < 20; ++i) - timers[i].t.async_wait(&timer_handler); + timers[i].t.async_wait(timer_handler()); ASIO_CHECK(timers[2].t.cancel() == 1); ASIO_CHECK(timers[41].t.cancel() == 1); diff --git a/asio/src/tests/unit/write.cpp b/asio/src/tests/unit/write.cpp index 1969019b..c8843a4e 100644 --- a/asio/src/tests/unit/write.cpp +++ b/asio/src/tests/unit/write.cpp @@ -20,6 +20,7 @@ #include #include "archetypes/async_result.hpp" #include "asio/io_service.hpp" +#include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" @@ -42,7 +43,7 @@ using namespace std; // For memcmp, memcpy and memset. class test_stream { public: - typedef asio::io_service io_service_type; + typedef asio::io_service::executor_type executor_type; test_stream(asio::io_service& io_service) : io_service_(io_service), @@ -53,9 +54,9 @@ public: memset(data_, 0, max_length); } - io_service_type& get_io_service() + executor_type get_executor() ASIO_NOEXCEPT { - return io_service_; + return io_service_.get_executor(); } void reset(size_t length = max_length) @@ -117,12 +118,14 @@ public: void async_write_some(const Const_Buffers& buffers, Handler handler) { size_t bytes_transferred = write_some(buffers); - io_service_.post(asio::detail::bind_handler( - handler, asio::error_code(), bytes_transferred)); + asio::post(get_executor(), + asio::detail::bind_handler( + ASIO_MOVE_CAST(Handler)(handler), + asio::error_code(), bytes_transferred)); } private: - io_service_type& io_service_; + asio::io_service& io_service_; enum { max_length = 8192 }; char data_[max_length]; size_t length_; diff --git a/asio/src/tests/unit/write_at.cpp b/asio/src/tests/unit/write_at.cpp index 6ee1ea1f..1f97a395 100644 --- a/asio/src/tests/unit/write_at.cpp +++ b/asio/src/tests/unit/write_at.cpp @@ -19,6 +19,7 @@ #include #include "archetypes/async_result.hpp" #include "asio/io_service.hpp" +#include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" @@ -41,7 +42,7 @@ using namespace std; // For memcmp, memcpy and memset. class test_random_access_device { public: - typedef asio::io_service io_service_type; + typedef asio::io_service::executor_type executor_type; test_random_access_device(asio::io_service& io_service) : io_service_(io_service), @@ -51,9 +52,9 @@ public: memset(data_, 0, max_length); } - io_service_type& get_io_service() + executor_type get_executor() ASIO_NOEXCEPT { - return io_service_; + return io_service_.get_executor(); } void reset() @@ -113,12 +114,14 @@ public: const Const_Buffers& buffers, Handler handler) { size_t bytes_transferred = write_some_at(offset, buffers); - io_service_.post(asio::detail::bind_handler( - handler, asio::error_code(), bytes_transferred)); + asio::post(get_executor(), + asio::detail::bind_handler( + ASIO_MOVE_CAST(Handler)(handler), + asio::error_code(), bytes_transferred)); } private: - io_service_type& io_service_; + asio::io_service& io_service_; enum { max_length = 8192 }; char data_[max_length]; size_t length_;