Add async_result support to post() and dispatch() functions.
diff --git a/asio/include/asio/detail/handler_type_requirements.hpp b/asio/include/asio/detail/handler_type_requirements.hpp index da090e8..22f7cb1 100644 --- a/asio/include/asio/detail/handler_type_requirements.hpp +++ b/asio/include/asio/detail/handler_type_requirements.hpp
@@ -113,17 +113,23 @@ #define ASIO_COMPLETION_HANDLER_CHECK( \ handler_type, handler) \ \ + typedef ASIO_HANDLER_TYPE(handler_type, \ + void()) asio_true_handler_type; \ + \ ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(asio::detail::zero_arg_handler_test( \ - handler, 0)) == 1, \ + asio::detail::clvref< \ + asio_true_handler_type>(), 0)) == 1, \ "CompletionHandler type requirements not met") \ \ typedef asio::detail::handler_type_requirements< \ sizeof( \ asio::detail::argbyv( \ - asio::detail::clvref(handler))) + \ + asio::detail::clvref< \ + asio_true_handler_type>())) + \ sizeof( \ - asio::detail::lvref(handler)(), \ + asio::detail::lvref< \ + asio_true_handler_type>()(), \ char(0))> #define ASIO_READ_HANDLER_CHECK( \
diff --git a/asio/include/asio/detail/impl/strand_service.hpp b/asio/include/asio/detail/impl/strand_service.hpp index 3b7ee23..3309518 100644 --- a/asio/include/asio/detail/impl/strand_service.hpp +++ b/asio/include/asio/detail/impl/strand_service.hpp
@@ -51,7 +51,7 @@ template <typename Handler> void strand_service::dispatch(strand_service::implementation_type& impl, - Handler handler) + Handler& handler) { // If we are already in the strand then the handler can run immediately. if (call_stack<strand_impl>::contains(impl)) @@ -91,7 +91,7 @@ // Request the io_service to invoke the given handler and return immediately. template <typename Handler> void strand_service::post(strand_service::implementation_type& impl, - Handler handler) + Handler& handler) { // Allocate and construct an operation to wrap the handler. typedef completion_handler<Handler> op;
diff --git a/asio/include/asio/detail/impl/task_io_service.hpp b/asio/include/asio/detail/impl/task_io_service.hpp index 03dc28d..1aca665 100644 --- a/asio/include/asio/detail/impl/task_io_service.hpp +++ b/asio/include/asio/detail/impl/task_io_service.hpp
@@ -26,7 +26,7 @@ namespace detail { template <typename Handler> -void task_io_service::dispatch(Handler handler) +void task_io_service::dispatch(Handler& handler) { if (thread_call_stack::contains(this)) { @@ -50,7 +50,7 @@ } template <typename Handler> -void task_io_service::post(Handler handler) +void task_io_service::post(Handler& handler) { // Allocate and construct an operation to wrap the handler. typedef completion_handler<Handler> op;
diff --git a/asio/include/asio/detail/impl/win_iocp_io_service.hpp b/asio/include/asio/detail/impl/win_iocp_io_service.hpp index 0fe7df6..1166baf 100644 --- a/asio/include/asio/detail/impl/win_iocp_io_service.hpp +++ b/asio/include/asio/detail/impl/win_iocp_io_service.hpp
@@ -30,7 +30,7 @@ namespace detail { template <typename Handler> -void win_iocp_io_service::dispatch(Handler handler) +void win_iocp_io_service::dispatch(Handler& handler) { if (thread_call_stack::contains(this)) { @@ -54,7 +54,7 @@ } template <typename Handler> -void win_iocp_io_service::post(Handler handler) +void win_iocp_io_service::post(Handler& handler) { // Allocate and construct an operation to wrap the handler. typedef completion_handler<Handler> op;
diff --git a/asio/include/asio/detail/strand_service.hpp b/asio/include/asio/detail/strand_service.hpp index 53b334c..313f5d7 100644 --- a/asio/include/asio/detail/strand_service.hpp +++ b/asio/include/asio/detail/strand_service.hpp
@@ -85,11 +85,11 @@ // Request the io_service to invoke the given handler. template <typename Handler> - void dispatch(implementation_type& impl, Handler handler); + void dispatch(implementation_type& impl, Handler& handler); // Request the io_service to invoke the given handler and return immediately. template <typename Handler> - void post(implementation_type& impl, Handler handler); + void post(implementation_type& impl, Handler& handler); private: // Helper function to dispatch a handler. Returns true if the handler should
diff --git a/asio/include/asio/detail/task_io_service.hpp b/asio/include/asio/detail/task_io_service.hpp index a6caecb..51473ca 100644 --- a/asio/include/asio/detail/task_io_service.hpp +++ b/asio/include/asio/detail/task_io_service.hpp
@@ -93,11 +93,11 @@ // Request invocation of the given handler. template <typename Handler> - void dispatch(Handler handler); + void dispatch(Handler& handler); // Request invocation of the given handler and return immediately. template <typename Handler> - void post(Handler handler); + void post(Handler& handler); // Request invocation of the given operation and return immediately. Assumes // that work_started() has not yet been called for the operation.
diff --git a/asio/include/asio/detail/win_iocp_io_service.hpp b/asio/include/asio/detail/win_iocp_io_service.hpp index 0a0a609..9907ec0 100644 --- a/asio/include/asio/detail/win_iocp_io_service.hpp +++ b/asio/include/asio/detail/win_iocp_io_service.hpp
@@ -112,11 +112,11 @@ // Request invocation of the given handler. template <typename Handler> - void dispatch(Handler handler); + void dispatch(Handler& handler); // Request invocation of the given handler and return immediately. template <typename Handler> - void post(Handler handler); + void post(Handler& handler); // Request invocation of the given operation and return immediately. Assumes // that work_started() has not yet been called for the operation.
diff --git a/asio/include/asio/impl/io_service.hpp b/asio/include/asio/impl/io_service.hpp index 2a6b4c4..06d443f 100644 --- a/asio/include/asio/impl/io_service.hpp +++ b/asio/include/asio/impl/io_service.hpp
@@ -74,24 +74,37 @@ namespace asio { template <typename CompletionHandler> -inline void io_service::dispatch( - ASIO_MOVE_ARG(CompletionHandler) handler) +inline ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) +io_service::dispatch(ASIO_MOVE_ARG(CompletionHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a CompletionHandler. ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - impl_.dispatch(ASIO_MOVE_CAST(CompletionHandler)(handler)); + detail::async_result_init< + CompletionHandler, void ()> init( + ASIO_MOVE_CAST(CompletionHandler)(handler)); + + impl_.dispatch(init.handler); + + return init.result.get(); } template <typename CompletionHandler> -inline void io_service::post(ASIO_MOVE_ARG(CompletionHandler) handler) +inline ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) +io_service::post(ASIO_MOVE_ARG(CompletionHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a CompletionHandler. ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - impl_.post(ASIO_MOVE_CAST(CompletionHandler)(handler)); + detail::async_result_init< + CompletionHandler, void ()> init( + ASIO_MOVE_CAST(CompletionHandler)(handler)); + + impl_.post(init.handler); + + return init.result.get(); } template <typename Handler>
diff --git a/asio/include/asio/io_service.hpp b/asio/include/asio/io_service.hpp index 668e8e2..4a1f1e8 100644 --- a/asio/include/asio/io_service.hpp +++ b/asio/include/asio/io_service.hpp
@@ -19,6 +19,7 @@ #include <cstddef> #include <stdexcept> #include <typeinfo> +#include "asio/async_result.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/service_registry_fwd.hpp" #include "asio/detail/wrapped_handler.hpp" @@ -440,7 +441,8 @@ * throws an exception. */ template <typename CompletionHandler> - void dispatch(ASIO_MOVE_ARG(CompletionHandler) handler); + ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) + dispatch(ASIO_MOVE_ARG(CompletionHandler) handler); /// Request the io_service to invoke the given handler and return immediately. /** @@ -465,7 +467,8 @@ * throws an exception. */ template <typename CompletionHandler> - void post(ASIO_MOVE_ARG(CompletionHandler) handler); + ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) + post(ASIO_MOVE_ARG(CompletionHandler) handler); /// Create a new handler that automatically dispatches the wrapped handler /// on the io_service.
diff --git a/asio/include/asio/strand.hpp b/asio/include/asio/strand.hpp index 8324b14..8b43085 100644 --- a/asio/include/asio/strand.hpp +++ b/asio/include/asio/strand.hpp
@@ -16,6 +16,7 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" +#include "asio/async_result.hpp" #include "asio/detail/handler_type_requirements.hpp" #include "asio/detail/strand_service.hpp" #include "asio/detail/wrapped_handler.hpp" @@ -139,13 +140,20 @@ * @code void handler(); @endcode */ template <typename CompletionHandler> - void dispatch(ASIO_MOVE_ARG(CompletionHandler) handler) + ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) + dispatch(ASIO_MOVE_ARG(CompletionHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a CompletionHandler. ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - service_.dispatch(impl_, ASIO_MOVE_CAST(CompletionHandler)(handler)); + detail::async_result_init< + CompletionHandler, void ()> init( + ASIO_MOVE_CAST(CompletionHandler)(handler)); + + service_.dispatch(impl_, init.handler); + + return init.result.get(); } /// Request the strand to invoke the given handler and return @@ -165,13 +173,20 @@ * @code void handler(); @endcode */ template <typename CompletionHandler> - void post(ASIO_MOVE_ARG(CompletionHandler) handler) + ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) + post(ASIO_MOVE_ARG(CompletionHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a CompletionHandler. ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; - service_.post(impl_, ASIO_MOVE_CAST(CompletionHandler)(handler)); + detail::async_result_init< + CompletionHandler, void ()> init( + ASIO_MOVE_CAST(CompletionHandler)(handler)); + + service_.post(impl_, init.handler); + + return init.result.get(); } /// Create a new handler that automatically dispatches the wrapped handler