diff --git a/.gitignore b/.gitignore index e6c8ff1c2f..4508d6ae15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /*.cpp /*.hpp +*.exe /boost diff --git a/asio/include/asio/detail/config.hpp b/asio/include/asio/detail/config.hpp index 26eecfa4e1..5e197163f4 100644 --- a/asio/include/asio/detail/config.hpp +++ b/asio/include/asio/detail/config.hpp @@ -22,6 +22,7 @@ # define ASIO_DISABLE_BOOST_STATIC_CONSTANT 1 # define ASIO_DISABLE_BOOST_THROW_EXCEPTION 1 # define ASIO_DISABLE_BOOST_WORKAROUND 1 +# define ASIO_DISABLE_BOOST_FUTURE 1 #else // defined(ASIO_STANDALONE) # include # include @@ -732,6 +733,10 @@ # endif // !defined(ASIO_DISABLE_STD_FUTURE) #endif // !defined(ASIO_HAS_STD_FUTURE) +#if !defined(ASIO_HAS_STD_FUTURE) && defined(ASIO_DISABLE_BOOST_FUTURE) +# define ASIO_DISABLE_FUTURE +#endif + // Standard library support for experimental::string_view. #if !defined(ASIO_HAS_STD_STRING_VIEW) # if !defined(ASIO_DISABLE_STD_STRING_VIEW) diff --git a/asio/include/asio/detail/cstddef.hpp b/asio/include/asio/detail/cstddef.hpp index a5092ce53b..fc293ad3e4 100644 --- a/asio/include/asio/detail/cstddef.hpp +++ b/asio/include/asio/detail/cstddef.hpp @@ -22,8 +22,10 @@ namespace asio { #if defined(ASIO_HAS_NULLPTR) using std::nullptr_t; +#define ASIO_NULL nullptr #else // defined(ASIO_HAS_NULLPTR) struct nullptr_t {}; +#define ASIO_NULL NULL #endif // defined(ASIO_HAS_NULLPTR) } // namespace asio diff --git a/asio/include/asio/detail/future.hpp b/asio/include/asio/detail/future.hpp new file mode 100644 index 0000000000..8d6cccbada --- /dev/null +++ b/asio/include/asio/detail/future.hpp @@ -0,0 +1,56 @@ +// +// detail/array.hpp +// ~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_DETAIL_FUTURE_HPP +#define ASIO_DETAIL_FUTURE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/detail/config.hpp" + +#if defined(ASIO_HAS_STD_FUTURE) +# include +# include +#else // defined(ASIO_HAS_STD_FUTURE) +# if defined(BOOST_THREAD_VERSION) && (BOOST_THREAD_VERSION < 3) +# error BOOST_THREAD_VERSION must be defined to at least 3 +# else +# if !defined(BOOST_THREAD_VERSION) +# define BOOST_THREAD_VERSION 3 +# endif +# endif +# define ASIO_USING_BOOST_FUTURE +# include +#endif // defined(ASIO_HAS_STD_FUTURE) + +namespace asio { +namespace detail { + +#if defined(ASIO_HAS_STD_FUTURE) +using std::future; +using std::packaged_task; +using std::promise; +#define ASIO_CURRENT_EXCEPTION std::current_exception() +#define ASIO_MAKE_EXCEPTION_PTR(_ex) std::make_exception_ptr(_ex) +using std::exception_ptr; +#else // defined(ASIO_HAS_STD_FUTURE) +using boost::future; +using boost::packaged_task; +using boost::promise; +#define ASIO_CURRENT_EXCEPTION boost::current_exception() +#define ASIO_MAKE_EXCEPTION_PTR(_ex) boost::copy_exception(_ex) +using boost::exception_ptr; +#endif // defined(ASIO_HAS_STD_FUTURE) +} // namespace detail +} // namespace asio + +#endif // ASIO_DETAIL_FUTURE_HPP diff --git a/asio/include/asio/detail/memory.hpp b/asio/include/asio/detail/memory.hpp index 04bad7e747..be0f718224 100644 --- a/asio/include/asio/detail/memory.hpp +++ b/asio/include/asio/detail/memory.hpp @@ -21,6 +21,7 @@ #if !defined(ASIO_HAS_STD_SHARED_PTR) # include # include +# include #endif // !defined(ASIO_HAS_STD_SHARED_PTR) #if !defined(ASIO_HAS_STD_ADDRESSOF) @@ -33,9 +34,11 @@ namespace detail { #if defined(ASIO_HAS_STD_SHARED_PTR) using std::shared_ptr; using std::weak_ptr; +#define ASIO_ALLOCATE_SHARED std::allocate_shared #else // defined(ASIO_HAS_STD_SHARED_PTR) using boost::shared_ptr; using boost::weak_ptr; +#define ASIO_ALLOCATE_SHARED boost::allocate_shared #endif // defined(ASIO_HAS_STD_SHARED_PTR) #if defined(ASIO_HAS_STD_ADDRESSOF) diff --git a/asio/include/asio/detail/winrt_async_manager.hpp b/asio/include/asio/detail/winrt_async_manager.hpp index 921dfdd627..aca8f1a70c 100644 --- a/asio/include/asio/detail/winrt_async_manager.hpp +++ b/asio/include/asio/detail/winrt_async_manager.hpp @@ -19,7 +19,7 @@ #if defined(ASIO_WINDOWS_RUNTIME) -#include +#include "asio/detail/future.hpp" #include "asio/detail/atomic_count.hpp" #include "asio/detail/winrt_async_op.hpp" #include "asio/error.hpp" @@ -53,7 +53,7 @@ class winrt_async_manager if (--outstanding_ops_ > 0) { // Block until last operation is complete. - std::future f = promise_.get_future(); + future f = promise_.get_future(); f.wait(); } } @@ -64,7 +64,7 @@ class winrt_async_manager using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; - auto promise = std::make_shared>(); + auto promise = std::make_shared>(); auto future = promise->get_future(); action->Completed = ref new AsyncActionCompletedHandler( @@ -96,7 +96,7 @@ class winrt_async_manager using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; - auto promise = std::make_shared>(); + auto promise = std::make_shared>(); auto future = promise->get_future(); operation->Completed = ref new AsyncOperationCompletedHandler( @@ -131,7 +131,7 @@ class winrt_async_manager using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; - auto promise = std::make_shared>(); + auto promise = std::make_shared>(); auto future = promise->get_future(); operation->Completed @@ -281,7 +281,7 @@ class winrt_async_manager atomic_count outstanding_ops_; // Used to keep wait for outstanding operations to complete. - std::promise promise_; + promise promise_; }; } // namespace detail diff --git a/asio/include/asio/detail/winrt_utils.hpp b/asio/include/asio/detail/winrt_utils.hpp index 52f714300a..d9cbf6e893 100644 --- a/asio/include/asio/detail/winrt_utils.hpp +++ b/asio/include/asio/detail/winrt_utils.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include "asio/detail/future.hpp" #include #include #include diff --git a/asio/include/asio/impl/use_future.hpp b/asio/include/asio/impl/use_future.hpp index 94e8af7f6c..5e1b7b6bd8 100644 --- a/asio/include/asio/impl/use_future.hpp +++ b/asio/include/asio/impl/use_future.hpp @@ -16,7 +16,7 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" -#include +#include "asio/detail/future.hpp" #include #include "asio/async_result.hpp" #include "asio/detail/memory.hpp" @@ -33,7 +33,7 @@ namespace detail { #if defined(ASIO_HAS_VARIADIC_TEMPLATES) template -inline void promise_invoke_and_set(std::promise& p, +inline void promise_invoke_and_set(promise& p, F& f, ASIO_MOVE_ARG(Args)... args) { #if !defined(ASIO_NO_EXCEPTIONS) @@ -45,13 +45,13 @@ inline void promise_invoke_and_set(std::promise& p, #if !defined(ASIO_NO_EXCEPTIONS) catch (...) { - p.set_exception(std::current_exception()); + p.set_exception(ASIO_CURRENT_EXCEPTION); } #endif // !defined(ASIO_NO_EXCEPTIONS) } template -inline void promise_invoke_and_set(std::promise& p, +inline void promise_invoke_and_set(promise& p, F& f, ASIO_MOVE_ARG(Args)... args) { #if !defined(ASIO_NO_EXCEPTIONS) @@ -64,7 +64,7 @@ inline void promise_invoke_and_set(std::promise& p, #if !defined(ASIO_NO_EXCEPTIONS) catch (...) { - p.set_exception(std::current_exception()); + p.set_exception(ASIO_CURRENT_EXCEPTION); } #endif // !defined(ASIO_NO_EXCEPTIONS) } @@ -72,7 +72,7 @@ inline void promise_invoke_and_set(std::promise& p, #else // defined(ASIO_HAS_VARIADIC_TEMPLATES) template -inline void promise_invoke_and_set(std::promise& p, F& f) +inline void promise_invoke_and_set(promise& p, F& f) { #if !defined(ASIO_NO_EXCEPTIONS) try @@ -83,13 +83,13 @@ inline void promise_invoke_and_set(std::promise& p, F& f) #if !defined(ASIO_NO_EXCEPTIONS) catch (...) { - p.set_exception(std::current_exception()); + p.set_exception(ASIO_CURRENT_EXCEPTION); } #endif // !defined(ASIO_NO_EXCEPTIONS) } -template -inline void promise_invoke_and_set(std::promise& p, F& f) +template +inline void promise_invoke_and_set(promise& p, F& f) { #if !defined(ASIO_NO_EXCEPTIONS) try @@ -101,7 +101,7 @@ inline void promise_invoke_and_set(std::promise& p, F& f) } catch (...) { - p.set_exception(std::current_exception()); + p.set_exception(ASIO_CURRENT_EXCEPTION); } #endif // !defined(ASIO_NO_EXCEPTIONS) } @@ -110,14 +110,14 @@ inline void promise_invoke_and_set(std::promise& p, F& f) #define ASIO_PRIVATE_PROMISE_INVOKE_DEF(n) \ template \ - inline void promise_invoke_and_set(std::promise& p, \ + inline void promise_invoke_and_set(promise& p, \ F& f, ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ p.set_value(f(ASIO_VARIADIC_MOVE_ARGS(n))); \ } \ \ template \ - inline void promise_invoke_and_set(std::promise& p, \ + inline void promise_invoke_and_set(promise& p, \ F& f, ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ f(ASIO_VARIADIC_MOVE_ARGS(n)); \ @@ -131,7 +131,7 @@ inline void promise_invoke_and_set(std::promise& p, F& f) #define ASIO_PRIVATE_PROMISE_INVOKE_DEF(n) \ template \ - inline void promise_invoke_and_set(std::promise& p, \ + inline void promise_invoke_and_set(promise& p, \ F& f, ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ try \ @@ -140,12 +140,12 @@ inline void promise_invoke_and_set(std::promise& p, F& f) } \ catch (...) \ { \ - p.set_exception(std::current_exception()); \ + p.set_exception(ASIO_CURRENT_EXCEPTION); \ } \ } \ \ template \ - inline void promise_invoke_and_set(std::promise& p, \ + inline void promise_invoke_and_set(promise& p, \ F& f, ASIO_VARIADIC_MOVE_PARAMS(n)) \ { \ try \ @@ -155,7 +155,7 @@ inline void promise_invoke_and_set(std::promise& p, F& f) } \ catch (...) \ { \ - p.set_exception(std::current_exception()); \ + p.set_exception(ASIO_CURRENT_EXCEPTION); \ } \ } \ /**/ @@ -172,7 +172,7 @@ template class promise_invoker { public: - promise_invoker(const shared_ptr >& p, + promise_invoker(const shared_ptr >& p, ASIO_MOVE_ARG(F) f) : p_(p), f_(f) { @@ -189,13 +189,13 @@ class promise_invoker #if !defined(ASIO_NO_EXCEPTIONS) catch (...) { - p_->set_exception(std::current_exception()); + p_->set_exception(ASIO_CURRENT_EXCEPTION); } #endif // !defined(ASIO_NO_EXCEPTIONS) } private: - shared_ptr > p_; + shared_ptr > p_; typename decay::type f_; }; @@ -205,7 +205,7 @@ template class promise_executor { public: - explicit promise_executor(const shared_ptr >& p) + explicit promise_executor(const shared_ptr >& p) : p_(p) { } @@ -251,7 +251,7 @@ class promise_executor } private: - shared_ptr > p_; + shared_ptr > p_; }; // The base class for all completion handlers that create promises. @@ -266,7 +266,7 @@ class promise_creator return executor_type(p_); } - typedef std::future future_type; + typedef future future_type; future_type get_future() { @@ -275,13 +275,19 @@ class promise_creator protected: template - void create_promise(const Allocator& a) + void create_promise(const Allocator& a, asio::error_code *pec) { ASIO_REBIND_ALLOC(Allocator, char) b(a); - p_ = std::allocate_shared>(b, std::allocator_arg, b); +#if defined(ASIO_HAS_STD_ALLOCATOR_ARG) + p_ = ASIO_ALLOCATE_SHARED< promise >(b, std::allocator_arg, b); +#else + p_ = ASIO_ALLOCATE_SHARED< promise >(b); +#endif + pec_ = pec; } - shared_ptr > p_; + shared_ptr< promise > p_; + asio::error_code *pec_; }; // For completion signature void(). @@ -302,14 +308,15 @@ class promise_handler_ec_0 public: void operator()(const asio::error_code& ec) { - if (ec) + if (ec && !this->pec_) { this->p_->set_exception( - std::make_exception_ptr( + ASIO_MAKE_EXCEPTION_PTR( asio::system_error(ec))); } else { + if (this->pec_) *this->pec_ = ec; this->p_->set_value(); } } @@ -320,7 +327,7 @@ class promise_handler_ex_0 : public promise_creator { public: - void operator()(const std::exception_ptr& ex) + void operator()(const exception_ptr& ex) { if (ex) { @@ -356,14 +363,17 @@ class promise_handler_ec_1 void operator()(const asio::error_code& ec, ASIO_MOVE_ARG(Arg) arg) { - if (ec) + if (ec && !this->pec_) { this->p_->set_exception( - std::make_exception_ptr( - asio::system_error(ec))); + ASIO_MAKE_EXCEPTION_PTR( + asio::system_error(ec))); } else + { + if(this->pec_) *this->pec_ = ec; this->p_->set_value(ASIO_MOVE_CAST(Arg)(arg)); + } } }; @@ -374,7 +384,7 @@ class promise_handler_ex_1 { public: template - void operator()(const std::exception_ptr& ex, + void operator()(const exception_ptr& ex, ASIO_MOVE_ARG(Arg) arg) { if (ex) @@ -429,14 +439,15 @@ class promise_handler_ec_n void operator()(const asio::error_code& ec, ASIO_MOVE_ARG(Args)... args) { - if (ec) + if (ec && !this->pec_) { this->p_->set_exception( - std::make_exception_ptr( - asio::system_error(ec))); + ASIO_MAKE_EXCEPTION_PTR( + asio::system_error(ec))); } else { + if(this->pec_) *this->pec_ = ec; this->p_->set_value( std::forward_as_tuple( ASIO_MOVE_CAST(Args)(args)...)); @@ -453,7 +464,7 @@ class promise_handler_ec_n if (ec) \ { \ this->p_->set_exception( \ - std::make_exception_ptr( \ + ASIO_MAKE_EXCEPTION_PTR( \ asio::system_error(ec))); \ } \ else \ @@ -479,7 +490,7 @@ class promise_handler_ex_n #if defined(ASIO_HAS_VARIADIC_TEMPLATES) template - void operator()(const std::exception_ptr& ex, + void operator()(const exception_ptr& ex, ASIO_MOVE_ARG(Args)... args) { if (ex) @@ -496,7 +507,7 @@ class promise_handler_ex_n #define ASIO_PRIVATE_CALL_OP_DEF(n) \ template \ - void operator()(const std::exception_ptr& ex, \ + void operator()(const exception_ptr& ex, \ ASIO_VARIADIC_MOVE_PARAMS(n)) \ {\ if (ex) \ @@ -528,7 +539,7 @@ class promise_handler_selector : public promise_handler_ec_0 {}; template <> -class promise_handler_selector +class promise_handler_selector : public promise_handler_ex_0 {}; template @@ -540,7 +551,7 @@ class promise_handler_selector : public promise_handler_ec_1 {}; template -class promise_handler_selector +class promise_handler_selector : public promise_handler_ex_1 {}; template @@ -552,7 +563,7 @@ class promise_handler_selector : public promise_handler_ec_n > {}; template -class promise_handler_selector +class promise_handler_selector : public promise_handler_ex_n > {}; // Completion handlers produced from the use_future completion token, when not @@ -568,7 +579,7 @@ class promise_handler promise_handler(use_future_t u) : allocator_(u.get_allocator()) { - this->create_promise(allocator_); + this->create_promise(allocator_, u.get_error_code()); } allocator_type get_allocator() const ASIO_NOEXCEPT @@ -650,7 +661,7 @@ class packaged_handler : function_(ASIO_MOVE_CAST(Function)(t.function_)), allocator_(t.allocator_) { - this->create_promise(allocator_); + this->create_promise(allocator_, ASIO_NULL); } allocator_type get_allocator() const ASIO_NOEXCEPT @@ -740,8 +751,8 @@ template template inline detail::packaged_token::type, Allocator> use_future_t::operator()(ASIO_MOVE_ARG(Function) f) const { - return detail::packaged_token::type, Allocator>( - ASIO_MOVE_CAST(Function)(f), allocator_); + return detail::packaged_token::type, Allocator> + (ASIO_MOVE_CAST(Function)(f), allocator_); } #if !defined(GENERATING_DOCUMENTATION) diff --git a/asio/include/asio/packaged_task.hpp b/asio/include/asio/packaged_task.hpp index af8d689664..ec0b977309 100644 --- a/asio/include/asio/packaged_task.hpp +++ b/asio/include/asio/packaged_task.hpp @@ -17,10 +17,10 @@ #include "asio/detail/config.hpp" -#if defined(ASIO_HAS_STD_FUTURE) \ - || defined(GENERATING_DOCUMENTATION) +#if !defined(ASIO_DISABLE_FUTURE) || defined(GENERATING_DOCUMENTATION) + +#include "asio/detail/future.hpp" -#include #include "asio/async_result.hpp" #include "asio/detail/type_traits.hpp" #include "asio/detail/variadic_templates.hpp" @@ -32,17 +32,17 @@ namespace asio { #if defined(ASIO_HAS_VARIADIC_TEMPLATES) \ || defined(GENERATING_DOCUMENTATION) -/// Partial specialisation of @c async_result for @c std::packaged_task. +/// Partial specialisation of @c async_result for @c packaged_task. template -class async_result, Signature> +class async_result, Signature> { public: /// The packaged task is the concrete completion handler type. - typedef std::packaged_task completion_handler_type; + typedef detail::packaged_task completion_handler_type; /// The return type of the initiating function is the future obtained from /// the packaged task. - typedef std::future return_type; + typedef detail::future return_type; /// The constructor extracts the future from the packaged task. explicit async_result(completion_handler_type& h) @@ -53,7 +53,7 @@ class async_result, Signature> /// Returns the packaged task's future. return_type get() { - return std::move(future_); + return ASIO_MOVE_CAST(return_type)(future_); } private: @@ -64,10 +64,10 @@ class async_result, Signature> // || defined(GENERATING_DOCUMENTATION) template -struct async_result, Signature> +struct async_result, Signature> { - typedef std::packaged_task completion_handler_type; - typedef std::future return_type; + typedef detail::packaged_task completion_handler_type; + typedef detail::future return_type; explicit async_result(completion_handler_type& h) : future_(h.get_future()) @@ -76,7 +76,7 @@ struct async_result, Signature> return_type get() { - return std::move(future_); + return ASIO_MOVE_CAST(return_type)(future_); } private: @@ -87,14 +87,14 @@ struct async_result, Signature> template \ class async_result< \ - std::packaged_task, Signature> \ + detail::packaged_task, Signature> \ { \ public: \ - typedef std::packaged_task< \ + typedef detail::packaged_task< \ Result(ASIO_VARIADIC_TARGS(n))> \ completion_handler_type; \ \ - typedef std::future return_type; \ + typedef detail::future return_type; \ \ explicit async_result(completion_handler_type& h) \ : future_(h.get_future()) \ @@ -103,7 +103,7 @@ struct async_result, Signature> \ return_type get() \ { \ - return std::move(future_); \ + return ASIO_MOVE_CAST(return_type)(future_); \ } \ \ private: \ @@ -120,7 +120,6 @@ struct async_result, Signature> #include "asio/detail/pop_options.hpp" -#endif // defined(ASIO_HAS_STD_FUTURE) - // || defined(GENERATING_DOCUMENTATION) +#endif // !defined(ASIO_DISABLE_FUTURE) || defined(GENERATING_DOCUMENTATION) #endif // ASIO_PACKAGED_TASK_HPP diff --git a/asio/include/asio/use_future.hpp b/asio/include/asio/use_future.hpp index 2a0e24ff94..9b9d87a8df 100644 --- a/asio/include/asio/use_future.hpp +++ b/asio/include/asio/use_future.hpp @@ -17,12 +17,12 @@ #include "asio/detail/config.hpp" -#if defined(ASIO_HAS_STD_FUTURE) \ - || defined(GENERATING_DOCUMENTATION) +#if !defined(ASIO_DISABLE_FUTURE) || defined(GENERATING_DOCUMENTATION) #include +#include "asio/error_code.hpp" #include "asio/detail/type_traits.hpp" - +#include "asio/detail/cstddef.hpp" #include "asio/detail/push_options.hpp" namespace asio { @@ -39,11 +39,11 @@ class packaged_handler; /// Class used to specify that an asynchronous operation should return a future. /** * The use_future_t class is used to indicate that an asynchronous operation - * should return a std::future object. A use_future_t object may be passed as a + * should return a future object. A use_future_t object may be passed as a * handler to an asynchronous operation, typically using the special value @c * asio::use_future. For example: * - * @code std::future my_future + * @code future my_future * = my_socket.async_read_some(my_buffer, asio::use_future); @endcode * * The initiating function (async_read_some in the above example) returns a @@ -56,17 +56,21 @@ class use_future_t { public: /// The allocator type. The allocator is used when constructing the - /// @c std::promise object for a given asynchronous operation. + /// @c promise object for a given asynchronous operation. typedef Allocator allocator_type; /// Construct using default-constructed allocator. - ASIO_CONSTEXPR use_future_t() + ASIO_CONSTEXPR use_future_t() : pec_(ASIO_NULL) + { + } + + ASIO_CONSTEXPR use_future_t(asio::error_code &ec) : pec_(&ec) { } /// Construct using specified allocator. - explicit use_future_t(const Allocator& allocator) - : allocator_(allocator) + explicit use_future_t(const Allocator& allocator, asio::error_code *ec = ASIO_NULL) + : allocator_(allocator), pec_(ec) { } @@ -75,7 +79,7 @@ class use_future_t template use_future_t operator[](const OtherAllocator& allocator) const { - return use_future_t(allocator); + return use_future_t(allocator, pec_); } #endif // !defined(ASIO_NO_DEPRECATED) @@ -83,7 +87,7 @@ class use_future_t template use_future_t rebind(const OtherAllocator& allocator) const { - return use_future_t(allocator); + return use_future_t(allocator_, pec_); } /// Obtain allocator. @@ -92,15 +96,26 @@ class use_future_t return allocator_; } + asio::error_code *get_error_code() const + { + return pec_; + } + + //make like yield_context for passing an error code in to retrieve error + use_future_t operator[](asio::error_code &ec) const + { + return use_future_t(allocator_, &ec); + } + /// Wrap a function object in a packaged task. /** * The @c package function is used to adapt a function object as a packaged * task. When this adapter is passed as a completion token to an asynchronous - * operation, the result of the function object is retuned via a std::future. + * operation, the result of the function object is retuned via a future. * * @par Example * - * @code std::future fut = + * @code future fut = * my_socket.async_read_some(buffer, * use_future([](asio::error_code ec, std::size_t n) * { @@ -119,6 +134,7 @@ class use_future_t private: Allocator allocator_; + asio::error_code *pec_; }; /// A special value, similar to std::nothrow. @@ -137,7 +153,6 @@ __declspec(selectany) use_future_t<> use_future; #include "asio/impl/use_future.hpp" -#endif // defined(ASIO_HAS_STD_FUTURE) - // || defined(GENERATING_DOCUMENTATION) +#endif //!(ASIO_DISABLE_FUTURE) || defined(GENERATING_DOCUMENTATION) #endif // ASIO_USE_FUTURE_HPP diff --git a/asio/src/examples/cpp03/iostreams/http_client.cpp b/asio/src/examples/cpp03/iostreams/http_client.cpp index 247df0f37e..5b6edea705 100644 --- a/asio/src/examples/cpp03/iostreams/http_client.cpp +++ b/asio/src/examples/cpp03/iostreams/http_client.cpp @@ -33,7 +33,11 @@ int main(int argc, char* argv[]) // The entire sequence of I/O operations must complete within 60 seconds. // If an expiry occurs, the socket is automatically closed and the stream // becomes bad. +#if defined(ASIO_STANDALONE) + s.expires_after(asio::chrono::seconds(60)); +#else s.expires_after(boost::posix_time::seconds(60)); +#endif // Establish a connection to the server. s.connect(argv[1], "http"); diff --git a/asio/src/examples/cpp11/executors/fork_join.cpp b/asio/src/examples/cpp11/executors/fork_join.cpp index 6971681482..12bcfb1d42 100644 --- a/asio/src/examples/cpp11/executors/fork_join.cpp +++ b/asio/src/examples/cpp11/executors/fork_join.cpp @@ -6,6 +6,7 @@ #include #include #include +#include using asio::dispatch; using asio::execution_context; diff --git a/asio/src/examples/cpp11/executors/pipeline.cpp b/asio/src/examples/cpp11/executors/pipeline.cpp index 86bf860cb9..fda0c9b8fa 100644 --- a/asio/src/examples/cpp11/executors/pipeline.cpp +++ b/asio/src/examples/cpp11/executors/pipeline.cpp @@ -11,6 +11,7 @@ #include #include #include +#include using asio::execution_context; using asio::executor_binder; diff --git a/asio/src/examples/cpp11/futures/daytime_client.cpp b/asio/src/examples/cpp11/futures/daytime_client.cpp index 0004e124ff..20f57d67b0 100644 --- a/asio/src/examples/cpp11/futures/daytime_client.cpp +++ b/asio/src/examples/cpp11/futures/daytime_client.cpp @@ -9,7 +9,6 @@ // #include -#include #include #include #include @@ -24,7 +23,7 @@ void get_daytime(asio::io_context& io_context, const char* hostname) { udp::resolver resolver(io_context); - std::future endpoints = + asio::detail::future endpoints = resolver.async_resolve( udp::v4(), hostname, "daytime", asio::use_future); @@ -35,7 +34,7 @@ void get_daytime(asio::io_context& io_context, const char* hostname) udp::socket socket(io_context, udp::v4()); std::array send_buf = {{ 0 }}; - std::future send_length = + asio::detail::future send_length = socket.async_send_to(asio::buffer(send_buf), *endpoints.get().begin(), // ... until here. This call may block. asio::use_future); @@ -46,7 +45,7 @@ void get_daytime(asio::io_context& io_context, const char* hostname) std::array recv_buf; udp::endpoint sender_endpoint; - std::future recv_length = + asio::detail::future recv_length = socket.async_receive_from( asio::buffer(recv_buf), sender_endpoint, diff --git a/asio/src/examples/cpp11/iostreams/http_client.cpp b/asio/src/examples/cpp11/iostreams/http_client.cpp index 7972a67ecf..fb90cb71b6 100644 --- a/asio/src/examples/cpp11/iostreams/http_client.cpp +++ b/asio/src/examples/cpp11/iostreams/http_client.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using asio::ip::tcp; @@ -33,7 +34,11 @@ int main(int argc, char* argv[]) // The entire sequence of I/O operations must complete within 60 seconds. // If an expiry occurs, the socket is automatically closed and the stream // becomes bad. - s.expires_after(std::chrono::seconds(60)); +#if defined(ASIO_STANDALONE) + s.expires_after(asio::chrono::seconds(60)); +#else + s.expires_after(boost::posix_time::seconds(60)); +#endif // Establish a connection to the server. s.connect(argv[1], "http"); diff --git a/asio/src/tests/unit/archetypes/async_ops.hpp b/asio/src/tests/unit/archetypes/async_ops.hpp index 331d8ac32e..3c40c50636 100644 --- a/asio/src/tests/unit/archetypes/async_ops.hpp +++ b/asio/src/tests/unit/archetypes/async_ops.hpp @@ -86,14 +86,14 @@ async_op_ec_0(bool ok, ASIO_MOVE_ARG(CompletionToken) token) } template -ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr)) +ASIO_INITFN_RESULT_TYPE(CompletionToken, void(asio::detail::exception_ptr)) async_op_ex_0(bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::async_completion::completion_handler_type handler_type; + void(asio::detail::exception_ptr)>::completion_handler_type handler_type; asio::async_completion completion(token); + void(asio::detail::exception_ptr)> completion(token); typename asio::associated_allocator::type a = asio::get_associated_allocator(completion.completion_handler); @@ -106,14 +106,14 @@ async_op_ex_0(bool ok, ASIO_MOVE_ARG(CompletionToken) token) ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::exception_ptr()), a); + asio::detail::exception_ptr()), a); } else { ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::make_exception_ptr(std::runtime_error("blah"))), a); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah"))), a); } return completion.result.get(); @@ -181,15 +181,15 @@ async_op_ec_1(bool ok, ASIO_MOVE_ARG(CompletionToken) token) } template -ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr, int)) +ASIO_INITFN_RESULT_TYPE(CompletionToken, void(asio::detail::exception_ptr, int)) async_op_ex_1(bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::async_completion::completion_handler_type + void(asio::detail::exception_ptr, int)>::completion_handler_type handler_type; asio::async_completion completion(token); + void(asio::detail::exception_ptr, int)> completion(token); typename asio::associated_allocator::type a = asio::get_associated_allocator(completion.completion_handler); @@ -202,14 +202,14 @@ async_op_ex_1(bool ok, ASIO_MOVE_ARG(CompletionToken) token) ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::exception_ptr(), 42), a); + asio::detail::exception_ptr(), 42), a); } else { ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::make_exception_ptr(std::runtime_error("blah")), 0), a); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0), a); } return completion.result.get(); @@ -278,15 +278,15 @@ async_op_ec_2(bool ok, ASIO_MOVE_ARG(CompletionToken) token) template ASIO_INITFN_RESULT_TYPE(CompletionToken, - void(std::exception_ptr, int, double)) + void(asio::detail::exception_ptr, int, double)) async_op_ex_2(bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::async_completion::completion_handler_type + void(asio::detail::exception_ptr, int, double)>::completion_handler_type handler_type; asio::async_completion completion(token); + void(asio::detail::exception_ptr, int, double)> completion(token); typename asio::associated_allocator::type a = asio::get_associated_allocator(completion.completion_handler); @@ -299,14 +299,14 @@ async_op_ex_2(bool ok, ASIO_MOVE_ARG(CompletionToken) token) ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::exception_ptr(), 42, 2.0), a); + asio::detail::exception_ptr(), 42, 2.0), a); } else { ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0), a); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0, 0.0), a); } return completion.result.get(); @@ -375,15 +375,15 @@ async_op_ec_3(bool ok, ASIO_MOVE_ARG(CompletionToken) token) template ASIO_INITFN_RESULT_TYPE(CompletionToken, - void(std::exception_ptr, int, double, char)) + void(asio::detail::exception_ptr, int, double, char)) async_op_ex_3(bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::async_completion::completion_handler_type + void(asio::detail::exception_ptr, int, double, char)>::completion_handler_type handler_type; asio::async_completion completion(token); + void(asio::detail::exception_ptr, int, double, char)> completion(token); typename asio::associated_allocator::type a = asio::get_associated_allocator(completion.completion_handler); @@ -396,14 +396,14 @@ async_op_ex_3(bool ok, ASIO_MOVE_ARG(CompletionToken) token) ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::exception_ptr(), 42, 2.0, 'a'), a); + asio::detail::exception_ptr(), 42, 2.0, 'a'), a); } else { ex.post( bindns::bind( ASIO_MOVE_CAST(handler_type)(completion.completion_handler), - std::make_exception_ptr(std::runtime_error("blah")), + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0, 0.0, 'z'), a); } diff --git a/asio/src/tests/unit/archetypes/deprecated_async_ops.hpp b/asio/src/tests/unit/archetypes/deprecated_async_ops.hpp index ee1cab939c..a301b94606 100644 --- a/asio/src/tests/unit/archetypes/deprecated_async_ops.hpp +++ b/asio/src/tests/unit/archetypes/deprecated_async_ops.hpp @@ -83,12 +83,12 @@ deprecated_async_op_ec_0(asio::io_context& ctx, template typename asio::async_result< typename asio::handler_type::type>::type + void(asio::detail::exception_ptr)>::type>::type deprecated_async_op_ex_0(asio::io_context& ctx, bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::handler_type::type handler_type; + void(asio::detail::exception_ptr)>::type handler_type; handler_type handler(ASIO_MOVE_CAST(CompletionToken)(token)); @@ -97,12 +97,12 @@ deprecated_async_op_ex_0(asio::io_context& ctx, if (ok) { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::exception_ptr())); + asio::detail::exception_ptr())); } else { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::make_exception_ptr(std::runtime_error("blah")))); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")))); } return result.get(); @@ -158,12 +158,12 @@ deprecated_async_op_ec_1(asio::io_context& ctx, template typename asio::async_result< typename asio::handler_type::type>::type + void(asio::detail::exception_ptr, int)>::type>::type deprecated_async_op_ex_1(asio::io_context& ctx, bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::handler_type::type handler_type; + void(asio::detail::exception_ptr, int)>::type handler_type; handler_type handler(ASIO_MOVE_CAST(CompletionToken)(token)); @@ -172,12 +172,12 @@ deprecated_async_op_ex_1(asio::io_context& ctx, if (ok) { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::exception_ptr(), 42)); + asio::detail::exception_ptr(), 42)); } else { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::make_exception_ptr(std::runtime_error("blah")), 0)); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0)); } return result.get(); @@ -235,12 +235,12 @@ deprecated_async_op_ec_2(asio::io_context& ctx, template typename asio::async_result< typename asio::handler_type::type>::type + void(asio::detail::exception_ptr, int, double)>::type>::type deprecated_async_op_ex_2(asio::io_context& ctx, bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::handler_type::type handler_type; + void(asio::detail::exception_ptr, int, double)>::type handler_type; handler_type handler(ASIO_MOVE_CAST(CompletionToken)(token)); @@ -249,12 +249,12 @@ deprecated_async_op_ex_2(asio::io_context& ctx, if (ok) { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::exception_ptr(), 42, 2.0)); + asio::detail::exception_ptr(), 42, 2.0)); } else { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0)); + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0, 0.0)); } return result.get(); @@ -312,12 +312,12 @@ deprecated_async_op_ec_3(asio::io_context& ctx, template typename asio::async_result< typename asio::handler_type::type>::type + void(asio::detail::exception_ptr, int, double, char)>::type>::type deprecated_async_op_ex_3(asio::io_context& ctx, bool ok, ASIO_MOVE_ARG(CompletionToken) token) { typedef typename asio::handler_type::type handler_type; + void(asio::detail::exception_ptr, int, double, char)>::type handler_type; handler_type handler(ASIO_MOVE_CAST(CompletionToken)(token)); @@ -326,12 +326,12 @@ deprecated_async_op_ex_3(asio::io_context& ctx, if (ok) { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::exception_ptr(), 42, 2.0, 'a')); + asio::detail::exception_ptr(), 42, 2.0, 'a')); } else { ctx.post(bindns::bind(ASIO_MOVE_CAST(handler_type)(handler), - std::make_exception_ptr(std::runtime_error("blah")), + ASIO_MAKE_EXCEPTION_PTR(std::runtime_error("blah")), 0, 0.0, 'z')); }