Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:57

0001 
0002 // impl/redirect_error.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP
0012 #define BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/associator.hpp>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/detail/handler_cont_helpers.hpp>
0022 #include <boost/asio/detail/type_traits.hpp>
0023 #include <boost/system/system_error.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030 
0031 // Class to adapt a redirect_error_t as a completion handler.
0032 template <typename Handler>
0033 class redirect_error_handler
0034 {
0035 public:
0036   typedef void result_type;
0037 
0038   template <typename CompletionToken>
0039   redirect_error_handler(redirect_error_t<CompletionToken> e)
0040     : ec_(e.ec_),
0041       handler_(static_cast<CompletionToken&&>(e.token_))
0042   {
0043   }
0044 
0045   template <typename RedirectedHandler>
0046   redirect_error_handler(boost::system::error_code& ec,
0047       RedirectedHandler&& h)
0048     : ec_(ec),
0049       handler_(static_cast<RedirectedHandler&&>(h))
0050   {
0051   }
0052 
0053   void operator()()
0054   {
0055     static_cast<Handler&&>(handler_)();
0056   }
0057 
0058   template <typename Arg, typename... Args>
0059   enable_if_t<
0060     !is_same<decay_t<Arg>, boost::system::error_code>::value
0061   >
0062   operator()(Arg&& arg, Args&&... args)
0063   {
0064     static_cast<Handler&&>(handler_)(
0065         static_cast<Arg&&>(arg),
0066         static_cast<Args&&>(args)...);
0067   }
0068 
0069   template <typename... Args>
0070   void operator()(const boost::system::error_code& ec, Args&&... args)
0071   {
0072     ec_ = ec;
0073     static_cast<Handler&&>(handler_)(static_cast<Args&&>(args)...);
0074   }
0075 
0076 //private:
0077   boost::system::error_code& ec_;
0078   Handler handler_;
0079 };
0080 
0081 template <typename Handler>
0082 inline bool asio_handler_is_continuation(
0083     redirect_error_handler<Handler>* this_handler)
0084 {
0085   return boost_asio_handler_cont_helpers::is_continuation(
0086         this_handler->handler_);
0087 }
0088 
0089 template <typename Signature>
0090 struct redirect_error_signature
0091 {
0092   typedef Signature type;
0093 };
0094 
0095 template <typename R, typename... Args>
0096 struct redirect_error_signature<R(boost::system::error_code, Args...)>
0097 {
0098   typedef R type(Args...);
0099 };
0100 
0101 template <typename R, typename... Args>
0102 struct redirect_error_signature<R(const boost::system::error_code&, Args...)>
0103 {
0104   typedef R type(Args...);
0105 };
0106 
0107 template <typename R, typename... Args>
0108 struct redirect_error_signature<R(boost::system::error_code, Args...) &>
0109 {
0110   typedef R type(Args...) &;
0111 };
0112 
0113 template <typename R, typename... Args>
0114 struct redirect_error_signature<R(const boost::system::error_code&, Args...) &>
0115 {
0116   typedef R type(Args...) &;
0117 };
0118 
0119 template <typename R, typename... Args>
0120 struct redirect_error_signature<R(boost::system::error_code, Args...) &&>
0121 {
0122   typedef R type(Args...) &&;
0123 };
0124 
0125 template <typename R, typename... Args>
0126 struct redirect_error_signature<R(const boost::system::error_code&, Args...) &&>
0127 {
0128   typedef R type(Args...) &&;
0129 };
0130 
0131 #if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0132 
0133 template <typename R, typename... Args>
0134 struct redirect_error_signature<
0135   R(boost::system::error_code, Args...) noexcept>
0136 {
0137   typedef R type(Args...) & noexcept;
0138 };
0139 
0140 template <typename R, typename... Args>
0141 struct redirect_error_signature<
0142   R(const boost::system::error_code&, Args...) noexcept>
0143 {
0144   typedef R type(Args...) & noexcept;
0145 };
0146 
0147 template <typename R, typename... Args>
0148 struct redirect_error_signature<
0149   R(boost::system::error_code, Args...) & noexcept>
0150 {
0151   typedef R type(Args...) & noexcept;
0152 };
0153 
0154 template <typename R, typename... Args>
0155 struct redirect_error_signature<
0156   R(const boost::system::error_code&, Args...) & noexcept>
0157 {
0158   typedef R type(Args...) & noexcept;
0159 };
0160 
0161 template <typename R, typename... Args>
0162 struct redirect_error_signature<
0163   R(boost::system::error_code, Args...) && noexcept>
0164 {
0165   typedef R type(Args...) && noexcept;
0166 };
0167 
0168 template <typename R, typename... Args>
0169 struct redirect_error_signature<
0170   R(const boost::system::error_code&, Args...) && noexcept>
0171 {
0172   typedef R type(Args...) && noexcept;
0173 };
0174 
0175 #endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0176 
0177 } // namespace detail
0178 
0179 #if !defined(GENERATING_DOCUMENTATION)
0180 
0181 template <typename CompletionToken, typename Signature>
0182 struct async_result<redirect_error_t<CompletionToken>, Signature>
0183   : async_result<CompletionToken,
0184       typename detail::redirect_error_signature<Signature>::type>
0185 {
0186 
0187   struct init_wrapper
0188   {
0189     explicit init_wrapper(boost::system::error_code& ec)
0190       : ec_(ec)
0191     {
0192     }
0193 
0194     template <typename Handler, typename Initiation, typename... Args>
0195     void operator()(Handler&& handler,
0196         Initiation&& initiation, Args&&... args) const
0197     {
0198       static_cast<Initiation&&>(initiation)(
0199           detail::redirect_error_handler<decay_t<Handler>>(
0200             ec_, static_cast<Handler&&>(handler)),
0201           static_cast<Args&&>(args)...);
0202     }
0203 
0204     boost::system::error_code& ec_;
0205   };
0206 
0207   template <typename Initiation, typename RawCompletionToken, typename... Args>
0208   static auto initiate(Initiation&& initiation,
0209       RawCompletionToken&& token, Args&&... args)
0210     -> decltype(
0211       async_initiate<CompletionToken,
0212         typename detail::redirect_error_signature<Signature>::type>(
0213           declval<init_wrapper>(), token.token_,
0214           static_cast<Initiation&&>(initiation),
0215           static_cast<Args&&>(args)...))
0216   {
0217     return async_initiate<CompletionToken,
0218       typename detail::redirect_error_signature<Signature>::type>(
0219         init_wrapper(token.ec_), token.token_,
0220         static_cast<Initiation&&>(initiation),
0221         static_cast<Args&&>(args)...);
0222   }
0223 };
0224 
0225 template <template <typename, typename> class Associator,
0226     typename Handler, typename DefaultCandidate>
0227 struct associator<Associator,
0228     detail::redirect_error_handler<Handler>, DefaultCandidate>
0229   : Associator<Handler, DefaultCandidate>
0230 {
0231   static typename Associator<Handler, DefaultCandidate>::type get(
0232       const detail::redirect_error_handler<Handler>& h) noexcept
0233   {
0234     return Associator<Handler, DefaultCandidate>::get(h.handler_);
0235   }
0236 
0237   static auto get(const detail::redirect_error_handler<Handler>& h,
0238       const DefaultCandidate& c) noexcept
0239     -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0240   {
0241     return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0242   }
0243 };
0244 
0245 #endif // !defined(GENERATING_DOCUMENTATION)
0246 
0247 } // namespace asio
0248 } // namespace boost
0249 
0250 #include <boost/asio/detail/pop_options.hpp>
0251 
0252 #endif // BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP