Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:24

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_DETAIL_GET_IO_CONTEXT_HPP
0011 #define BOOST_BEAST_DETAIL_GET_IO_CONTEXT_HPP
0012 
0013 #include <boost/beast/core/stream_traits.hpp>
0014 #ifdef BOOST_ASIO_NO_TS_EXECUTORS
0015 #include <boost/asio/execution.hpp>
0016 #endif
0017 #include <boost/asio/executor.hpp>
0018 #include <boost/asio/io_context.hpp>
0019 #include <boost/asio/strand.hpp>
0020 #include <memory>
0021 #include <type_traits>
0022 
0023 namespace boost {
0024 namespace beast {
0025 namespace detail {
0026 
0027 //------------------------------------------------------------------------------
0028 
0029 inline
0030 net::io_context*
0031 get_io_context(net::io_context& ioc)
0032 {
0033     return std::addressof(ioc);
0034 }
0035 
0036 inline
0037 net::io_context*
0038 get_io_context(net::io_context::executor_type const& ex)
0039 {
0040     return std::addressof(net::query(ex, net::execution::context));
0041 }
0042 
0043 inline
0044 net::io_context*
0045 get_io_context(net::strand<
0046     net::io_context::executor_type> const& ex)
0047 {
0048     return get_io_context(ex.get_inner_executor());
0049 }
0050 
0051 template<class Executor>
0052 net::io_context*
0053 get_io_context(net::strand<Executor> const& ex)
0054 {
0055     return get_io_context(ex.get_inner_executor());
0056 }
0057 
0058 template<
0059     class T,
0060     class = typename std::enable_if<
0061         std::is_same<T, net::executor>::value || std::is_same<T, net::any_io_executor>::value>::type>
0062 net::io_context*
0063 get_io_context(T const& ex)
0064 {
0065     auto p = ex.template target<typename
0066         net::io_context::executor_type>();
0067     if(! p)
0068         return nullptr;
0069     return get_io_context(*p);
0070 }
0071 
0072 inline
0073 net::io_context*
0074 get_io_context(...)
0075 {
0076     return nullptr;
0077 }
0078 
0079 //------------------------------------------------------------------------------
0080 
0081 template<class T>
0082 net::io_context*
0083 get_io_context_impl(T& t, std::true_type)
0084 {
0085     return get_io_context(
0086         t.get_executor());
0087 }
0088 
0089 template<class T>
0090 net::io_context*
0091 get_io_context_impl(T const&, std::false_type)
0092 {
0093     return nullptr;
0094 }
0095 
0096 // Returns the io_context*, or nullptr, for any object.
0097 template<class T>
0098 net::io_context*
0099 get_io_context(T& t)
0100 {
0101     return get_io_context_impl(t,
0102         has_get_executor<T>{});
0103 }
0104 
0105 } // detail
0106 } // beast
0107 } // boost
0108 
0109 #endif