repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
asio
data/projects/asio/include/boost/asio/traits/prefer_free.hpp
// // traits/prefer_free.hpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_PREFER_FREE_HPP #define BOOST_ASIO_TRAITS_PREFER_FREE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct prefer_free_default; template <typename T, typename Property, typename = void> struct prefer_free; } // namespace traits namespace detail { struct no_prefer_free { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT) template <typename T, typename Property, typename = void> struct prefer_free_trait : no_prefer_free { }; template <typename T, typename Property> struct prefer_free_trait<T, Property, void_t< decltype(prefer(declval<T>(), declval<Property>())) >> { static constexpr bool is_valid = true; using result_type = decltype( prefer(declval<T>(), declval<Property>())); static constexpr bool is_noexcept = noexcept(prefer(declval<T>(), declval<Property>())); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT) template <typename T, typename Property, typename = void> struct prefer_free_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_prefer_free, traits::prefer_free< decay_t<T>, decay_t<Property>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct prefer_free_default : detail::prefer_free_trait<T, Property> { }; template <typename T, typename Property, typename> struct prefer_free : prefer_free_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_PREFER_FREE_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/require_concept_member.hpp
// // traits/require_concept_member.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_MEMBER_HPP #define BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_MEMBER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_MEMBER_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct require_concept_member_default; template <typename T, typename Property, typename = void> struct require_concept_member; } // namespace traits namespace detail { struct no_require_concept_member { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct require_concept_member_trait : no_require_concept_member { }; template <typename T, typename Property> struct require_concept_member_trait<T, Property, void_t< decltype(declval<T>().require_concept(declval<Property>())) >> { static constexpr bool is_valid = true; using result_type = decltype( declval<T>().require_concept(declval<Property>())); static constexpr bool is_noexcept = noexcept(declval<T>().require_concept(declval<Property>())); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct require_concept_member_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_require_concept_member, traits::require_concept_member< decay_t<T>, decay_t<Property>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_MEMBER_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct require_concept_member_default : detail::require_concept_member_trait<T, Property> { }; template <typename T, typename Property, typename> struct require_concept_member : require_concept_member_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_MEMBER_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/query_static_constexpr_member.hpp
// // traits/query_static_constexpr_member.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_MEMBER_HPP #define BOOST_ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_MEMBER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE) \ && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE) // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct query_static_constexpr_member_default; template <typename T, typename Property, typename = void> struct query_static_constexpr_member; } // namespace traits namespace detail { struct no_query_static_constexpr_member { static constexpr bool is_valid = false; }; template <typename T, typename Property, typename = void> struct query_static_constexpr_member_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_query_static_constexpr_member, traits::query_static_constexpr_member< decay_t<T>, decay_t<Property>> > { }; #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) template <typename T, typename Property> struct query_static_constexpr_member_trait<T, Property, enable_if_t< (static_cast<void>(T::query(Property{})), true) >> { static constexpr bool is_valid = true; using result_type = decltype(T::query(Property{})); static constexpr bool is_noexcept = noexcept(T::query(Property{})); static constexpr result_type value() noexcept(is_noexcept) { return T::query(Property{}); } }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct query_static_constexpr_member_default : detail::query_static_constexpr_member_trait<T, Property> { }; template <typename T, typename Property, typename> struct query_static_constexpr_member : query_static_constexpr_member_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_QUERY_STATIC_CONSTEXPR_MEMBER_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/require_free.hpp
// // traits/require_free.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_REQUIRE_FREE_HPP #define BOOST_ASIO_TRAITS_REQUIRE_FREE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct require_free_default; template <typename T, typename Property, typename = void> struct require_free; } // namespace traits namespace detail { struct no_require_free { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT) template <typename T, typename Property, typename = void> struct require_free_trait : no_require_free { }; template <typename T, typename Property> struct require_free_trait<T, Property, void_t< decltype(require(declval<T>(), declval<Property>())) >> { static constexpr bool is_valid = true; using result_type = decltype( require(declval<T>(), declval<Property>())); static constexpr bool is_noexcept = noexcept(require(declval<T>(), declval<Property>())); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT) template <typename T, typename Property, typename = void> struct require_free_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_require_free, traits::require_free< decay_t<T>, decay_t<Property>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct require_free_default : detail::require_free_trait<T, Property> { }; template <typename T, typename Property, typename> struct require_free : require_free_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_REQUIRE_FREE_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/require_member.hpp
// // traits/require_member.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_REQUIRE_MEMBER_HPP #define BOOST_ASIO_TRAITS_REQUIRE_MEMBER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct require_member_default; template <typename T, typename Property, typename = void> struct require_member; } // namespace traits namespace detail { struct no_require_member { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct require_member_trait : no_require_member { }; template <typename T, typename Property> struct require_member_trait<T, Property, void_t< decltype(declval<T>().require(declval<Property>())) >> { static constexpr bool is_valid = true; using result_type = decltype( declval<T>().require(declval<Property>())); static constexpr bool is_noexcept = noexcept(declval<T>().require(declval<Property>())); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct require_member_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_require_member, traits::require_member< decay_t<T>, decay_t<Property>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct require_member_default : detail::require_member_trait<T, Property> { }; template <typename T, typename Property, typename> struct require_member : require_member_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_REQUIRE_MEMBER_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/static_require.hpp
// // traits/static_require.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_STATIC_REQUIRE_HPP #define BOOST_ASIO_TRAITS_STATIC_REQUIRE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/traits/static_query.hpp> #define BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT 1 #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct static_require_default; template <typename T, typename Property, typename = void> struct static_require; } // namespace traits namespace detail { struct no_static_require { static constexpr bool is_valid = false; }; template <typename T, typename Property, typename = void> struct static_require_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_static_require, traits::static_require< decay_t<T>, decay_t<Property>> > { }; #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) template <typename T, typename Property> struct static_require_trait<T, Property, enable_if_t< decay_t<Property>::value() == traits::static_query<T, Property>::value() >> { static constexpr bool is_valid = true; }; #else // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) false_type static_require_test(...); template <typename T, typename Property> true_type static_require_test(T*, Property*, enable_if_t< Property::value() == traits::static_query<T, Property>::value() >* = 0); template <typename T, typename Property> struct has_static_require { static constexpr bool value = decltype((static_require_test)( static_cast<T*>(0), static_cast<Property*>(0)))::value; }; template <typename T, typename Property> struct static_require_trait<T, Property, enable_if_t< has_static_require<decay_t<T>, decay_t<Property>>::value >> { static constexpr bool is_valid = true; }; #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct static_require_default : detail::static_require_trait<T, Property> { }; template <typename T, typename Property, typename> struct static_require : static_require_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_STATIC_REQUIRE_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/prefer_member.hpp
// // traits/prefer_member.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP #define BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct prefer_member_default; template <typename T, typename Property, typename = void> struct prefer_member; } // namespace traits namespace detail { struct no_prefer_member { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct prefer_member_trait : no_prefer_member { }; template <typename T, typename Property> struct prefer_member_trait<T, Property, void_t< decltype(declval<T>().prefer(declval<Property>())) >> { static constexpr bool is_valid = true; using result_type = decltype( declval<T>().prefer(declval<Property>())); static constexpr bool is_noexcept = noexcept(declval<T>().prefer(declval<Property>())); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) template <typename T, typename Property, typename = void> struct prefer_member_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_prefer_member, traits::prefer_member< decay_t<T>, decay_t<Property>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct prefer_member_default : detail::prefer_member_trait<T, Property> { }; template <typename T, typename Property, typename> struct prefer_member : prefer_member_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_PREFER_MEMBER_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/static_query.hpp
// // traits/static_query.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_STATIC_QUERY_HPP #define BOOST_ASIO_TRAITS_STATIC_QUERY_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) \ && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace traits { template <typename T, typename Property, typename = void> struct static_query_default; template <typename T, typename Property, typename = void> struct static_query; } // namespace traits namespace detail { struct no_static_query { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; template <typename T, typename Property, typename = void> struct static_query_trait : conditional_t< is_same<T, decay_t<T>>::value && is_same<Property, decay_t<Property>>::value, no_static_query, traits::static_query< decay_t<T>, decay_t<Property>> > { }; #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) template <typename T, typename Property> struct static_query_trait<T, Property, void_t< decltype(decay_t<Property>::template static_query_v<T>) >> { static constexpr bool is_valid = true; using result_type = decltype( decay_t<Property>::template static_query_v<T>); static constexpr bool is_noexcept = noexcept(decay_t<Property>::template static_query_v<T>); static constexpr result_type value() noexcept(is_noexcept) { return decay_t<Property>::template static_query_v<T>; } }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) } // namespace detail namespace traits { template <typename T, typename Property, typename> struct static_query_default : detail::static_query_trait<T, Property> { }; template <typename T, typename Property, typename> struct static_query : static_query_default<T, Property> { }; } // namespace traits } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_TRAITS_STATIC_QUERY_HPP
hpp
asio
data/projects/asio/include/boost/asio/traits/equality_comparable.hpp
// // traits/equality_comparable.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP #define BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # define BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT 1 #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) namespace boost { namespace asio { namespace traits { template <typename T, typename = void> struct equality_comparable_default; template <typename T, typename = void> struct equality_comparable; } // namespace traits namespace detail { struct no_equality_comparable { static constexpr bool is_valid = false; static constexpr bool is_noexcept = false; }; #if defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) template <typename T, typename = void> struct equality_comparable_trait : no_equality_comparable { }; template <typename T> struct equality_comparable_trait<T, void_t< decltype( static_cast<void>( static_cast<bool>(declval<const T>() == declval<const T>()) ), static_cast<void>( static_cast<bool>(declval<const T>() != declval<const T>()) ) ) >> { static constexpr bool is_valid = true; static constexpr bool is_noexcept = noexcept(declval<const T>() == declval<const T>()) && noexcept(declval<const T>() != declval<const T>()); }; #else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) template <typename T, typename = void> struct equality_comparable_trait : conditional_t< is_same<T, decay_t<T>>::value, no_equality_comparable, traits::equality_comparable<decay_t<T>> > { }; #endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) } // namespace detail namespace traits { template <typename T, typename> struct equality_comparable_default : detail::equality_comparable_trait<T> { }; template <typename T, typename> struct equality_comparable : equality_comparable_default<T> { }; } // namespace traits } // namespace asio } // namespace boost #endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/basic_overlapped_handle.hpp
// // windows/basic_overlapped_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_BASIC_OVERLAPPED_HANDLE_HPP #define BOOST_ASIO_WINDOWS_BASIC_OVERLAPPED_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \ || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <cstddef> #include <utility> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/io_object_impl.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/detail/win_iocp_handle_service.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace windows { /// Provides Windows handle functionality for objects that support /// overlapped I/O. /** * The windows::overlapped_handle class provides the ability to wrap a Windows * handle. The underlying object referred to by the handle must support * overlapped I/O. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. */ template <typename Executor = any_io_executor> class basic_overlapped_handle { public: /// The type of the executor associated with the object. typedef Executor executor_type; /// Rebinds the handle type to another executor. template <typename Executor1> struct rebind_executor { /// The handle type when rebound to the specified executor. typedef basic_overlapped_handle<Executor1> other; }; /// The native representation of a handle. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined native_handle_type; #else typedef boost::asio::detail::win_iocp_handle_service::native_handle_type native_handle_type; #endif /// An overlapped_handle is always the lowest layer. typedef basic_overlapped_handle lowest_layer_type; /// Construct an overlapped handle without opening it. /** * This constructor creates an overlapped handle without opening it. * * @param ex The I/O executor that the overlapped handle will use, by default, * to dispatch handlers for any asynchronous operations performed on the * overlapped handle. */ explicit basic_overlapped_handle(const executor_type& ex) : impl_(0, ex) { } /// Construct an overlapped handle without opening it. /** * This constructor creates an overlapped handle without opening it. * * @param context An execution context which provides the I/O executor that * the overlapped handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the overlapped handle. */ template <typename ExecutionContext> explicit basic_overlapped_handle(ExecutionContext& context, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : impl_(0, 0, context) { } /// Construct an overlapped handle on an existing native handle. /** * This constructor creates an overlapped handle object to hold an existing * native handle. * * @param ex The I/O executor that the overlapped handle will use, by default, * to dispatch handlers for any asynchronous operations performed on the * overlapped handle. * * @param native_handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ basic_overlapped_handle(const executor_type& ex, const native_handle_type& native_handle) : impl_(0, ex) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), native_handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Construct an overlapped handle on an existing native handle. /** * This constructor creates an overlapped handle object to hold an existing * native handle. * * @param context An execution context which provides the I/O executor that * the overlapped handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the overlapped handle. * * @param native_handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ template <typename ExecutionContext> basic_overlapped_handle(ExecutionContext& context, const native_handle_type& native_handle, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) : impl_(0, 0, context) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), native_handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Move-construct an overlapped handle from another. /** * This constructor moves a handle from one object to another. * * @param other The other overlapped handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c overlapped_handle(const executor_type&) * constructor. */ basic_overlapped_handle(basic_overlapped_handle&& other) : impl_(std::move(other.impl_)) { } /// Move-assign an overlapped handle from another. /** * This assignment operator moves a handle from one object to another. * * @param other The other overlapped handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c overlapped_handle(const executor_type&) * constructor. */ basic_overlapped_handle& operator=(basic_overlapped_handle&& other) { impl_ = std::move(other.impl_); return *this; } // All overlapped handles have access to each other's implementations. template <typename Executor1> friend class basic_overlapped_handle; /// Move-construct an overlapped handle from a handle of another executor /// type. /** * This constructor moves a handle from one object to another. * * @param other The other overlapped handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c overlapped_handle(const executor_type&) * constructor. */ template<typename Executor1> basic_overlapped_handle(basic_overlapped_handle<Executor1>&& other, constraint_t< is_convertible<Executor1, Executor>::value, defaulted_constraint > = defaulted_constraint()) : impl_(std::move(other.impl_)) { } /// Move-assign an overlapped handle from a handle of another executor type. /** * This assignment operator moves a handle from one object to another. * * @param other The other overlapped handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c overlapped_handle(const executor_type&) * constructor. */ template<typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_overlapped_handle& > operator=(basic_overlapped_handle<Executor1>&& other) { impl_ = std::move(other.impl_); return *this; } /// Get the executor associated with the object. const executor_type& get_executor() noexcept { return impl_.get_executor(); } /// Get a reference to the lowest layer. /** * This function returns a reference to the lowest layer in a stack of * layers. Since an overlapped_handle cannot contain any further layers, it * simply returns a reference to itself. * * @return A reference to the lowest layer in the stack of layers. Ownership * is not transferred to the caller. */ lowest_layer_type& lowest_layer() { return *this; } /// Get a const reference to the lowest layer. /** * This function returns a const reference to the lowest layer in a stack of * layers. Since an overlapped_handle cannot contain any further layers, it * simply returns a reference to itself. * * @return A const reference to the lowest layer in the stack of layers. * Ownership is not transferred to the caller. */ const lowest_layer_type& lowest_layer() const { return *this; } /// Assign an existing native handle to the handle. /* * This function opens the handle to hold an existing native handle. * * @param handle A native handle. * * @throws boost::system::system_error Thrown on failure. */ void assign(const native_handle_type& handle) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Assign an existing native handle to the handle. /* * This function opens the handle to hold an existing native handle. * * @param handle A native handle. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID assign(const native_handle_type& handle, boost::system::error_code& ec) { impl_.get_service().assign(impl_.get_implementation(), handle, ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } /// Determine whether the handle is open. bool is_open() const { return impl_.get_service().is_open(impl_.get_implementation()); } /// Close the handle. /** * This function is used to close the handle. Any asynchronous read or write * operations will be cancelled immediately, and will complete with the * boost::asio::error::operation_aborted error. * * @throws boost::system::system_error Thrown on failure. */ void close() { boost::system::error_code ec; impl_.get_service().close(impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "close"); } /// Close the handle. /** * This function is used to close the handle. Any asynchronous read or write * operations will be cancelled immediately, and will complete with the * boost::asio::error::operation_aborted error. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec) { impl_.get_service().close(impl_.get_implementation(), ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } /// Release ownership of the underlying native handle. /** * This function causes all outstanding asynchronous operations to finish * immediately, and the handlers for cancelled operations will be passed the * boost::asio::error::operation_aborted error. Ownership of the native handle * is then transferred to the caller. * * @throws boost::system::system_error Thrown on failure. * * @note This function is unsupported on Windows versions prior to Windows * 8.1, and will fail with boost::asio::error::operation_not_supported on * these platforms. */ #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \ && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603) __declspec(deprecated("This function always fails with " "operation_not_supported when used on Windows versions " "prior to Windows 8.1.")) #endif native_handle_type release() { boost::system::error_code ec; native_handle_type s = impl_.get_service().release( impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "release"); return s; } /// Release ownership of the underlying native handle. /** * This function causes all outstanding asynchronous operations to finish * immediately, and the handlers for cancelled operations will be passed the * boost::asio::error::operation_aborted error. Ownership of the native handle * is then transferred to the caller. * * @param ec Set to indicate what error occurred, if any. * * @note This function is unsupported on Windows versions prior to Windows * 8.1, and will fail with boost::asio::error::operation_not_supported on * these platforms. */ #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \ && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603) __declspec(deprecated("This function always fails with " "operation_not_supported when used on Windows versions " "prior to Windows 8.1.")) #endif native_handle_type release(boost::system::error_code& ec) { return impl_.get_service().release(impl_.get_implementation(), ec); } /// Get the native handle representation. /** * This function may be used to obtain the underlying representation of the * handle. This is intended to allow access to native handle functionality * that is not otherwise provided. */ native_handle_type native_handle() { return impl_.get_service().native_handle(impl_.get_implementation()); } /// Cancel all asynchronous operations associated with the handle. /** * This function causes all outstanding asynchronous read or write operations * to finish immediately, and the handlers for cancelled operations will be * passed the boost::asio::error::operation_aborted error. * * @throws boost::system::system_error Thrown on failure. */ void cancel() { boost::system::error_code ec; impl_.get_service().cancel(impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "cancel"); } /// Cancel all asynchronous operations associated with the handle. /** * This function causes all outstanding asynchronous read or write operations * to finish immediately, and the handlers for cancelled operations will be * passed the boost::asio::error::operation_aborted error. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec) { impl_.get_service().cancel(impl_.get_implementation(), ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } protected: /// Protected destructor to prevent deletion through this type. /** * This function destroys the handle, cancelling any outstanding asynchronous * wait operations associated with the handle as if by calling @c cancel. */ ~basic_overlapped_handle() { } boost::asio::detail::io_object_impl< boost::asio::detail::win_iocp_handle_service, Executor> impl_; private: // Disallow copying and assignment. basic_overlapped_handle(const basic_overlapped_handle&) = delete; basic_overlapped_handle& operator=( const basic_overlapped_handle&) = delete; }; } // namespace windows } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) // || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_BASIC_OVERLAPPED_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/object_handle.hpp
// // windows/object_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2011 Boris Schaeling ([email protected]) // // 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 BOOST_ASIO_WINDOWS_OBJECT_HANDLE_HPP #define BOOST_ASIO_WINDOWS_OBJECT_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/windows/basic_object_handle.hpp> namespace boost { namespace asio { namespace windows { /// Typedef for the typical usage of an object handle. typedef basic_object_handle<> object_handle; } // namespace windows } // namespace asio } // namespace boost #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_OBJECT_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/stream_handle.hpp
// // windows/stream_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_STREAM_HANDLE_HPP #define BOOST_ASIO_WINDOWS_STREAM_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/windows/basic_stream_handle.hpp> namespace boost { namespace asio { namespace windows { /// Typedef for the typical usage of a stream-oriented handle. typedef basic_stream_handle<> stream_handle; } // namespace windows } // namespace asio } // namespace boost #endif // defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_STREAM_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/overlapped_ptr.hpp
// // windows/overlapped_ptr.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP #define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/win_iocp_overlapped_ptr.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace windows { /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O. /** * A special-purpose smart pointer used to wrap an application handler so that * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. */ class overlapped_ptr : private noncopyable { public: /// Construct an empty overlapped_ptr. overlapped_ptr() : impl_() { } /// Construct an overlapped_ptr to contain the specified handler. template <typename ExecutionContext, typename Handler> explicit overlapped_ptr(ExecutionContext& context, Handler&& handler, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) : impl_(context.get_executor(), static_cast<Handler&&>(handler)) { } /// Construct an overlapped_ptr to contain the specified handler. template <typename Executor, typename Handler> explicit overlapped_ptr(const Executor& ex, Handler&& handler, constraint_t< execution::is_executor<Executor>::value || is_executor<Executor>::value > = 0) : impl_(ex, static_cast<Handler&&>(handler)) { } /// Destructor automatically frees the OVERLAPPED object unless released. ~overlapped_ptr() { } /// Reset to empty. void reset() { impl_.reset(); } /// Reset to contain the specified handler, freeing any current OVERLAPPED /// object. template <typename ExecutionContext, typename Handler> void reset(ExecutionContext& context, Handler&& handler, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) { impl_.reset(context.get_executor(), static_cast<Handler&&>(handler)); } /// Reset to contain the specified handler, freeing any current OVERLAPPED /// object. template <typename Executor, typename Handler> void reset(const Executor& ex, Handler&& handler, constraint_t< execution::is_executor<Executor>::value || is_executor<Executor>::value > = 0) { impl_.reset(ex, static_cast<Handler&&>(handler)); } /// Get the contained OVERLAPPED object. OVERLAPPED* get() { return impl_.get(); } /// Get the contained OVERLAPPED object. const OVERLAPPED* get() const { return impl_.get(); } /// Release ownership of the OVERLAPPED object. OVERLAPPED* release() { return impl_.release(); } /// Post completion notification for overlapped operation. Releases ownership. void complete(const boost::system::error_code& ec, std::size_t bytes_transferred) { impl_.complete(ec, bytes_transferred); } private: detail::win_iocp_overlapped_ptr impl_; }; } // namespace windows } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/basic_stream_handle.hpp
// // windows/basic_stream_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_BASIC_STREAM_HANDLE_HPP #define BOOST_ASIO_WINDOWS_BASIC_STREAM_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/windows/basic_overlapped_handle.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace windows { /// Provides stream-oriented handle functionality. /** * The windows::basic_stream_handle class provides asynchronous and blocking * stream-oriented handle functionality. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. * * @par Concepts: * AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream. */ template <typename Executor = any_io_executor> class basic_stream_handle : public basic_overlapped_handle<Executor> { private: class initiate_async_write_some; class initiate_async_read_some; public: /// The type of the executor associated with the object. typedef Executor executor_type; /// Rebinds the handle type to another executor. template <typename Executor1> struct rebind_executor { /// The handle type when rebound to the specified executor. typedef basic_stream_handle<Executor1> other; }; /// The native representation of a handle. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined native_handle_type; #else typedef boost::asio::detail::win_iocp_handle_service::native_handle_type native_handle_type; #endif /// Construct a stream handle without opening it. /** * This constructor creates a stream handle without opening it. * * @param ex The I/O executor that the stream handle will use, by default, to * dispatch handlers for any asynchronous operations performed on the stream * handle. */ explicit basic_stream_handle(const executor_type& ex) : basic_overlapped_handle<Executor>(ex) { } /// Construct a stream handle without opening it. /** * This constructor creates a stream handle without opening it. The handle * needs to be opened or assigned before data can be written to or read from * it. * * @param context An execution context which provides the I/O executor that * the stream handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the stream handle. */ template <typename ExecutionContext> explicit basic_stream_handle(ExecutionContext& context, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : basic_overlapped_handle<Executor>(context) { } /// Construct a stream handle on an existing native handle. /** * This constructor creates a stream handle object to hold an existing native * handle. * * @param ex The I/O executor that the stream handle will use, by default, to * dispatch handlers for any asynchronous operations performed on the stream * handle. * * @param handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ basic_stream_handle(const executor_type& ex, const native_handle_type& handle) : basic_overlapped_handle<Executor>(ex, handle) { } /// Construct a stream handle on an existing native handle. /** * This constructor creates a stream handle object to hold an existing native * handle. * * @param context An execution context which provides the I/O executor that * the stream handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the stream handle. * * @param handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ template <typename ExecutionContext> basic_stream_handle(ExecutionContext& context, const native_handle_type& handle, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) : basic_overlapped_handle<Executor>(context, handle) { } /// Move-construct a stream handle from another. /** * This constructor moves a stream handle from one object to another. * * @param other The other stream handle object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_stream_handle(const executor_type&) * constructor. */ basic_stream_handle(basic_stream_handle&& other) : basic_overlapped_handle<Executor>(std::move(other)) { } /// Move-assign a stream handle from another. /** * This assignment operator moves a stream handle from one object to * another. * * @param other The other stream handle object from which the move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_stream_handle(const executor_type&) * constructor. */ basic_stream_handle& operator=(basic_stream_handle&& other) { basic_overlapped_handle<Executor>::operator=(std::move(other)); return *this; } /// Move-construct a stream handle from a handle of another executor type. /** * This constructor moves a stream handle from one object to another. * * @param other The other stream handle object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_stream_handle(const executor_type&) * constructor. */ template<typename Executor1> basic_stream_handle(basic_stream_handle<Executor1>&& other, constraint_t< is_convertible<Executor1, Executor>::value, defaulted_constraint > = defaulted_constraint()) : basic_overlapped_handle<Executor>(std::move(other)) { } /// Move-assign a stream handle from a handle of another executor type. /** * This assignment operator moves a stream handle from one object to * another. * * @param other The other stream handle object from which the move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_stream_handle(const executor_type&) * constructor. */ template<typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_stream_handle& > operator=(basic_stream_handle<Executor1>&& other) { basic_overlapped_handle<Executor>::operator=(std::move(other)); return *this; } /// Write some data to the handle. /** * This function is used to write data to the stream handle. The function call * will block until one or more bytes of the data has been written * successfully, or until an error occurs. * * @param buffers One or more data buffers to be written to the handle. * * @returns The number of bytes written. * * @throws boost::system::system_error Thrown on failure. An error code of * boost::asio::error::eof indicates that the connection was closed by the * peer. * * @note The write_some operation may not transmit all of the data to the * peer. Consider using the @ref write function if you need to ensure that * all data is written before the blocking operation completes. * * @par Example * To write a single data buffer use the @ref buffer function as follows: * @code * handle.write_some(boost::asio::buffer(data, size)); * @endcode * See the @ref buffer documentation for information on writing multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. */ template <typename ConstBufferSequence> std::size_t write_some(const ConstBufferSequence& buffers) { boost::system::error_code ec; std::size_t s = this->impl_.get_service().write_some( this->impl_.get_implementation(), buffers, ec); boost::asio::detail::throw_error(ec, "write_some"); return s; } /// Write some data to the handle. /** * This function is used to write data to the stream handle. The function call * will block until one or more bytes of the data has been written * successfully, or until an error occurs. * * @param buffers One or more data buffers to be written to the handle. * * @param ec Set to indicate what error occurred, if any. * * @returns The number of bytes written. Returns 0 if an error occurred. * * @note The write_some operation may not transmit all of the data to the * peer. Consider using the @ref write function if you need to ensure that * all data is written before the blocking operation completes. */ template <typename ConstBufferSequence> std::size_t write_some(const ConstBufferSequence& buffers, boost::system::error_code& ec) { return this->impl_.get_service().write_some( this->impl_.get_implementation(), buffers, ec); } /// Start an asynchronous write. /** * This function is used to asynchronously write data to the stream handle. * It is an initiating function for an @ref asynchronous_operation, and always * returns immediately. * * @param buffers One or more data buffers to be written to the handle. * Although the buffers object may be copied as necessary, ownership of the * underlying memory blocks is retained by the caller, which must guarantee * that they remain valid until the completion handler is called. * * @param token The @ref completion_token that will be used to produce a * completion handler, which will be called when the write completes. * Potential completion tokens include @ref use_future, @ref use_awaitable, * @ref yield_context, or a function object with the correct completion * signature. The function signature of the completion handler must be: * @code void handler( * const boost::system::error_code& error, // Result of operation. * std::size_t bytes_transferred // Number of bytes written. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the completion handler will not be invoked from within this function. * On immediate completion, invocation of the handler will be performed in a * manner equivalent to using boost::asio::post(). * * @par Completion Signature * @code void(boost::system::error_code, std::size_t) @endcode * * @note The write operation may not transmit all of the data to the peer. * Consider using the @ref async_write function if you need to ensure that all * data is written before the asynchronous operation completes. * * @par Example * To write a single data buffer use the @ref buffer function as follows: * @code * handle.async_write_some(boost::asio::buffer(data, size), handler); * @endcode * See the @ref buffer documentation for information on writing multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. * * @par Per-Operation Cancellation * This asynchronous operation supports cancellation for the following * boost::asio::cancellation_type values: * * @li @c cancellation_type::terminal * * @li @c cancellation_type::partial * * @li @c cancellation_type::total */ template <typename ConstBufferSequence, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) WriteToken = default_completion_token_t<executor_type>> auto async_write_some(const ConstBufferSequence& buffers, WriteToken&& token = default_completion_token_t<executor_type>()) -> decltype( async_initiate<WriteToken, void (boost::system::error_code, std::size_t)>( declval<initiate_async_write_some>(), token, buffers)) { return async_initiate<WriteToken, void (boost::system::error_code, std::size_t)>( initiate_async_write_some(this), token, buffers); } /// Read some data from the handle. /** * This function is used to read data from the stream handle. The function * call will block until one or more bytes of data has been read successfully, * or until an error occurs. * * @param buffers One or more buffers into which the data will be read. * * @returns The number of bytes read. * * @throws boost::system::system_error Thrown on failure. An error code of * boost::asio::error::eof indicates that the connection was closed by the * peer. * * @note The read_some operation may not read all of the requested number of * bytes. Consider using the @ref read function if you need to ensure that * the requested amount of data is read before the blocking operation * completes. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code * handle.read_some(boost::asio::buffer(data, size)); * @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. */ template <typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence& buffers) { boost::system::error_code ec; std::size_t s = this->impl_.get_service().read_some( this->impl_.get_implementation(), buffers, ec); boost::asio::detail::throw_error(ec, "read_some"); return s; } /// Read some data from the handle. /** * This function is used to read data from the stream handle. The function * call will block until one or more bytes of data has been read successfully, * or until an error occurs. * * @param buffers One or more buffers into which the data will be read. * * @param ec Set to indicate what error occurred, if any. * * @returns The number of bytes read. Returns 0 if an error occurred. * * @note The read_some operation may not read all of the requested number of * bytes. Consider using the @ref read function if you need to ensure that * the requested amount of data is read before the blocking operation * completes. */ template <typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence& buffers, boost::system::error_code& ec) { return this->impl_.get_service().read_some( this->impl_.get_implementation(), buffers, ec); } /// Start an asynchronous read. /** * This function is used to asynchronously read data from the stream handle. * It is an initiating function for an @ref asynchronous_operation, and always * returns immediately. * * @param buffers One or more buffers into which the data will be read. * Although the buffers object may be copied as necessary, ownership of the * underlying memory blocks is retained by the caller, which must guarantee * that they remain valid until the completion handler is called. * * @param token The @ref completion_token that will be used to produce a * completion handler, which will be called when the read completes. * Potential completion tokens include @ref use_future, @ref use_awaitable, * @ref yield_context, or a function object with the correct completion * signature. The function signature of the completion handler must be: * @code void handler( * const boost::system::error_code& error, // Result of operation. * std::size_t bytes_transferred // Number of bytes read. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the completion handler will not be invoked from within this function. * On immediate completion, invocation of the handler will be performed in a * manner equivalent to using boost::asio::post(). * * @par Completion Signature * @code void(boost::system::error_code, std::size_t) @endcode * * @note The read operation may not read all of the requested number of bytes. * Consider using the @ref async_read function if you need to ensure that the * requested amount of data is read before the asynchronous operation * completes. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code * handle.async_read_some(boost::asio::buffer(data, size), handler); * @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. * * @par Per-Operation Cancellation * This asynchronous operation supports cancellation for the following * boost::asio::cancellation_type values: * * @li @c cancellation_type::terminal * * @li @c cancellation_type::partial * * @li @c cancellation_type::total */ template <typename MutableBufferSequence, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) ReadToken = default_completion_token_t<executor_type>> auto async_read_some(const MutableBufferSequence& buffers, ReadToken&& token = default_completion_token_t<executor_type>()) -> decltype( async_initiate<ReadToken, void (boost::system::error_code, std::size_t)>( declval<initiate_async_read_some>(), token, buffers)) { return async_initiate<ReadToken, void (boost::system::error_code, std::size_t)>( initiate_async_read_some(this), token, buffers); } private: class initiate_async_write_some { public: typedef Executor executor_type; explicit initiate_async_write_some(basic_stream_handle* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename WriteHandler, typename ConstBufferSequence> void operator()(WriteHandler&& handler, const ConstBufferSequence& buffers) const { // If you get an error on the following line it means that your handler // does not meet the documented type requirements for a WriteHandler. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; detail::non_const_lvalue<WriteHandler> handler2(handler); self_->impl_.get_service().async_write_some( self_->impl_.get_implementation(), buffers, handler2.value, self_->impl_.get_executor()); } private: basic_stream_handle* self_; }; class initiate_async_read_some { public: typedef Executor executor_type; explicit initiate_async_read_some(basic_stream_handle* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename ReadHandler, typename MutableBufferSequence> void operator()(ReadHandler&& handler, const MutableBufferSequence& buffers) const { // If you get an error on the following line it means that your handler // does not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; detail::non_const_lvalue<ReadHandler> handler2(handler); self_->impl_.get_service().async_read_some( self_->impl_.get_implementation(), buffers, handler2.value, self_->impl_.get_executor()); } private: basic_stream_handle* self_; }; }; } // namespace windows } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_BASIC_STREAM_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/basic_random_access_handle.hpp
// // windows/basic_random_access_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_BASIC_RANDOM_ACCESS_HANDLE_HPP #define BOOST_ASIO_WINDOWS_BASIC_RANDOM_ACCESS_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/windows/basic_overlapped_handle.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace windows { /// Provides random-access handle functionality. /** * The windows::basic_random_access_handle class provides asynchronous and * blocking random-access handle functionality. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. */ template <typename Executor = any_io_executor> class basic_random_access_handle : public basic_overlapped_handle<Executor> { private: class initiate_async_write_some_at; class initiate_async_read_some_at; public: /// The type of the executor associated with the object. typedef Executor executor_type; /// Rebinds the handle type to another executor. template <typename Executor1> struct rebind_executor { /// The handle type when rebound to the specified executor. typedef basic_random_access_handle<Executor1> other; }; /// The native representation of a handle. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined native_handle_type; #else typedef boost::asio::detail::win_iocp_handle_service::native_handle_type native_handle_type; #endif /// Construct a random-access handle without opening it. /** * This constructor creates a random-access handle without opening it. * * @param ex The I/O executor that the random-access handle will use, by * default, to dispatch handlers for any asynchronous operations performed on * the random-access handle. */ explicit basic_random_access_handle(const executor_type& ex) : basic_overlapped_handle<Executor>(ex) { } /// Construct a random-access handle without opening it. /** * This constructor creates a random-access handle without opening it. The * handle needs to be opened or assigned before data can be written to or read * from it. * * @param context An execution context which provides the I/O executor that * the random-access handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the random-access handle. */ template <typename ExecutionContext> explicit basic_random_access_handle(ExecutionContext& context, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : basic_overlapped_handle<Executor>(context) { } /// Construct a random-access handle on an existing native handle. /** * This constructor creates a random-access handle object to hold an existing * native handle. * * @param ex The I/O executor that the random-access handle will use, by * default, to dispatch handlers for any asynchronous operations performed on * the random-access handle. * * @param handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ basic_random_access_handle(const executor_type& ex, const native_handle_type& handle) : basic_overlapped_handle<Executor>(ex, handle) { } /// Construct a random-access handle on an existing native handle. /** * This constructor creates a random-access handle object to hold an existing * native handle. * * @param context An execution context which provides the I/O executor that * the random-access handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the random-access handle. * * @param handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ template <typename ExecutionContext> basic_random_access_handle(ExecutionContext& context, const native_handle_type& handle, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) : basic_overlapped_handle<Executor>(context, handle) { } /// Move-construct a random-access handle from another. /** * This constructor moves a random-access handle from one object to another. * * @param other The other random-access handle object from which the * move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_random_access_handle(const executor_type&) * constructor. */ basic_random_access_handle(basic_random_access_handle&& other) : basic_overlapped_handle<Executor>(std::move(other)) { } /// Move-assign a random-access handle from another. /** * This assignment operator moves a random-access handle from one object to * another. * * @param other The other random-access handle object from which the * move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_random_access_handle(const executor_type&) * constructor. */ basic_random_access_handle& operator=(basic_random_access_handle&& other) { basic_overlapped_handle<Executor>::operator=(std::move(other)); return *this; } /// Move-construct a random-access handle from a handle of another executor /// type. /** * This constructor moves a random-access handle from one object to another. * * @param other The other random-access handle object from which the * move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_random_access_handle(const executor_type&) * constructor. */ template<typename Executor1> basic_random_access_handle(basic_random_access_handle<Executor1>&& other, constraint_t< is_convertible<Executor1, Executor>::value, defaulted_constraint > = defaulted_constraint()) : basic_overlapped_handle<Executor>(std::move(other)) { } /// Move-assign a random-access handle from a handle of another executor /// type. /** * This assignment operator moves a random-access handle from one object to * another. * * @param other The other random-access handle object from which the * move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_random_access_handle(const executor_type&) * constructor. */ template<typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_random_access_handle& > operator=(basic_random_access_handle<Executor1>&& other) { basic_overlapped_handle<Executor>::operator=(std::move(other)); return *this; } /// Write some data to the handle at the specified offset. /** * This function is used to write data to the random-access handle. The * function call will block until one or more bytes of the data has been * written successfully, or until an error occurs. * * @param offset The offset at which the data will be written. * * @param buffers One or more data buffers to be written to the handle. * * @returns The number of bytes written. * * @throws boost::system::system_error Thrown on failure. An error code of * boost::asio::error::eof indicates that the connection was closed by the * peer. * * @note The write_some_at operation may not write all of the data. Consider * using the @ref write_at function if you need to ensure that all data is * written before the blocking operation completes. * * @par Example * To write a single data buffer use the @ref buffer function as follows: * @code * handle.write_some_at(42, boost::asio::buffer(data, size)); * @endcode * See the @ref buffer documentation for information on writing multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. */ template <typename ConstBufferSequence> std::size_t write_some_at(uint64_t offset, const ConstBufferSequence& buffers) { boost::system::error_code ec; std::size_t s = this->impl_.get_service().write_some_at( this->impl_.get_implementation(), offset, buffers, ec); boost::asio::detail::throw_error(ec, "write_some_at"); return s; } /// Write some data to the handle at the specified offset. /** * This function is used to write data to the random-access handle. The * function call will block until one or more bytes of the data has been * written successfully, or until an error occurs. * * @param offset The offset at which the data will be written. * * @param buffers One or more data buffers to be written to the handle. * * @param ec Set to indicate what error occurred, if any. * * @returns The number of bytes written. Returns 0 if an error occurred. * * @note The write_some operation may not transmit all of the data to the * peer. Consider using the @ref write_at function if you need to ensure that * all data is written before the blocking operation completes. */ template <typename ConstBufferSequence> std::size_t write_some_at(uint64_t offset, const ConstBufferSequence& buffers, boost::system::error_code& ec) { return this->impl_.get_service().write_some_at( this->impl_.get_implementation(), offset, buffers, ec); } /// Start an asynchronous write at the specified offset. /** * This function is used to asynchronously write data to the random-access * handle. It is an initiating function for an @ref asynchronous_operation, * and always returns immediately. * * @param offset The offset at which the data will be written. * * @param buffers One or more data buffers to be written to the handle. * Although the buffers object may be copied as necessary, ownership of the * underlying memory blocks is retained by the caller, which must guarantee * that they remain valid until the completion handler is called. * * @param token The @ref completion_token that will be used to produce a * completion handler, which will be called when the write completes. * Potential completion tokens include @ref use_future, @ref use_awaitable, * @ref yield_context, or a function object with the correct completion * signature. The function signature of the completion handler must be: * @code void handler( * const boost::system::error_code& error, // Result of operation. * std::size_t bytes_transferred // Number of bytes written. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the completion handler will not be invoked from within this function. * On immediate completion, invocation of the handler will be performed in a * manner equivalent to using boost::asio::post(). * * @par Completion Signature * @code void(boost::system::error_code, std::size_t) @endcode * * @note The write operation may not transmit all of the data to the peer. * Consider using the @ref async_write_at function if you need to ensure that * all data is written before the asynchronous operation completes. * * @par Example * To write a single data buffer use the @ref buffer function as follows: * @code * handle.async_write_some_at(42, boost::asio::buffer(data, size), handler); * @endcode * See the @ref buffer documentation for information on writing multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. * * @par Per-Operation Cancellation * This asynchronous operation supports cancellation for the following * boost::asio::cancellation_type values: * * @li @c cancellation_type::terminal * * @li @c cancellation_type::partial * * @li @c cancellation_type::total */ template <typename ConstBufferSequence, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) WriteToken = default_completion_token_t<executor_type>> auto async_write_some_at(uint64_t offset, const ConstBufferSequence& buffers, WriteToken&& token = default_completion_token_t<executor_type>()) -> decltype( async_initiate<WriteToken, void (boost::system::error_code, std::size_t)>( declval<initiate_async_write_some_at>(), token, offset, buffers)) { return async_initiate<WriteToken, void (boost::system::error_code, std::size_t)>( initiate_async_write_some_at(this), token, offset, buffers); } /// Read some data from the handle at the specified offset. /** * This function is used to read data from the random-access handle. The * function call will block until one or more bytes of data has been read * successfully, or until an error occurs. * * @param offset The offset at which the data will be read. * * @param buffers One or more buffers into which the data will be read. * * @returns The number of bytes read. * * @throws boost::system::system_error Thrown on failure. An error code of * boost::asio::error::eof indicates that the connection was closed by the * peer. * * @note The read_some operation may not read all of the requested number of * bytes. Consider using the @ref read_at function if you need to ensure that * the requested amount of data is read before the blocking operation * completes. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code * handle.read_some_at(42, boost::asio::buffer(data, size)); * @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. */ template <typename MutableBufferSequence> std::size_t read_some_at(uint64_t offset, const MutableBufferSequence& buffers) { boost::system::error_code ec; std::size_t s = this->impl_.get_service().read_some_at( this->impl_.get_implementation(), offset, buffers, ec); boost::asio::detail::throw_error(ec, "read_some_at"); return s; } /// Read some data from the handle at the specified offset. /** * This function is used to read data from the random-access handle. The * function call will block until one or more bytes of data has been read * successfully, or until an error occurs. * * @param offset The offset at which the data will be read. * * @param buffers One or more buffers into which the data will be read. * * @param ec Set to indicate what error occurred, if any. * * @returns The number of bytes read. Returns 0 if an error occurred. * * @note The read_some operation may not read all of the requested number of * bytes. Consider using the @ref read_at function if you need to ensure that * the requested amount of data is read before the blocking operation * completes. */ template <typename MutableBufferSequence> std::size_t read_some_at(uint64_t offset, const MutableBufferSequence& buffers, boost::system::error_code& ec) { return this->impl_.get_service().read_some_at( this->impl_.get_implementation(), offset, buffers, ec); } /// Start an asynchronous read at the specified offset. /** * This function is used to asynchronously read data from the random-access * handle. It is an initiating function for an @ref asynchronous_operation, * and always returns immediately. * * @param offset The offset at which the data will be read. * * @param buffers One or more buffers into which the data will be read. * Although the buffers object may be copied as necessary, ownership of the * underlying memory blocks is retained by the caller, which must guarantee * that they remain valid until the completion handler is called. * * @param token The @ref completion_token that will be used to produce a * completion handler, which will be called when the read completes. * Potential completion tokens include @ref use_future, @ref use_awaitable, * @ref yield_context, or a function object with the correct completion * signature. The function signature of the completion handler must be: * @code void handler( * const boost::system::error_code& error, // Result of operation. * std::size_t bytes_transferred // Number of bytes read. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the completion handler will not be invoked from within this function. * On immediate completion, invocation of the handler will be performed in a * manner equivalent to using boost::asio::post(). * * @par Completion Signature * @code void(boost::system::error_code, std::size_t) @endcode * * @note The read operation may not read all of the requested number of bytes. * Consider using the @ref async_read_at function if you need to ensure that * the requested amount of data is read before the asynchronous operation * completes. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code * handle.async_read_some_at(42, boost::asio::buffer(data, size), handler); * @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. * * @par Per-Operation Cancellation * This asynchronous operation supports cancellation for the following * boost::asio::cancellation_type values: * * @li @c cancellation_type::terminal * * @li @c cancellation_type::partial * * @li @c cancellation_type::total */ template <typename MutableBufferSequence, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code, std::size_t)) ReadToken = default_completion_token_t<executor_type>> auto async_read_some_at(uint64_t offset, const MutableBufferSequence& buffers, ReadToken&& token = default_completion_token_t<executor_type>()) -> decltype( async_initiate<ReadToken, void (boost::system::error_code, std::size_t)>( declval<initiate_async_read_some_at>(), token, offset, buffers)) { return async_initiate<ReadToken, void (boost::system::error_code, std::size_t)>( initiate_async_read_some_at(this), token, offset, buffers); } private: class initiate_async_write_some_at { public: typedef Executor executor_type; explicit initiate_async_write_some_at(basic_random_access_handle* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename WriteHandler, typename ConstBufferSequence> void operator()(WriteHandler&& handler, uint64_t offset, const ConstBufferSequence& buffers) const { // If you get an error on the following line it means that your handler // does not meet the documented type requirements for a WriteHandler. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; detail::non_const_lvalue<WriteHandler> handler2(handler); self_->impl_.get_service().async_write_some_at( self_->impl_.get_implementation(), offset, buffers, handler2.value, self_->impl_.get_executor()); } private: basic_random_access_handle* self_; }; class initiate_async_read_some_at { public: typedef Executor executor_type; explicit initiate_async_read_some_at(basic_random_access_handle* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename ReadHandler, typename MutableBufferSequence> void operator()(ReadHandler&& handler, uint64_t offset, const MutableBufferSequence& buffers) const { // If you get an error on the following line it means that your handler // does not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; detail::non_const_lvalue<ReadHandler> handler2(handler); self_->impl_.get_service().async_read_some_at( self_->impl_.get_implementation(), offset, buffers, handler2.value, self_->impl_.get_executor()); } private: basic_random_access_handle* self_; }; }; } // namespace windows } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_BASIC_RANDOM_ACCESS_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/random_access_handle.hpp
// // windows/random_access_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_HPP #define BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/windows/basic_random_access_handle.hpp> namespace boost { namespace asio { namespace windows { /// Typedef for the typical usage of a random-access handle. typedef basic_random_access_handle<> random_access_handle; } // namespace windows } // namespace asio } // namespace boost #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/overlapped_handle.hpp
// // windows/overlapped_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_WINDOWS_OVERLAPPED_HANDLE_HPP #define BOOST_ASIO_WINDOWS_OVERLAPPED_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \ || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/windows/basic_overlapped_handle.hpp> namespace boost { namespace asio { namespace windows { /// Typedef for the typical usage of an overlapped handle. typedef basic_overlapped_handle<> overlapped_handle; } // namespace windows } // namespace asio } // namespace boost #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) // || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/windows/basic_object_handle.hpp
// // windows/basic_object_handle.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2011 Boris Schaeling ([email protected]) // // 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 BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP #define BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \ || defined(GENERATING_DOCUMENTATION) #include <utility> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/io_object_impl.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/detail/win_object_handle_service.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace windows { /// Provides object-oriented handle functionality. /** * The windows::basic_object_handle class provides asynchronous and blocking * object-oriented handle functionality. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. */ template <typename Executor = any_io_executor> class basic_object_handle { private: class initiate_async_wait; public: /// The type of the executor associated with the object. typedef Executor executor_type; /// Rebinds the handle type to another executor. template <typename Executor1> struct rebind_executor { /// The handle type when rebound to the specified executor. typedef basic_object_handle<Executor1> other; }; /// The native representation of a handle. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined native_handle_type; #else typedef boost::asio::detail::win_object_handle_service::native_handle_type native_handle_type; #endif /// An object handle is always the lowest layer. typedef basic_object_handle lowest_layer_type; /// Construct an object handle without opening it. /** * This constructor creates an object handle without opening it. * * @param ex The I/O executor that the object handle will use, by default, to * dispatch handlers for any asynchronous operations performed on the * object handle. */ explicit basic_object_handle(const executor_type& ex) : impl_(0, ex) { } /// Construct an object handle without opening it. /** * This constructor creates an object handle without opening it. * * @param context An execution context which provides the I/O executor that * the object handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the object handle. */ template <typename ExecutionContext> explicit basic_object_handle(ExecutionContext& context, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : impl_(0, 0, context) { } /// Construct an object handle on an existing native handle. /** * This constructor creates an object handle object to hold an existing native * handle. * * @param ex The I/O executor that the object handle will use, by default, to * dispatch handlers for any asynchronous operations performed on the * object handle. * * @param native_handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ basic_object_handle(const executor_type& ex, const native_handle_type& native_handle) : impl_(0, ex) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), native_handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Construct an object handle on an existing native handle. /** * This constructor creates an object handle object to hold an existing native * handle. * * @param context An execution context which provides the I/O executor that * the object handle will use, by default, to dispatch handlers for any * asynchronous operations performed on the object handle. * * @param native_handle The new underlying handle implementation. * * @throws boost::system::system_error Thrown on failure. */ template <typename ExecutionContext> basic_object_handle(ExecutionContext& context, const native_handle_type& native_handle, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value > = 0) : impl_(0, 0, context) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), native_handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Move-construct an object handle from another. /** * This constructor moves an object handle from one object to another. * * @param other The other object handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_object_handle(const executor_type&) * constructor. */ basic_object_handle(basic_object_handle&& other) : impl_(std::move(other.impl_)) { } /// Move-assign an object handle from another. /** * This assignment operator moves an object handle from one object to another. * * @param other The other object handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_object_handle(const executor_type&) * constructor. */ basic_object_handle& operator=(basic_object_handle&& other) { impl_ = std::move(other.impl_); return *this; } // All handles have access to each other's implementations. template <typename Executor1> friend class basic_object_handle; /// Move-construct an object handle from a handle of another executor type. /** * This constructor moves an object handle from one object to another. * * @param other The other object handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_object_handle(const executor_type&) * constructor. */ template<typename Executor1> basic_object_handle(basic_object_handle<Executor1>&& other, constraint_t< is_convertible<Executor1, Executor>::value, defaulted_constraint > = defaulted_constraint()) : impl_(std::move(other.impl_)) { } /// Move-assign an object handle from a handle of another executor type. /** * This assignment operator moves an object handle from one object to another. * * @param other The other object handle object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_object_handle(const executor_type&) * constructor. */ template<typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_object_handle& > operator=(basic_object_handle<Executor1>&& other) { impl_ = std::move(other.impl_); return *this; } /// Get the executor associated with the object. const executor_type& get_executor() noexcept { return impl_.get_executor(); } /// Get a reference to the lowest layer. /** * This function returns a reference to the lowest layer in a stack of * layers. Since an object handle cannot contain any further layers, it simply * returns a reference to itself. * * @return A reference to the lowest layer in the stack of layers. Ownership * is not transferred to the caller. */ lowest_layer_type& lowest_layer() { return *this; } /// Get a const reference to the lowest layer. /** * This function returns a const reference to the lowest layer in a stack of * layers. Since an object handle cannot contain any further layers, it simply * returns a reference to itself. * * @return A const reference to the lowest layer in the stack of layers. * Ownership is not transferred to the caller. */ const lowest_layer_type& lowest_layer() const { return *this; } /// Assign an existing native handle to the handle. /* * This function opens the handle to hold an existing native handle. * * @param handle A native handle. * * @throws boost::system::system_error Thrown on failure. */ void assign(const native_handle_type& handle) { boost::system::error_code ec; impl_.get_service().assign(impl_.get_implementation(), handle, ec); boost::asio::detail::throw_error(ec, "assign"); } /// Assign an existing native handle to the handle. /* * This function opens the handle to hold an existing native handle. * * @param handle A native handle. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID assign(const native_handle_type& handle, boost::system::error_code& ec) { impl_.get_service().assign(impl_.get_implementation(), handle, ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } /// Determine whether the handle is open. bool is_open() const { return impl_.get_service().is_open(impl_.get_implementation()); } /// Close the handle. /** * This function is used to close the handle. Any asynchronous read or write * operations will be cancelled immediately, and will complete with the * boost::asio::error::operation_aborted error. * * @throws boost::system::system_error Thrown on failure. */ void close() { boost::system::error_code ec; impl_.get_service().close(impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "close"); } /// Close the handle. /** * This function is used to close the handle. Any asynchronous read or write * operations will be cancelled immediately, and will complete with the * boost::asio::error::operation_aborted error. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec) { impl_.get_service().close(impl_.get_implementation(), ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } /// Get the native handle representation. /** * This function may be used to obtain the underlying representation of the * handle. This is intended to allow access to native handle functionality * that is not otherwise provided. */ native_handle_type native_handle() { return impl_.get_service().native_handle(impl_.get_implementation()); } /// Cancel all asynchronous operations associated with the handle. /** * This function causes all outstanding asynchronous read or write operations * to finish immediately, and the handlers for cancelled operations will be * passed the boost::asio::error::operation_aborted error. * * @throws boost::system::system_error Thrown on failure. */ void cancel() { boost::system::error_code ec; impl_.get_service().cancel(impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "cancel"); } /// Cancel all asynchronous operations associated with the handle. /** * This function causes all outstanding asynchronous read or write operations * to finish immediately, and the handlers for cancelled operations will be * passed the boost::asio::error::operation_aborted error. * * @param ec Set to indicate what error occurred, if any. */ BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec) { impl_.get_service().cancel(impl_.get_implementation(), ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } /// Perform a blocking wait on the object handle. /** * This function is used to wait for the object handle to be set to the * signalled state. This function blocks and does not return until the object * handle has been set to the signalled state. * * @throws boost::system::system_error Thrown on failure. */ void wait() { boost::system::error_code ec; impl_.get_service().wait(impl_.get_implementation(), ec); boost::asio::detail::throw_error(ec, "wait"); } /// Perform a blocking wait on the object handle. /** * This function is used to wait for the object handle to be set to the * signalled state. This function blocks and does not return until the object * handle has been set to the signalled state. * * @param ec Set to indicate what error occurred, if any. */ void wait(boost::system::error_code& ec) { impl_.get_service().wait(impl_.get_implementation(), ec); } /// Start an asynchronous wait on the object handle. /** * This function is be used to initiate an asynchronous wait against the * object handle. It is an initiating function for an @ref * asynchronous_operation, and always returns immediately. * * @param token The @ref completion_token that will be used to produce a * completion handler, which will be called when the wait completes. * Potential completion tokens include @ref use_future, @ref use_awaitable, * @ref yield_context, or a function object with the correct completion * signature. The function signature of the completion handler must be: * @code void handler( * const boost::system::error_code& error // Result of operation. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the completion handler will not be invoked from within this function. * On immediate completion, invocation of the handler will be performed in a * manner equivalent to using boost::asio::post(). * * @par Completion Signature * @code void(boost::system::error_code) @endcode */ template < BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) WaitToken = default_completion_token_t<executor_type>> auto async_wait( WaitToken&& token = default_completion_token_t<executor_type>()) -> decltype( async_initiate<WaitToken, void (boost::system::error_code)>( declval<initiate_async_wait>(), token)) { return async_initiate<WaitToken, void (boost::system::error_code)>( initiate_async_wait(this), token); } private: // Disallow copying and assignment. basic_object_handle(const basic_object_handle&) = delete; basic_object_handle& operator=(const basic_object_handle&) = delete; class initiate_async_wait { public: typedef Executor executor_type; explicit initiate_async_wait(basic_object_handle* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename WaitHandler> void operator()(WaitHandler&& handler) const { // If you get an error on the following line it means that your handler // does not meet the documented type requirements for a WaitHandler. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check; detail::non_const_lvalue<WaitHandler> handler2(handler); self_->impl_.get_service().async_wait( self_->impl_.get_implementation(), handler2.value, self_->impl_.get_executor()); } private: basic_object_handle* self_; }; boost::asio::detail::io_object_impl< boost::asio::detail::win_object_handle_service, Executor> impl_; }; } // namespace windows } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/awaitable_operators.hpp
// // experimental/awaitable_operators.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_AWAITABLE_OPERATORS_HPP #define BOOST_ASIO_EXPERIMENTAL_AWAITABLE_OPERATORS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <optional> #include <stdexcept> #include <tuple> #include <variant> #include <boost/asio/awaitable.hpp> #include <boost/asio/co_spawn.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/experimental/deferred.hpp> #include <boost/asio/experimental/parallel_group.hpp> #include <boost/asio/multiple_exceptions.hpp> #include <boost/asio/this_coro.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace awaitable_operators { namespace detail { template <typename T, typename Executor> awaitable<T, Executor> awaitable_wrap(awaitable<T, Executor> a, constraint_t<is_constructible<T>::value>* = 0) { return a; } template <typename T, typename Executor> awaitable<std::optional<T>, Executor> awaitable_wrap(awaitable<T, Executor> a, constraint_t<!is_constructible<T>::value>* = 0) { co_return std::optional<T>(co_await std::move(a)); } template <typename T> T& awaitable_unwrap(conditional_t<true, T, void>& r, constraint_t<is_constructible<T>::value>* = 0) { return r; } template <typename T> T& awaitable_unwrap(std::optional<conditional_t<true, T, void>>& r, constraint_t<!is_constructible<T>::value>* = 0) { return *r; } } // namespace detail /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename Executor> awaitable<void, Executor> operator&&( awaitable<void, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, ex1] = co_await make_parallel_group( co_spawn(ex, std::move(t), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return; } /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename U, typename Executor> awaitable<U, Executor> operator&&( awaitable<void, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, std::move(t), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return std::move(detail::awaitable_unwrap<U>(r1)); } /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename T, typename Executor> awaitable<T, Executor> operator&&( awaitable<T, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return std::move(detail::awaitable_unwrap<T>(r0)); } /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename T, typename U, typename Executor> awaitable<std::tuple<T, U>, Executor> operator&&( awaitable<T, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return std::make_tuple( std::move(detail::awaitable_unwrap<T>(r0)), std::move(detail::awaitable_unwrap<U>(r1))); } /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename... T, typename Executor> awaitable<std::tuple<T..., std::monostate>, Executor> operator&&( awaitable<std::tuple<T...>, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return std::move(detail::awaitable_unwrap<std::tuple<T...>>(r0)); } /// Wait for both operations to succeed. /** * If one operations fails, the other is cancelled as the AND-condition can no * longer be satisfied. */ template <typename... T, typename U, typename Executor> awaitable<std::tuple<T..., U>, Executor> operator&&( awaitable<std::tuple<T...>, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_error(), deferred ); if (ex0 && ex1) throw multiple_exceptions(ex0); if (ex0) std::rethrow_exception(ex0); if (ex1) std::rethrow_exception(ex1); co_return std::tuple_cat( std::move(detail::awaitable_unwrap<std::tuple<T...>>(r0)), std::make_tuple(std::move(detail::awaitable_unwrap<U>(r1)))); } /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename Executor> awaitable<std::variant<std::monostate, std::monostate>, Executor> operator||( awaitable<void, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, ex1] = co_await make_parallel_group( co_spawn(ex, std::move(t), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_success(), deferred ); if (order[0] == 0) { if (!ex0) co_return std::variant<std::monostate, std::monostate>{ std::in_place_index<0>}; if (!ex1) co_return std::variant<std::monostate, std::monostate>{ std::in_place_index<1>}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<std::monostate, std::monostate>{ std::in_place_index<1>}; if (!ex0) co_return std::variant<std::monostate, std::monostate>{ std::in_place_index<0>}; throw multiple_exceptions(ex1); } } /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename U, typename Executor> awaitable<std::variant<std::monostate, U>, Executor> operator||( awaitable<void, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, std::move(t), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_success(), deferred ); if (order[0] == 0) { if (!ex0) co_return std::variant<std::monostate, U>{ std::in_place_index<0>}; if (!ex1) co_return std::variant<std::monostate, U>{ std::in_place_index<1>, std::move(detail::awaitable_unwrap<U>(r1))}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<std::monostate, U>{ std::in_place_index<1>, std::move(detail::awaitable_unwrap<U>(r1))}; if (!ex0) co_return std::variant<std::monostate, U>{ std::in_place_index<0>}; throw multiple_exceptions(ex1); } } /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename T, typename Executor> awaitable<std::variant<T, std::monostate>, Executor> operator||( awaitable<T, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_success(), deferred ); if (order[0] == 0) { if (!ex0) co_return std::variant<T, std::monostate>{ std::in_place_index<0>, std::move(detail::awaitable_unwrap<T>(r0))}; if (!ex1) co_return std::variant<T, std::monostate>{ std::in_place_index<1>}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<T, std::monostate>{ std::in_place_index<1>}; if (!ex0) co_return std::variant<T, std::monostate>{ std::in_place_index<0>, std::move(detail::awaitable_unwrap<T>(r0))}; throw multiple_exceptions(ex1); } } /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename T, typename U, typename Executor> awaitable<std::variant<T, U>, Executor> operator||( awaitable<T, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_success(), deferred ); if (order[0] == 0) { if (!ex0) co_return std::variant<T, U>{ std::in_place_index<0>, std::move(detail::awaitable_unwrap<T>(r0))}; if (!ex1) co_return std::variant<T, U>{ std::in_place_index<1>, std::move(detail::awaitable_unwrap<U>(r1))}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<T, U>{ std::in_place_index<1>, std::move(detail::awaitable_unwrap<U>(r1))}; if (!ex0) co_return std::variant<T, U>{ std::in_place_index<0>, std::move(detail::awaitable_unwrap<T>(r0))}; throw multiple_exceptions(ex1); } } namespace detail { template <typename... T> struct widen_variant { template <std::size_t I, typename SourceVariant> static std::variant<T...> call(SourceVariant& source) { if (source.index() == I) return std::variant<T...>{ std::in_place_index<I>, std::move(std::get<I>(source))}; else if constexpr (I + 1 < std::variant_size_v<SourceVariant>) return call<I + 1>(source); else throw std::logic_error("empty variant"); } }; } // namespace detail /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename... T, typename Executor> awaitable<std::variant<T..., std::monostate>, Executor> operator||( awaitable<std::variant<T...>, Executor> t, awaitable<void, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, std::move(u), deferred) ).async_wait( wait_for_one_success(), deferred ); using widen = detail::widen_variant<T..., std::monostate>; if (order[0] == 0) { if (!ex0) co_return widen::template call<0>( detail::awaitable_unwrap<std::variant<T...>>(r0)); if (!ex1) co_return std::variant<T..., std::monostate>{ std::in_place_index<sizeof...(T)>}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<T..., std::monostate>{ std::in_place_index<sizeof...(T)>}; if (!ex0) co_return widen::template call<0>( detail::awaitable_unwrap<std::variant<T...>>(r0)); throw multiple_exceptions(ex1); } } /// Wait for one operation to succeed. /** * If one operations succeeds, the other is cancelled as the OR-condition is * already satisfied. */ template <typename... T, typename U, typename Executor> awaitable<std::variant<T..., U>, Executor> operator||( awaitable<std::variant<T...>, Executor> t, awaitable<U, Executor> u) { auto ex = co_await this_coro::executor; auto [order, ex0, r0, ex1, r1] = co_await make_parallel_group( co_spawn(ex, detail::awaitable_wrap(std::move(t)), deferred), co_spawn(ex, detail::awaitable_wrap(std::move(u)), deferred) ).async_wait( wait_for_one_success(), deferred ); using widen = detail::widen_variant<T..., U>; if (order[0] == 0) { if (!ex0) co_return widen::template call<0>( detail::awaitable_unwrap<std::variant<T...>>(r0)); if (!ex1) co_return std::variant<T..., U>{ std::in_place_index<sizeof...(T)>, std::move(detail::awaitable_unwrap<U>(r1))}; throw multiple_exceptions(ex0); } else { if (!ex1) co_return std::variant<T..., U>{ std::in_place_index<sizeof...(T)>, std::move(detail::awaitable_unwrap<U>(r1))}; if (!ex0) co_return widen::template call<0>( detail::awaitable_unwrap<std::variant<T...>>(r0)); throw multiple_exceptions(ex1); } } } // namespace awaitable_operators } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_AWAITABLE_OPERATORS_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/deferred.hpp
// // experimental/deferred.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DEFERRED_HPP #define BOOST_ASIO_EXPERIMENTAL_DEFERRED_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { #if !defined(BOOST_ASIO_NO_DEPRECATED) using boost::asio::deferred_t; using boost::asio::deferred; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DEFERRED_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/promise.hpp
// // experimental/promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_PROMISE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/cancellation_signal.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/experimental/impl/promise.hpp> #include <boost/asio/post.hpp> #include <algorithm> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { template <typename T> struct is_promise : std::false_type {}; template <typename ... Ts> struct is_promise<promise<Ts...>> : std::true_type {}; template <typename T> constexpr bool is_promise_v = is_promise<T>::value; template <typename ... Ts> struct promise_value_type { using type = std::tuple<Ts...>; }; template <typename T> struct promise_value_type<T> { using type = T; }; template <> struct promise_value_type<> { using type = std::tuple<>; }; #if defined(GENERATING_DOCUMENTATION) /// A disposable handle for an eager operation. /** * @tparam Signature The signature of the operation. * * @tparam Executor The executor to be used by the promise (taken from the * operation). * * @tparam Allocator The allocator used for the promise. Can be set through * use_allocator. * * A promise can be used to initiate an asynchronous option that can be * completed later. If the promise gets destroyed before completion, the * operation gets a cancel signal and the result is ignored. * * A promise fulfills the requirements of async_operation. * * @par Examples * Reading and writing from one coroutine. * @code * awaitable<void> read_write_some(boost::asio::ip::tcp::socket & sock, * boost::asio::mutable_buffer read_buf, boost::asio::const_buffer to_write) * { * auto p = boost::asio::async_read(read_buf, boost::asio::use_awaitable); * co_await boost::asio::async_write_some(to_write, boost::asio::deferred); * co_await p; * } * @endcode */ template<typename Signature = void(), typename Executor = boost::asio::any_io_executor, typename Allocator = std::allocator<void>> struct promise #else template <typename ... Ts, typename Executor, typename Allocator> struct promise<void(Ts...), Executor, Allocator> #endif // defined(GENERATING_DOCUMENTATION) { /// The value that's returned by the promise. using value_type = typename promise_value_type<Ts...>::type; /// Cancel the promise. Usually done through the destructor. void cancel(cancellation_type level = cancellation_type::all) { if (impl_ && !impl_->done) { boost::asio::dispatch(impl_->executor, [level, impl = impl_]{ impl->cancel.emit(level); }); } } /// Check if the promise is completed already. bool completed() const noexcept { return impl_ && impl_->done; } /// Wait for the promise to become ready. template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(Ts...)) CompletionToken> inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(Ts...)) operator()(CompletionToken&& token) { assert(impl_); return async_initiate<CompletionToken, void(Ts...)>( initiate_async_wait{impl_}, token); } promise() = delete; promise(const promise& ) = delete; promise(promise&& ) noexcept = default; /// Destruct the promise and cancel the operation. /** * It is safe to destruct a promise of a promise that didn't complete. */ ~promise() { cancel(); } private: #if !defined(GENERATING_DOCUMENTATION) template <typename, typename, typename> friend struct promise; friend struct detail::promise_handler<void(Ts...), Executor, Allocator>; #endif // !defined(GENERATING_DOCUMENTATION) std::shared_ptr<detail::promise_impl< void(Ts...), Executor, Allocator>> impl_; promise( std::shared_ptr<detail::promise_impl< void(Ts...), Executor, Allocator>> impl) : impl_(impl) { } struct initiate_async_wait { std::shared_ptr<detail::promise_impl< void(Ts...), Executor, Allocator>> self_; template <typename WaitHandler> void operator()(WaitHandler&& handler) const { const auto alloc = get_associated_allocator( handler, self_->get_allocator()); auto cancel = get_associated_cancellation_slot(handler); if (self_->done) { auto exec = boost::asio::get_associated_executor( handler, self_->get_executor()); boost::asio::post(exec, [self = std::move(self_), handler = std::forward<WaitHandler>(handler)]() mutable { self->apply(std::move(handler)); }); } else { if (cancel.is_connected()) { struct cancel_handler { std::weak_ptr<detail::promise_impl< void(Ts...), Executor, Allocator>> self; cancel_handler( std::weak_ptr<detail::promise_impl< void(Ts...), Executor, Allocator>> self) : self(std::move(self)) { } void operator()(cancellation_type level) const { if (auto p = self.lock()) { p->cancel.emit(level); p->cancel_(); } } }; cancel.template emplace<cancel_handler>(self_); } self_->set_completion(alloc, std::forward<WaitHandler>(handler)); } } }; }; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_PROMISE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/basic_concurrent_channel.hpp
// // experimental/basic_concurrent_channel.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_BASIC_CONCURRENT_CHANNEL_HPP #define BOOST_ASIO_EXPERIMENTAL_BASIC_CONCURRENT_CHANNEL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/non_const_lvalue.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/experimental/detail/channel_send_functions.hpp> #include <boost/asio/experimental/detail/channel_service.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { } // namespace detail /// A channel for messages. /** * The basic_concurrent_channel class template is used for sending messages * between different parts of the same application. A <em>message</em> is * defined as a collection of arguments to be passed to a completion handler, * and the set of messages supported by a channel is specified by its @c Traits * and <tt>Signatures...</tt> template parameters. Messages may be sent and * received using asynchronous or non-blocking synchronous operations. * * Unless customising the traits, applications will typically use the @c * experimental::concurrent_channel alias template. For example: * @code void send_loop(int i, steady_timer& timer, * concurrent_channel<void(error_code, int)>& ch) * { * if (i < 10) * { * timer.expires_after(chrono::seconds(1)); * timer.async_wait( * [i, &timer, &ch](error_code error) * { * if (!error) * { * ch.async_send(error_code(), i, * [i, &timer, &ch](error_code error) * { * if (!error) * { * send_loop(i + 1, timer, ch); * } * }); * } * }); * } * else * { * ch.close(); * } * } * * void receive_loop(concurent_channel<void(error_code, int)>& ch) * { * ch.async_receive( * [&ch](error_code error, int i) * { * if (!error) * { * std::cout << "Received " << i << "\n"; * receive_loop(ch); * } * }); * } @endcode * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Safe. * * The basic_concurrent_channel class template is thread-safe, and would * typically be used for passing messages between application code that run on * different threads. Consider using @ref basic_channel, and its alias template * @c experimental::channel, to pass messages between code running in a single * thread or on the same strand. */ template <typename Executor, typename Traits, typename... Signatures> class basic_concurrent_channel #if !defined(GENERATING_DOCUMENTATION) : public detail::channel_send_functions< basic_concurrent_channel<Executor, Traits, Signatures...>, Executor, Signatures...> #endif // !defined(GENERATING_DOCUMENTATION) { private: class initiate_async_send; class initiate_async_receive; typedef detail::channel_service<boost::asio::detail::mutex> service_type; typedef typename service_type::template implementation_type< Traits, Signatures...>::payload_type payload_type; template <typename... PayloadSignatures, BOOST_ASIO_COMPLETION_TOKEN_FOR(PayloadSignatures...) CompletionToken> auto do_async_receive(detail::channel_payload<PayloadSignatures...>*, CompletionToken&& token) -> decltype( async_initiate<CompletionToken, PayloadSignatures...>( declval<initiate_async_receive>(), token)) { return async_initiate<CompletionToken, PayloadSignatures...>( initiate_async_receive(this), token); } public: /// The type of the executor associated with the channel. typedef Executor executor_type; /// Rebinds the channel type to another executor. template <typename Executor1> struct rebind_executor { /// The channel type when rebound to the specified executor. typedef basic_concurrent_channel<Executor1, Traits, Signatures...> other; }; /// The traits type associated with the channel. typedef typename Traits::template rebind<Signatures...>::other traits_type; /// Construct a basic_concurrent_channel. /** * This constructor creates and channel. * * @param ex The I/O executor that the channel will use, by default, to * dispatch handlers for any asynchronous operations performed on the channel. * * @param max_buffer_size The maximum number of messages that may be buffered * in the channel. */ basic_concurrent_channel(const executor_type& ex, std::size_t max_buffer_size = 0) : service_(&boost::asio::use_service<service_type>( basic_concurrent_channel::get_context(ex))), impl_(), executor_(ex) { service_->construct(impl_, max_buffer_size); } /// Construct and open a basic_concurrent_channel. /** * This constructor creates and opens a channel. * * @param context An execution context which provides the I/O executor that * the channel will use, by default, to dispatch handlers for any asynchronous * operations performed on the channel. * * @param max_buffer_size The maximum number of messages that may be buffered * in the channel. */ template <typename ExecutionContext> basic_concurrent_channel(ExecutionContext& context, std::size_t max_buffer_size = 0, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : service_(&boost::asio::use_service<service_type>(context)), impl_(), executor_(context.get_executor()) { service_->construct(impl_, max_buffer_size); } /// Move-construct a basic_concurrent_channel from another. /** * This constructor moves a channel from one object to another. * * @param other The other basic_concurrent_channel object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_concurrent_channel(const executor_type&) * constructor. */ basic_concurrent_channel(basic_concurrent_channel&& other) : service_(other.service_), executor_(other.executor_) { service_->move_construct(impl_, other.impl_); } /// Move-assign a basic_concurrent_channel from another. /** * This assignment operator moves a channel from one object to another. * Cancels any outstanding asynchronous operations associated with the target * object. * * @param other The other basic_concurrent_channel object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_concurrent_channel(const executor_type&) * constructor. */ basic_concurrent_channel& operator=(basic_concurrent_channel&& other) { if (this != &other) { service_->move_assign(impl_, *other.service_, other.impl_); executor_.~executor_type(); new (&executor_) executor_type(other.executor_); service_ = other.service_; } return *this; } // All channels have access to each other's implementations. template <typename, typename, typename...> friend class basic_concurrent_channel; /// Move-construct a basic_concurrent_channel from another. /** * This constructor moves a channel from one object to another. * * @param other The other basic_concurrent_channel object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_concurrent_channel(const executor_type&) * constructor. */ template <typename Executor1> basic_concurrent_channel( basic_concurrent_channel<Executor1, Traits, Signatures...>&& other, constraint_t< is_convertible<Executor1, Executor>::value > = 0) : service_(other.service_), executor_(other.executor_) { service_->move_construct(impl_, other.impl_); } /// Move-assign a basic_concurrent_channel from another. /** * This assignment operator moves a channel from one object to another. * Cancels any outstanding asynchronous operations associated with the target * object. * * @param other The other basic_concurrent_channel object from which the move * will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_concurrent_channel(const executor_type&) * constructor. */ template <typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_concurrent_channel& > operator=( basic_concurrent_channel<Executor1, Traits, Signatures...>&& other) { if (this != &other) { service_->move_assign(impl_, *other.service_, other.impl_); executor_.~executor_type(); new (&executor_) executor_type(other.executor_); service_ = other.service_; } return *this; } /// Destructor. ~basic_concurrent_channel() { service_->destroy(impl_); } /// Get the executor associated with the object. const executor_type& get_executor() noexcept { return executor_; } /// Get the capacity of the channel's buffer. std::size_t capacity() noexcept { return service_->capacity(impl_); } /// Determine whether the channel is open. bool is_open() const noexcept { return service_->is_open(impl_); } /// Reset the channel to its initial state. void reset() { service_->reset(impl_); } /// Close the channel. void close() { service_->close(impl_); } /// Cancel all asynchronous operations waiting on the channel. /** * All outstanding send operations will complete with the error * @c boost::asio::experimental::error::channel_cancelled. Outstanding receive * operations complete with the result as determined by the channel traits. */ void cancel() { service_->cancel(impl_); } /// Determine whether a message can be received without blocking. bool ready() const noexcept { return service_->ready(impl_); } #if defined(GENERATING_DOCUMENTATION) /// Try to send a message without blocking. /** * Fails if the buffer is full and there are no waiting receive operations. * * @returns @c true on success, @c false on failure. */ template <typename... Args> bool try_send(Args&&... args); /// Try to send a message without blocking, using dispatch semantics to call /// the receive operation's completion handler. /** * Fails if the buffer is full and there are no waiting receive operations. * * The receive operation's completion handler may be called from inside this * function. * * @returns @c true on success, @c false on failure. */ template <typename... Args> bool try_send_via_dispatch(Args&&... args); /// Try to send a number of messages without blocking. /** * @returns The number of messages that were sent. */ template <typename... Args> std::size_t try_send_n(std::size_t count, Args&&... args); /// Try to send a number of messages without blocking, using dispatch /// semantics to call the receive operations' completion handlers. /** * The receive operations' completion handlers may be called from inside this * function. * * @returns The number of messages that were sent. */ template <typename... Args> std::size_t try_send_n_via_dispatch(std::size_t count, Args&&... args); /// Asynchronously send a message. template <typename... Args, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> auto async_send(Args&&... args, CompletionToken&& token); #endif // defined(GENERATING_DOCUMENTATION) /// Try to receive a message without blocking. /** * Fails if the buffer is full and there are no waiting receive operations. * * @returns @c true on success, @c false on failure. */ template <typename Handler> bool try_receive(Handler&& handler) { return service_->try_receive(impl_, static_cast<Handler&&>(handler)); } /// Asynchronously receive a message. template <typename CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> auto async_receive( CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)) #if !defined(GENERATING_DOCUMENTATION) -> decltype( this->do_async_receive(static_cast<payload_type*>(0), static_cast<CompletionToken&&>(token))) #endif // !defined(GENERATING_DOCUMENTATION) { return this->do_async_receive(static_cast<payload_type*>(0), static_cast<CompletionToken&&>(token)); } private: // Disallow copying and assignment. basic_concurrent_channel( const basic_concurrent_channel&) = delete; basic_concurrent_channel& operator=( const basic_concurrent_channel&) = delete; template <typename, typename, typename...> friend class detail::channel_send_functions; // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<execution::is_executor<T>::value>* = 0) { return boost::asio::query(t, execution::context); } // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<!execution::is_executor<T>::value>* = 0) { return t.context(); } class initiate_async_send { public: typedef Executor executor_type; explicit initiate_async_send(basic_concurrent_channel* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename SendHandler> void operator()(SendHandler&& handler, payload_type&& payload) const { boost::asio::detail::non_const_lvalue<SendHandler> handler2(handler); self_->service_->async_send(self_->impl_, static_cast<payload_type&&>(payload), handler2.value, self_->get_executor()); } private: basic_concurrent_channel* self_; }; class initiate_async_receive { public: typedef Executor executor_type; explicit initiate_async_receive(basic_concurrent_channel* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename ReceiveHandler> void operator()(ReceiveHandler&& handler) const { boost::asio::detail::non_const_lvalue<ReceiveHandler> handler2(handler); self_->service_->async_receive(self_->impl_, handler2.value, self_->get_executor()); } private: basic_concurrent_channel* self_; }; // The service associated with the I/O object. service_type* service_; // The underlying implementation of the I/O object. typename service_type::template implementation_type< Traits, Signatures...> impl_; // The associated executor. Executor executor_; }; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_BASIC_CONCURRENT_CHANNEL_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/co_composed.hpp
// // experimental/co_composed.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CO_COMPOSED_HPP #define BOOST_ASIO_EXPERIMENTAL_CO_COMPOSED_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { /// Creates an initiation function object that may be used to launch a /// coroutine-based composed asynchronous operation. /** * The experimental::co_composed utility simplifies the implementation of * composed asynchronous operations by automatically adapting a coroutine to be * an initiation function object for use with @c async_initiate. When awaiting * asynchronous operations, the coroutine automatically uses a conforming * intermediate completion handler. * * @param implementation A function object that contains the coroutine-based * implementation of the composed asynchronous operation. The first argument to * the function object represents the state of the operation, and may be used * to test for cancellation. The remaining arguments are those passed to @c * async_initiate after the completion token. * * @param io_objects_or_executors Zero or more I/O objects or I/O executors for * which outstanding work must be maintained while the operation is incomplete. * * @par Per-Operation Cancellation * By default, terminal per-operation cancellation is enabled for composed * operations that use experimental::co_composed. To disable cancellation for * the composed operation, or to alter its supported cancellation types, call * the state's @c reset_cancellation_state function. * * @par Examples * The following example illustrates manual error handling and explicit checks * for cancellation. The completion handler is invoked via a @c co_yield to the * state's @c complete function, which never returns. * * @code template <typename CompletionToken> * auto async_echo(tcp::socket& socket, * CompletionToken&& token) * { * return boost::asio::async_initiate< * CompletionToken, void(boost::system::error_code)>( * boost::asio::experimental::co_composed( * [](auto state, tcp::socket& socket) -> void * { * state.reset_cancellation_state( * boost::asio::enable_terminal_cancellation()); * * while (!state.cancelled()) * { * char data[1024]; * auto [e1, n1] = * co_await socket.async_read_some( * boost::asio::buffer(data), * boost::asio::as_tuple(boost::asio::deferred)); * * if (e1) * co_yield state.complete(e1); * * if (!!state.cancelled()) * co_yield state.complete( * make_error_code(boost::asio::error::operation_aborted)); * * auto [e2, n2] = * co_await boost::asio::async_write(socket, * boost::asio::buffer(data, n1), * boost::asio::as_tuple(boost::asio::deferred)); * * if (e2) * co_yield state.complete(e2); * } * }, socket), * token, std::ref(socket)); * } @endcode * * This next example shows exception-based error handling and implicit checks * for cancellation. The completion handler is invoked after returning from the * coroutine via @c co_return. Valid @c co_return values are specified using * completion signatures passed to the @c co_composed function. * * @code template <typename CompletionToken> * auto async_echo(tcp::socket& socket, * CompletionToken&& token) * { * return boost::asio::async_initiate< * CompletionToken, void(boost::system::error_code)>( * boost::asio::experimental::co_composed< * void(boost::system::error_code)>( * [](auto state, tcp::socket& socket) -> void * { * try * { * state.throw_if_cancelled(true); * state.reset_cancellation_state( * boost::asio::enable_terminal_cancellation()); * * for (;;) * { * char data[1024]; * std::size_t n = co_await socket.async_read_some( * boost::asio::buffer(data), boost::asio::deferred); * * co_await boost::asio::async_write(socket, * boost::asio::buffer(data, n), boost::asio::deferred); * } * } * catch (const boost::system::system_error& e) * { * co_return {e.code()}; * } * }, socket), * token, std::ref(socket)); * } @endcode */ template <completion_signature... Signatures, typename Implementation, typename... IoObjectsOrExecutors> auto co_composed(Implementation&& implementation, IoObjectsOrExecutors&&... io_objects_or_executors); } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/co_composed.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CO_COMPOSED_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/parallel_group.hpp
// // experimental/parallel_group.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_PARALLEL_GROUP_HPP #define BOOST_ASIO_EXPERIMENTAL_PARALLEL_GROUP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <vector> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/array.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/utility.hpp> #include <boost/asio/experimental/cancellation_condition.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { // Helper trait for getting a tuple from a completion signature. template <typename Signature> struct parallel_op_signature_as_tuple; template <typename R, typename... Args> struct parallel_op_signature_as_tuple<R(Args...)> { typedef std::tuple<decay_t<Args>...> type; }; // Helper trait for concatenating completion signatures. template <std::size_t N, typename Offsets, typename... Signatures> struct parallel_group_signature; template <std::size_t N, typename R0, typename... Args0> struct parallel_group_signature<N, R0(Args0...)> { typedef boost::asio::detail::array<std::size_t, N> order_type; typedef R0 raw_type(Args0...); typedef R0 type(order_type, Args0...); }; template <std::size_t N, typename R0, typename... Args0, typename R1, typename... Args1> struct parallel_group_signature<N, R0(Args0...), R1(Args1...)> { typedef boost::asio::detail::array<std::size_t, N> order_type; typedef R0 raw_type(Args0..., Args1...); typedef R0 type(order_type, Args0..., Args1...); }; template <std::size_t N, typename Sig0, typename Sig1, typename... SigN> struct parallel_group_signature<N, Sig0, Sig1, SigN...> { typedef boost::asio::detail::array<std::size_t, N> order_type; typedef typename parallel_group_signature<N, typename parallel_group_signature<N, Sig0, Sig1>::raw_type, SigN...>::raw_type raw_type; typedef typename parallel_group_signature<N, typename parallel_group_signature<N, Sig0, Sig1>::raw_type, SigN...>::type type; }; template <typename Condition, typename Handler, typename... Ops, std::size_t... I> void parallel_group_launch(Condition cancellation_condition, Handler handler, std::tuple<Ops...>& ops, boost::asio::detail::index_sequence<I...>); // Helper trait for determining ranged parallel group completion signatures. template <typename Signature, typename Allocator> struct ranged_parallel_group_signature; template <typename R, typename... Args, typename Allocator> struct ranged_parallel_group_signature<R(Args...), Allocator> { typedef std::vector<std::size_t, BOOST_ASIO_REBIND_ALLOC(Allocator, std::size_t)> order_type; typedef R raw_type( std::vector<Args, BOOST_ASIO_REBIND_ALLOC(Allocator, Args)>...); typedef R type(order_type, std::vector<Args, BOOST_ASIO_REBIND_ALLOC(Allocator, Args)>...); }; template <typename Condition, typename Handler, typename Range, typename Allocator> void ranged_parallel_group_launch(Condition cancellation_condition, Handler handler, Range&& range, const Allocator& allocator); char (&parallel_group_has_iterator_helper(...))[2]; template <typename T> char parallel_group_has_iterator_helper(T*, typename T::iterator* = 0); template <typename T> struct parallel_group_has_iterator_typedef { enum { value = (sizeof((parallel_group_has_iterator_helper)((T*)(0))) == 1) }; }; } // namespace detail /// Type trait used to determine whether a type is a range of asynchronous /// operations that can be used with with @c make_parallel_group. template <typename T> struct is_async_operation_range { #if defined(GENERATING_DOCUMENTATION) /// The value member is true if the type may be used as a range of /// asynchronous operations. static const bool value; #else enum { value = detail::parallel_group_has_iterator_typedef<T>::value }; #endif }; /// A group of asynchronous operations that may be launched in parallel. /** * See the documentation for boost::asio::experimental::make_parallel_group for * a usage example. */ template <typename... Ops> class parallel_group { private: struct initiate_async_wait { template <typename Handler, typename Condition> void operator()(Handler&& h, Condition&& c, std::tuple<Ops...>&& ops) const { detail::parallel_group_launch( std::forward<Condition>(c), std::forward<Handler>(h), ops, boost::asio::detail::index_sequence_for<Ops...>()); } }; std::tuple<Ops...> ops_; public: /// Constructor. explicit parallel_group(Ops... ops) : ops_(std::move(ops)...) { } /// The completion signature for the group of operations. typedef typename detail::parallel_group_signature<sizeof...(Ops), completion_signature_of_t<Ops>...>::type signature; /// Initiate an asynchronous wait for the group of operations. /** * Launches the group and asynchronously waits for completion. * * @param cancellation_condition A function object, called on completion of * an operation within the group, that is used to determine whether to cancel * the remaining operations. The function object is passed the arguments of * the completed operation's handler. To trigger cancellation of the remaining * operations, it must return a boost::asio::cancellation_type value other * than <tt>boost::asio::cancellation_type::none</tt>. * * @param token A @ref completion_token whose signature is comprised of * a @c std::array<std::size_t, N> indicating the completion order of the * operations, followed by all operations' completion handler arguments. * * The library provides the following @c cancellation_condition types: * * @li boost::asio::experimental::wait_for_all * @li boost::asio::experimental::wait_for_one * @li boost::asio::experimental::wait_for_one_error * @li boost::asio::experimental::wait_for_one_success */ template <typename CancellationCondition, BOOST_ASIO_COMPLETION_TOKEN_FOR(signature) CompletionToken> auto async_wait(CancellationCondition cancellation_condition, CompletionToken&& token) -> decltype( boost::asio::async_initiate<CompletionToken, signature>( declval<initiate_async_wait>(), token, std::move(cancellation_condition), std::move(ops_))) { return boost::asio::async_initiate<CompletionToken, signature>( initiate_async_wait(), token, std::move(cancellation_condition), std::move(ops_)); } }; /// Create a group of operations that may be launched in parallel. /** * For example: * @code boost::asio::experimental::make_parallel_group( * [&](auto token) * { * return in.async_read_some(boost::asio::buffer(data), token); * }, * [&](auto token) * { * return timer.async_wait(token); * } * ).async_wait( * boost::asio::experimental::wait_for_all(), * []( * std::array<std::size_t, 2> completion_order, * boost::system::error_code ec1, std::size_t n1, * boost::system::error_code ec2 * ) * { * switch (completion_order[0]) * { * case 0: * { * std::cout << "descriptor finished: " << ec1 << ", " << n1 << "\n"; * } * break; * case 1: * { * std::cout << "timer finished: " << ec2 << "\n"; * } * break; * } * } * ); * @endcode */ template <typename... Ops> BOOST_ASIO_NODISCARD inline parallel_group<Ops...> make_parallel_group(Ops... ops) { return parallel_group<Ops...>(std::move(ops)...); } /// A range-based group of asynchronous operations that may be launched in /// parallel. /** * See the documentation for boost::asio::experimental::make_parallel_group for * a usage example. */ template <typename Range, typename Allocator = std::allocator<void>> class ranged_parallel_group { private: struct initiate_async_wait { template <typename Handler, typename Condition> void operator()(Handler&& h, Condition&& c, Range&& range, const Allocator& allocator) const { detail::ranged_parallel_group_launch(std::move(c), std::move(h), std::forward<Range>(range), allocator); } }; Range range_; Allocator allocator_; public: /// Constructor. explicit ranged_parallel_group(Range range, const Allocator& allocator = Allocator()) : range_(std::move(range)), allocator_(allocator) { } /// The completion signature for the group of operations. typedef typename detail::ranged_parallel_group_signature< completion_signature_of_t< decay_t<decltype(*std::declval<typename Range::iterator>())>>, Allocator>::type signature; /// Initiate an asynchronous wait for the group of operations. /** * Launches the group and asynchronously waits for completion. * * @param cancellation_condition A function object, called on completion of * an operation within the group, that is used to determine whether to cancel * the remaining operations. The function object is passed the arguments of * the completed operation's handler. To trigger cancellation of the remaining * operations, it must return a boost::asio::cancellation_type value other * than <tt>boost::asio::cancellation_type::none</tt>. * * @param token A @ref completion_token whose signature is comprised of * a @c std::vector<std::size_t, Allocator> indicating the completion order of * the operations, followed by a vector for each of the completion signature's * arguments. * * The library provides the following @c cancellation_condition types: * * @li boost::asio::experimental::wait_for_all * @li boost::asio::experimental::wait_for_one * @li boost::asio::experimental::wait_for_one_error * @li boost::asio::experimental::wait_for_one_success */ template <typename CancellationCondition, BOOST_ASIO_COMPLETION_TOKEN_FOR(signature) CompletionToken> auto async_wait(CancellationCondition cancellation_condition, CompletionToken&& token) -> decltype( boost::asio::async_initiate<CompletionToken, signature>( declval<initiate_async_wait>(), token, std::move(cancellation_condition), std::move(range_), allocator_)) { return boost::asio::async_initiate<CompletionToken, signature>( initiate_async_wait(), token, std::move(cancellation_condition), std::move(range_), allocator_); } }; /// Create a group of operations that may be launched in parallel. /** * @param range A range containing the operations to be launched. * * For example: * @code * using op_type = decltype( * socket1.async_read_some( * boost::asio::buffer(data1), * boost::asio::deferred * ) * ); * * std::vector<op_type> ops; * * ops.push_back( * socket1.async_read_some( * boost::asio::buffer(data1), * boost::asio::deferred * ) * ); * * ops.push_back( * socket2.async_read_some( * boost::asio::buffer(data2), * boost::asio::deferred * ) * ); * * boost::asio::experimental::make_parallel_group(ops).async_wait( * boost::asio::experimental::wait_for_all(), * []( * std::vector<std::size_t> completion_order, * std::vector<boost::system::error_code> e, * std::vector<std::size_t> n * ) * { * for (std::size_t i = 0; i < completion_order.size(); ++i) * { * std::size_t idx = completion_order[i]; * std::cout << "socket " << idx << " finished: "; * std::cout << e[idx] << ", " << n[idx] << "\n"; * } * } * ); * @endcode */ template <typename Range> BOOST_ASIO_NODISCARD inline ranged_parallel_group<decay_t<Range>> make_parallel_group(Range&& range, constraint_t< is_async_operation_range<decay_t<Range>>::value > = 0) { return ranged_parallel_group<decay_t<Range>>(std::forward<Range>(range)); } /// Create a group of operations that may be launched in parallel. /** * @param allocator Specifies the allocator to be used with the result vectors. * * @param range A range containing the operations to be launched. * * For example: * @code * using op_type = decltype( * socket1.async_read_some( * boost::asio::buffer(data1), * boost::asio::deferred * ) * ); * * std::vector<op_type> ops; * * ops.push_back( * socket1.async_read_some( * boost::asio::buffer(data1), * boost::asio::deferred * ) * ); * * ops.push_back( * socket2.async_read_some( * boost::asio::buffer(data2), * boost::asio::deferred * ) * ); * * boost::asio::experimental::make_parallel_group( * std::allocator_arg_t, * my_allocator, * ops * ).async_wait( * boost::asio::experimental::wait_for_all(), * []( * std::vector<std::size_t> completion_order, * std::vector<boost::system::error_code> e, * std::vector<std::size_t> n * ) * { * for (std::size_t i = 0; i < completion_order.size(); ++i) * { * std::size_t idx = completion_order[i]; * std::cout << "socket " << idx << " finished: "; * std::cout << e[idx] << ", " << n[idx] << "\n"; * } * } * ); * @endcode */ template <typename Allocator, typename Range> BOOST_ASIO_NODISCARD inline ranged_parallel_group<decay_t<Range>, Allocator> make_parallel_group(allocator_arg_t, const Allocator& allocator, Range&& range, constraint_t< is_async_operation_range<decay_t<Range>>::value > = 0) { return ranged_parallel_group<decay_t<Range>, Allocator>( std::forward<Range>(range), allocator); } } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/parallel_group.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_PARALLEL_GROUP_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/coro_traits.hpp
// // experimental/detail/coro_traits.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_TRAITS_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_TRAITS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <optional> #include <variant> #include <boost/asio/any_io_executor.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <class From, class To> concept convertible_to = std::is_convertible_v<From, To>; template <typename T> concept decays_to_executor = execution::executor<std::decay_t<T>>; template <typename T, typename Executor = any_io_executor> concept execution_context = requires (T& t) { {t.get_executor()} -> convertible_to<Executor>; }; template <typename Yield, typename Return> struct coro_result { using type = std::variant<Yield, Return>; }; template <typename Yield> struct coro_result<Yield, void> { using type = std::optional<Yield>; }; template <typename Return> struct coro_result<void, Return> { using type = Return; }; template <typename YieldReturn> struct coro_result<YieldReturn, YieldReturn> { using type = YieldReturn; }; template <> struct coro_result<void, void> { using type = void; }; template <typename Yield, typename Return> using coro_result_t = typename coro_result<Yield, Return>::type; template <typename Result, bool IsNoexcept> struct coro_handler; template <> struct coro_handler<void, false> { using type = void(std::exception_ptr); }; template <> struct coro_handler<void, true> { using type = void(); }; template <typename T> struct coro_handler<T, false> { using type = void(std::exception_ptr, T); }; template <typename T> struct coro_handler<T, true> { using type = void(T); }; template <typename Result, bool IsNoexcept> using coro_handler_t = typename coro_handler<Result, IsNoexcept>::type; } // namespace detail #if defined(GENERATING_DOCUMENTATION) /// The traits describing the resumable coroutine behaviour. /** * Template parameter @c Yield specifies type or signature used by co_yield, * @c Return specifies the type used for co_return, and @c Executor specifies * the underlying executor type. */ template <typename Yield, typename Return, typename Executor> struct coro_traits { /// The value that can be passed into a symmetrical cororoutine. @c void if /// asymmetrical. using input_type = argument_dependent; /// The type that can be passed out through a co_yield. using yield_type = argument_dependent; /// The type that can be passed out through a co_return. using return_type = argument_dependent; /// The type received by a co_await or async_resume. It's a combination of /// yield and return. using result_type = argument_dependent; /// The signature used by the async_resume. using signature_type = argument_dependent; /// Whether or not the coroutine is noexcept. constexpr static bool is_noexcept = argument_dependent; /// The error type of the coroutine. @c void for noexcept. using error_type = argument_dependent; /// Completion handler type used by async_resume. using completion_handler = argument_dependent; }; #else // defined(GENERATING_DOCUMENTATION) template <typename Yield, typename Return, typename Executor> struct coro_traits { using input_type = void; using yield_type = Yield; using return_type = Return; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(); constexpr static bool is_noexcept = false; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; template <typename T, typename Return, typename Executor> struct coro_traits<T(), Return, Executor> { using input_type = void; using yield_type = T; using return_type = Return; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(); constexpr static bool is_noexcept = false; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; template <typename T, typename Return, typename Executor> struct coro_traits<T() noexcept, Return, Executor> { using input_type = void; using yield_type = T; using return_type = Return; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(); constexpr static bool is_noexcept = true; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; template <typename T, typename U, typename Return, typename Executor> struct coro_traits<T(U), Return, Executor> { using input_type = U; using yield_type = T; using return_type = Return; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(input_type); constexpr static bool is_noexcept = false; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; template <typename T, typename U, typename Return, typename Executor> struct coro_traits<T(U) noexcept, Return, Executor> { using input_type = U; using yield_type = T; using return_type = Return; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(input_type); constexpr static bool is_noexcept = true; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; template <typename Executor> struct coro_traits<void() noexcept, void, Executor> { using input_type = void; using yield_type = void; using return_type = void; using result_type = detail::coro_result_t<yield_type, return_type>; using signature_type = result_type(input_type); constexpr static bool is_noexcept = true; using error_type = std::conditional_t<is_noexcept, void, std::exception_ptr>; using completion_handler = detail::coro_handler_t<result_type, is_noexcept>; }; #endif // defined(GENERATING_DOCUMENTATION) } // namespace experimental } // namespace asio } // namespace boost #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_TRAITS_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/basic_channel.hpp
// // experimental/basic_channel.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_BASIC_CHANNEL_HPP #define BOOST_ASIO_EXPERIMENTAL_BASIC_CHANNEL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/non_const_lvalue.hpp> #include <boost/asio/detail/null_mutex.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/experimental/detail/channel_send_functions.hpp> #include <boost/asio/experimental/detail/channel_service.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { } // namespace detail /// A channel for messages. /** * The basic_channel class template is used for sending messages between * different parts of the same application. A <em>message</em> is defined as a * collection of arguments to be passed to a completion handler, and the set of * messages supported by a channel is specified by its @c Traits and * <tt>Signatures...</tt> template parameters. Messages may be sent and received * using asynchronous or non-blocking synchronous operations. * * Unless customising the traits, applications will typically use the @c * experimental::channel alias template. For example: * @code void send_loop(int i, steady_timer& timer, * channel<void(error_code, int)>& ch) * { * if (i < 10) * { * timer.expires_after(chrono::seconds(1)); * timer.async_wait( * [i, &timer, &ch](error_code error) * { * if (!error) * { * ch.async_send(error_code(), i, * [i, &timer, &ch](error_code error) * { * if (!error) * { * send_loop(i + 1, timer, ch); * } * }); * } * }); * } * else * { * ch.close(); * } * } * * void receive_loop(channel<void(error_code, int)>& ch) * { * ch.async_receive( * [&ch](error_code error, int i) * { * if (!error) * { * std::cout << "Received " << i << "\n"; * receive_loop(ch); * } * }); * } @endcode * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. * * The basic_channel class template is not thread-safe, and would typically be * used for passing messages between application code that runs on the same * thread or in the same strand. Consider using @ref basic_concurrent_channel, * and its alias template @c experimental::concurrent_channel, to pass messages * between code running in different threads. */ template <typename Executor, typename Traits, typename... Signatures> class basic_channel #if !defined(GENERATING_DOCUMENTATION) : public detail::channel_send_functions< basic_channel<Executor, Traits, Signatures...>, Executor, Signatures...> #endif // !defined(GENERATING_DOCUMENTATION) { private: class initiate_async_send; class initiate_async_receive; typedef detail::channel_service<boost::asio::detail::null_mutex> service_type; typedef typename service_type::template implementation_type< Traits, Signatures...>::payload_type payload_type; template <typename... PayloadSignatures, BOOST_ASIO_COMPLETION_TOKEN_FOR(PayloadSignatures...) CompletionToken> auto do_async_receive(detail::channel_payload<PayloadSignatures...>*, CompletionToken&& token) -> decltype( async_initiate<CompletionToken, PayloadSignatures...>( declval<initiate_async_receive>(), token)) { return async_initiate<CompletionToken, PayloadSignatures...>( initiate_async_receive(this), token); } public: /// The type of the executor associated with the channel. typedef Executor executor_type; /// Rebinds the channel type to another executor. template <typename Executor1> struct rebind_executor { /// The channel type when rebound to the specified executor. typedef basic_channel<Executor1, Traits, Signatures...> other; }; /// The traits type associated with the channel. typedef typename Traits::template rebind<Signatures...>::other traits_type; /// Construct a basic_channel. /** * This constructor creates and channel. * * @param ex The I/O executor that the channel will use, by default, to * dispatch handlers for any asynchronous operations performed on the channel. * * @param max_buffer_size The maximum number of messages that may be buffered * in the channel. */ basic_channel(const executor_type& ex, std::size_t max_buffer_size = 0) : service_(&boost::asio::use_service<service_type>( basic_channel::get_context(ex))), impl_(), executor_(ex) { service_->construct(impl_, max_buffer_size); } /// Construct and open a basic_channel. /** * This constructor creates and opens a channel. * * @param context An execution context which provides the I/O executor that * the channel will use, by default, to dispatch handlers for any asynchronous * operations performed on the channel. * * @param max_buffer_size The maximum number of messages that may be buffered * in the channel. */ template <typename ExecutionContext> basic_channel(ExecutionContext& context, std::size_t max_buffer_size = 0, constraint_t< is_convertible<ExecutionContext&, execution_context&>::value, defaulted_constraint > = defaulted_constraint()) : service_(&boost::asio::use_service<service_type>(context)), impl_(), executor_(context.get_executor()) { service_->construct(impl_, max_buffer_size); } /// Move-construct a basic_channel from another. /** * This constructor moves a channel from one object to another. * * @param other The other basic_channel object from which the move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_channel(const executor_type&) constructor. */ basic_channel(basic_channel&& other) : service_(other.service_), executor_(other.executor_) { service_->move_construct(impl_, other.impl_); } /// Move-assign a basic_channel from another. /** * This assignment operator moves a channel from one object to another. * Cancels any outstanding asynchronous operations associated with the target * object. * * @param other The other basic_channel object from which the move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_channel(const executor_type&) * constructor. */ basic_channel& operator=(basic_channel&& other) { if (this != &other) { service_->move_assign(impl_, *other.service_, other.impl_); executor_.~executor_type(); new (&executor_) executor_type(other.executor_); service_ = other.service_; } return *this; } // All channels have access to each other's implementations. template <typename, typename, typename...> friend class basic_channel; /// Move-construct a basic_channel from another. /** * This constructor moves a channel from one object to another. * * @param other The other basic_channel object from which the move will occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_channel(const executor_type&) * constructor. */ template <typename Executor1> basic_channel( basic_channel<Executor1, Traits, Signatures...>&& other, constraint_t< is_convertible<Executor1, Executor>::value > = 0) : service_(other.service_), executor_(other.executor_) { service_->move_construct(impl_, other.impl_); } /// Move-assign a basic_channel from another. /** * This assignment operator moves a channel from one object to another. * Cancels any outstanding asynchronous operations associated with the target * object. * * @param other The other basic_channel object from which the move will * occur. * * @note Following the move, the moved-from object is in the same state as if * constructed using the @c basic_channel(const executor_type&) * constructor. */ template <typename Executor1> constraint_t< is_convertible<Executor1, Executor>::value, basic_channel& > operator=(basic_channel<Executor1, Traits, Signatures...>&& other) { if (this != &other) { service_->move_assign(impl_, *other.service_, other.impl_); executor_.~executor_type(); new (&executor_) executor_type(other.executor_); service_ = other.service_; } return *this; } /// Destructor. ~basic_channel() { service_->destroy(impl_); } /// Get the executor associated with the object. const executor_type& get_executor() noexcept { return executor_; } /// Get the capacity of the channel's buffer. std::size_t capacity() noexcept { return service_->capacity(impl_); } /// Determine whether the channel is open. bool is_open() const noexcept { return service_->is_open(impl_); } /// Reset the channel to its initial state. void reset() { service_->reset(impl_); } /// Close the channel. void close() { service_->close(impl_); } /// Cancel all asynchronous operations waiting on the channel. /** * All outstanding send operations will complete with the error * @c boost::asio::experimental::error::channel_cancelled. Outstanding receive * operations complete with the result as determined by the channel traits. */ void cancel() { service_->cancel(impl_); } /// Determine whether a message can be received without blocking. bool ready() const noexcept { return service_->ready(impl_); } #if defined(GENERATING_DOCUMENTATION) /// Try to send a message without blocking. /** * Fails if the buffer is full and there are no waiting receive operations. * * @returns @c true on success, @c false on failure. */ template <typename... Args> bool try_send(Args&&... args); /// Try to send a message without blocking, using dispatch semantics to call /// the receive operation's completion handler. /** * Fails if the buffer is full and there are no waiting receive operations. * * The receive operation's completion handler may be called from inside this * function. * * @returns @c true on success, @c false on failure. */ template <typename... Args> bool try_send_via_dispatch(Args&&... args); /// Try to send a number of messages without blocking. /** * @returns The number of messages that were sent. */ template <typename... Args> std::size_t try_send_n(std::size_t count, Args&&... args); /// Try to send a number of messages without blocking, using dispatch /// semantics to call the receive operations' completion handlers. /** * The receive operations' completion handlers may be called from inside this * function. * * @returns The number of messages that were sent. */ template <typename... Args> std::size_t try_send_n_via_dispatch(std::size_t count, Args&&... args); /// Asynchronously send a message. /** * @par Completion Signature * @code void(boost::system::error_code) @endcode */ template <typename... Args, BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> auto async_send(Args&&... args, CompletionToken&& token); #endif // defined(GENERATING_DOCUMENTATION) /// Try to receive a message without blocking. /** * Fails if the buffer is full and there are no waiting receive operations. * * @returns @c true on success, @c false on failure. */ template <typename Handler> bool try_receive(Handler&& handler) { return service_->try_receive(impl_, static_cast<Handler&&>(handler)); } /// Asynchronously receive a message. /** * @par Completion Signature * As determined by the <tt>Signatures...</tt> template parameter and the * channel traits. */ template <typename CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> auto async_receive( CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)) #if !defined(GENERATING_DOCUMENTATION) -> decltype( this->do_async_receive(static_cast<payload_type*>(0), static_cast<CompletionToken&&>(token))) #endif // !defined(GENERATING_DOCUMENTATION) { return this->do_async_receive(static_cast<payload_type*>(0), static_cast<CompletionToken&&>(token)); } private: // Disallow copying and assignment. basic_channel(const basic_channel&) = delete; basic_channel& operator=(const basic_channel&) = delete; template <typename, typename, typename...> friend class detail::channel_send_functions; // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<execution::is_executor<T>::value>* = 0) { return boost::asio::query(t, execution::context); } // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<!execution::is_executor<T>::value>* = 0) { return t.context(); } class initiate_async_send { public: typedef Executor executor_type; explicit initiate_async_send(basic_channel* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename SendHandler> void operator()(SendHandler&& handler, payload_type&& payload) const { boost::asio::detail::non_const_lvalue<SendHandler> handler2(handler); self_->service_->async_send(self_->impl_, static_cast<payload_type&&>(payload), handler2.value, self_->get_executor()); } private: basic_channel* self_; }; class initiate_async_receive { public: typedef Executor executor_type; explicit initiate_async_receive(basic_channel* self) : self_(self) { } const executor_type& get_executor() const noexcept { return self_->get_executor(); } template <typename ReceiveHandler> void operator()(ReceiveHandler&& handler) const { boost::asio::detail::non_const_lvalue<ReceiveHandler> handler2(handler); self_->service_->async_receive(self_->impl_, handler2.value, self_->get_executor()); } private: basic_channel* self_; }; // The service associated with the I/O object. service_type* service_; // The underlying implementation of the I/O object. typename service_type::template implementation_type< Traits, Signatures...> impl_; // The associated executor. Executor executor_; }; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_BASIC_CHANNEL_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/prepend.hpp
// // experimental/prepend.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP #define BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/prepend.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { #if !defined(BOOST_ASIO_NO_DEPRECATED) using boost::asio::prepend_t; using boost::asio::prepend; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_PREPEND_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/cancellation_condition.hpp
// // experimental/cancellation_condition.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP #define BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <exception> #include <boost/asio/cancellation_type.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { /// Wait for all operations to complete. class wait_for_all { public: template <typename... Args> constexpr cancellation_type_t operator()(Args&&...) const noexcept { return cancellation_type::none; } }; /// Wait until an operation completes, then cancel the others. class wait_for_one { public: constexpr explicit wait_for_one( cancellation_type_t cancel_type = cancellation_type::all) : cancel_type_(cancel_type) { } template <typename... Args> constexpr cancellation_type_t operator()(Args&&...) const noexcept { return cancel_type_; } private: cancellation_type_t cancel_type_; }; /// Wait until an operation completes without an error, then cancel the others. /** * If no operation completes without an error, waits for completion of all * operations. */ class wait_for_one_success { public: constexpr explicit wait_for_one_success( cancellation_type_t cancel_type = cancellation_type::all) : cancel_type_(cancel_type) { } constexpr cancellation_type_t operator()() const noexcept { return cancel_type_; } template <typename E, typename... Args> constexpr constraint_t< !is_same<decay_t<E>, boost::system::error_code>::value && !is_same<decay_t<E>, std::exception_ptr>::value, cancellation_type_t > operator()(const E&, Args&&...) const noexcept { return cancel_type_; } template <typename E, typename... Args> constexpr constraint_t< is_same<decay_t<E>, boost::system::error_code>::value || is_same<decay_t<E>, std::exception_ptr>::value, cancellation_type_t > operator()(const E& e, Args&&...) const noexcept { return !!e ? cancellation_type::none : cancel_type_; } private: cancellation_type_t cancel_type_; }; /// Wait until an operation completes with an error, then cancel the others. /** * If no operation completes with an error, waits for completion of all * operations. */ class wait_for_one_error { public: constexpr explicit wait_for_one_error( cancellation_type_t cancel_type = cancellation_type::all) : cancel_type_(cancel_type) { } constexpr cancellation_type_t operator()() const noexcept { return cancellation_type::none; } template <typename E, typename... Args> constexpr constraint_t< !is_same<decay_t<E>, boost::system::error_code>::value && !is_same<decay_t<E>, std::exception_ptr>::value, cancellation_type_t > operator()(const E&, Args&&...) const noexcept { return cancellation_type::none; } template <typename E, typename... Args> constexpr constraint_t< is_same<decay_t<E>, boost::system::error_code>::value || is_same<decay_t<E>, std::exception_ptr>::value, cancellation_type_t > operator()(const E& e, Args&&...) const noexcept { return !!e ? cancel_type_ : cancellation_type::none; } private: cancellation_type_t cancel_type_; }; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CANCELLATION_CONDITION_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/as_tuple.hpp
// // experimental/as_tuple.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_AS_TUPLE_HPP #define BOOST_ASIO_EXPERIMENTAL_AS_TUPLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/as_tuple.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { #if !defined(BOOST_ASIO_NO_DEPRECATED) using boost::asio::as_tuple_t; using boost::asio::as_tuple; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_AS_TUPLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/channel_error.hpp
// // experimental/channel_error.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CHANNEL_ERROR_HPP #define BOOST_ASIO_EXPERIMENTAL_CHANNEL_ERROR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace error { enum channel_errors { /// The channel was closed. channel_closed = 1, /// The channel was cancelled. channel_cancelled = 2 }; extern BOOST_ASIO_DECL const boost::system::error_category& get_channel_category(); static const boost::system::error_category& channel_category BOOST_ASIO_UNUSED_VARIABLE = boost::asio::experimental::error::get_channel_category(); } // namespace error namespace channel_errc { // Simulates a scoped enum. using error::channel_closed; using error::channel_cancelled; } // namespace channel_errc } // namespace experimental } // namespace asio } // namespace boost namespace boost { namespace system { template<> struct is_error_code_enum< boost::asio::experimental::error::channel_errors> { static const bool value = true; }; } // namespace system } // namespace boost namespace boost { namespace asio { namespace experimental { namespace error { inline boost::system::error_code make_error_code(channel_errors e) { return boost::system::error_code( static_cast<int>(e), get_channel_category()); } } // namespace error } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/experimental/impl/channel_error.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_EXPERIMENTAL_CHANNEL_ERROR_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/use_coro.hpp
// // experimental/use_coro.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_USE_CORO_HPP #define BOOST_ASIO_EXPERIMENTAL_USE_CORO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <memory> #include <boost/asio/deferred.hpp> #include <boost/asio/detail/source_location.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class any_io_executor; namespace experimental { /// A @ref completion_token that creates another coro for the task completion. /** * The @c use_coro_t class, with its value @c use_coro, is used to represent an * operation that can be awaited by the current resumable coroutine. This * completion token may be passed as a handler to an asynchronous operation. * For example: * * @code coro<void> my_coroutine(tcp::socket my_socket) * { * std::size_t n = co_await my_socket.async_read_some(buffer, use_coro); * ... * } @endcode * * When used with co_await, the initiating function (@c async_read_some in the * above example) suspends the current coroutine. The coroutine is resumed when * the asynchronous operation completes, and the result of the operation is * returned. * * Note that this token is not the most efficient (use @c boost::asio::deferred * for that) but does provide type erasure, as it will always return a @c coro. */ template <typename Allocator = std::allocator<void>> struct use_coro_t { /// The allocator type. The allocator is used when constructing the /// @c std::promise object for a given asynchronous operation. typedef Allocator allocator_type; /// Default constructor. constexpr use_coro_t( allocator_type allocator = allocator_type{} #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , boost::asio::detail::source_location location = boost::asio::detail::source_location::current() # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) ) : allocator_(allocator) #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , file_name_(location.file_name()), line_(location.line()), function_name_(location.function_name()) # else // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , file_name_(0), line_(0), function_name_(0) # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) { } /// Specify an alternate allocator. template <typename OtherAllocator> use_coro_t<OtherAllocator> rebind(const OtherAllocator& allocator) const { return use_future_t<OtherAllocator>(allocator); } /// Obtain allocator. allocator_type get_allocator() const { return allocator_; } /// Constructor used to specify file name, line, and function name. constexpr use_coro_t(const char* file_name, int line, const char* function_name, allocator_type allocator = allocator_type{}) : #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) file_name_(file_name), line_(line), function_name_(function_name), #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) allocator_(allocator) { #if !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) (void)file_name; (void)line; (void)function_name; #endif // !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) } /// Adapts an executor to add the @c use_coro_t completion token as the /// default. template <typename InnerExecutor> struct executor_with_default : InnerExecutor { /// Specify @c use_coro_t as the default completion token type. typedef use_coro_t default_completion_token_type; /// Construct the adapted executor from the inner executor type. template <typename InnerExecutor1> executor_with_default(const InnerExecutor1& ex, constraint_t< conditional_t< !is_same<InnerExecutor1, executor_with_default>::value, is_convertible<InnerExecutor1, InnerExecutor>, false_type >::value > = 0) noexcept : InnerExecutor(ex) { } }; /// Type alias to adapt an I/O object to use @c use_coro_t as its /// default completion token type. template <typename T> using as_default_on_t = typename T::template rebind_executor< executor_with_default<typename T::executor_type>>::other; /// Function helper to adapt an I/O object to use @c use_coro_t as its /// default completion token type. template <typename T> static typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other as_default_on(T&& object) { return typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other(static_cast<T&&>(object)); } #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) const char* file_name_; int line_; const char* function_name_; #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) private: Allocator allocator_; }; /// A @ref completion_token object that represents the currently executing /// resumable coroutine. /** * See the documentation for boost::asio::use_coro_t for a usage example. */ #if defined(GENERATING_DOCUMENTATION) constexpr use_coro_t<> use_coro; #else constexpr use_coro_t<> use_coro(0, 0, 0); #endif } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/use_coro.hpp> #include <boost/asio/experimental/coro.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_USE_CORO_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/as_single.hpp
// // experimental/as_single.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_AS_SINGLE_HPP #define BOOST_ASIO_EXPERIMENTAL_AS_SINGLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { /// A @ref completion_token adapter used to specify that the completion handler /// arguments should be combined into a single argument. /** * The as_single_t class is used to indicate that any arguments to the * completion handler should be combined and passed as a single argument. * If there is already one argument, that argument is passed as-is. If * there is more than argument, the arguments are first moved into a * @c std::tuple and that tuple is then passed to the completion handler. */ template <typename CompletionToken> class as_single_t { public: /// Tag type used to prevent the "default" constructor from being used for /// conversions. struct default_constructor_tag {}; /// Default constructor. /** * This constructor is only valid if the underlying completion token is * default constructible and move constructible. The underlying completion * token is itself defaulted as an argument to allow it to capture a source * location. */ constexpr as_single_t( default_constructor_tag = default_constructor_tag(), CompletionToken token = CompletionToken()) : token_(static_cast<CompletionToken&&>(token)) { } /// Constructor. template <typename T> constexpr explicit as_single_t( T&& completion_token) : token_(static_cast<T&&>(completion_token)) { } /// Adapts an executor to add the @c as_single_t completion token as the /// default. template <typename InnerExecutor> struct executor_with_default : InnerExecutor { /// Specify @c as_single_t as the default completion token type. typedef as_single_t default_completion_token_type; /// Construct the adapted executor from the inner executor type. executor_with_default(const InnerExecutor& ex) noexcept : InnerExecutor(ex) { } /// Convert the specified executor to the inner executor type, then use /// that to construct the adapted executor. template <typename OtherExecutor> executor_with_default(const OtherExecutor& ex, constraint_t< is_convertible<OtherExecutor, InnerExecutor>::value > = 0) noexcept : InnerExecutor(ex) { } }; /// Type alias to adapt an I/O object to use @c as_single_t as its /// default completion token type. template <typename T> using as_default_on_t = typename T::template rebind_executor< executor_with_default<typename T::executor_type>>::other; /// Function helper to adapt an I/O object to use @c as_single_t as its /// default completion token type. template <typename T> static typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other as_default_on(T&& object) { return typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other(static_cast<T&&>(object)); } //private: CompletionToken token_; }; /// Adapt a @ref completion_token to specify that the completion handler /// arguments should be combined into a single argument. template <typename CompletionToken> BOOST_ASIO_NODISCARD inline constexpr as_single_t<decay_t<CompletionToken>> as_single(CompletionToken&& completion_token) { return as_single_t<decay_t<CompletionToken>>( static_cast<CompletionToken&&>(completion_token)); } } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/as_single.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_AS_SINGLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/channel_traits.hpp
// // experimental/channel_traits.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP #define BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <deque> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/error.hpp> #include <boost/asio/experimental/channel_error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { #if defined(GENERATING_DOCUMENTATION) template <typename... Signatures> struct channel_traits { /// Rebind the traits to a new set of signatures. /** * This nested structure must have a single nested type @c other that * aliases a traits type with the specified set of signatures. */ template <typename... NewSignatures> struct rebind { typedef user_defined other; }; /// Determine the container for the specified elements. /** * This nested structure must have a single nested type @c other that * aliases a container type for the specified element type. */ template <typename Element> struct container { typedef user_defined type; }; /// The signature of a channel cancellation notification. typedef void receive_cancelled_signature(...); /// Invoke the specified handler with a cancellation notification. template <typename F> static void invoke_receive_cancelled(F f); /// The signature of a channel closed notification. typedef void receive_closed_signature(...); /// Invoke the specified handler with a closed notification. template <typename F> static void invoke_receive_closed(F f); }; #else // defined(GENERATING_DOCUMENTATION) /// Traits used for customising channel behaviour. template <typename... Signatures> struct channel_traits { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; }; template <typename R> struct channel_traits<R(boost::system::error_code)> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(boost::system::error_code); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)(e); } typedef R receive_closed_signature(boost::system::error_code); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)(e); } }; template <typename R, typename... Args, typename... Signatures> struct channel_traits<R(boost::system::error_code, Args...), Signatures...> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(boost::system::error_code, Args...); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)(e, decay_t<Args>()...); } typedef R receive_closed_signature(boost::system::error_code, Args...); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)(e, decay_t<Args>()...); } }; template <typename R> struct channel_traits<R(std::exception_ptr)> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(std::exception_ptr); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)( std::make_exception_ptr(boost::system::system_error(e))); } typedef R receive_closed_signature(std::exception_ptr); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)( std::make_exception_ptr(boost::system::system_error(e))); } }; template <typename R, typename... Args, typename... Signatures> struct channel_traits<R(std::exception_ptr, Args...), Signatures...> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(std::exception_ptr, Args...); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)( std::make_exception_ptr(boost::system::system_error(e)), decay_t<Args>()...); } typedef R receive_closed_signature(std::exception_ptr, Args...); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)( std::make_exception_ptr(boost::system::system_error(e)), decay_t<Args>()...); } }; template <typename R> struct channel_traits<R()> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(boost::system::error_code); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)(e); } typedef R receive_closed_signature(boost::system::error_code); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)(e); } }; template <typename R, typename T> struct channel_traits<R(T)> { template <typename... NewSignatures> struct rebind { typedef channel_traits<NewSignatures...> other; }; template <typename Element> struct container { typedef std::deque<Element> type; }; typedef R receive_cancelled_signature(boost::system::error_code); template <typename F> static void invoke_receive_cancelled(F f) { const boost::system::error_code e = error::channel_cancelled; static_cast<F&&>(f)(e); } typedef R receive_closed_signature(boost::system::error_code); template <typename F> static void invoke_receive_closed(F f) { const boost::system::error_code e = error::channel_closed; static_cast<F&&>(f)(e); } }; #endif // defined(GENERATING_DOCUMENTATION) } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/coro.hpp
// // experimental/coro.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_CORO_HPP #define BOOST_ASIO_EXPERIMENTAL_CORO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/error.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/experimental/coro_traits.hpp> #include <boost/asio/experimental/detail/coro_promise_allocator.hpp> #include <boost/asio/experimental/detail/partial_promise.hpp> #include <boost/asio/post.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Signature, typename Return, typename Executor, typename Allocator> struct coro_promise; template <typename T, typename Coroutine> struct coro_with_arg; } // namespace detail /// The main type of a resumable coroutine. /** * Template parameter @c Yield specifies type or signature used by co_yield, * @c Return specifies the type used for co_return, and @c Executor specifies * the underlying executor type. */ template <typename Yield = void, typename Return = void, typename Executor = any_io_executor, typename Allocator = std::allocator<void>> struct coro { /// The traits of the coroutine. See boost::asio::experimental::coro_traits /// for details. using traits = coro_traits<Yield, Return, Executor>; /// The value that can be passed into a symmetrical cororoutine. @c void if /// asymmetrical. using input_type = typename traits::input_type; /// The type that can be passed out through a co_yield. using yield_type = typename traits::yield_type; /// The type that can be passed out through a co_return. using return_type = typename traits::return_type; /// The type received by a co_await or async_resume. Its a combination of /// yield and return. using result_type = typename traits::result_type; /// The signature used by the async_resume. using signature_type = typename traits::signature_type; /// Whether or not the coroutine is noexcept. constexpr static bool is_noexcept = traits::is_noexcept; /// The error type of the coroutine. Void for noexcept using error_type = typename traits::error_type; /// Completion handler type used by async_resume. using completion_handler = typename traits::completion_handler; /// The internal promise-type of the coroutine. using promise_type = detail::coro_promise<Yield, Return, Executor, Allocator>; #if !defined(GENERATING_DOCUMENTATION) template <typename T, typename Coroutine> friend struct detail::coro_with_arg; #endif // !defined(GENERATING_DOCUMENTATION) /// The executor type. using executor_type = Executor; /// The allocator type. using allocator_type = Allocator; #if !defined(GENERATING_DOCUMENTATION) friend struct detail::coro_promise<Yield, Return, Executor, Allocator>; #endif // !defined(GENERATING_DOCUMENTATION) /// The default constructor, gives an invalid coroutine. coro() = default; /// Move constructor. coro(coro&& lhs) noexcept : coro_(std::exchange(lhs.coro_, nullptr)) { } coro(const coro&) = delete; /// Move assignment. coro& operator=(coro&& lhs) noexcept { std::swap(coro_, lhs.coro_); return *this; } coro& operator=(const coro&) = delete; /// Destructor. Destroys the coroutine, if it holds a valid one. /** * @note This does not cancel an active coroutine. Destructing a resumable * coroutine, i.e. one with a call to async_resume that has not completed, is * undefined behaviour. */ ~coro() { if (coro_ != nullptr) { struct destroyer { detail::coroutine_handle<promise_type> handle; destroyer(const detail::coroutine_handle<promise_type>& handle) : handle(handle) { } destroyer(destroyer&& lhs) : handle(std::exchange(lhs.handle, nullptr)) { } destroyer(const destroyer&) = delete; void operator()() {} ~destroyer() { if (handle) handle.destroy(); } }; auto handle = detail::coroutine_handle<promise_type>::from_promise(*coro_); if (handle) boost::asio::dispatch(coro_->get_executor(), destroyer{handle}); } } /// Get the used executor. executor_type get_executor() const { if (coro_) return coro_->get_executor(); if constexpr (std::is_default_constructible_v<Executor>) return Executor{}; else throw std::logic_error("Coroutine has no executor"); } /// Get the used allocator. allocator_type get_allocator() const { if (coro_) return coro_->get_allocator(); if constexpr (std::is_default_constructible_v<Allocator>) return Allocator{}; else throw std::logic_error( "Coroutine has no available allocator without a constructed promise"); } /// Resume the coroutine. /** * @param token The completion token of the async resume. * * @attention Calling an invalid coroutine with a noexcept signature is * undefined behaviour. * * @note This overload is only available for coroutines without an input * value. */ template <typename CompletionToken> requires std::is_void_v<input_type> auto async_resume(CompletionToken&& token) & { return async_initiate<CompletionToken, typename traits::completion_handler>( initiate_async_resume(this), token); } /// Resume the coroutine. /** * @param token The completion token of the async resume. * * @attention Calling an invalid coroutine with a noexcept signature is * undefined behaviour. * * @note This overload is only available for coroutines with an input value. */ template <typename CompletionToken, detail::convertible_to<input_type> T> auto async_resume(T&& ip, CompletionToken&& token) & { return async_initiate<CompletionToken, typename traits::completion_handler>( initiate_async_resume(this), token, std::forward<T>(ip)); } /// Operator used for coroutines without input value. auto operator co_await() requires (std::is_void_v<input_type>) { return awaitable_t{*this}; } /// Operator used for coroutines with input value. /** * @param ip The input value * * @returns An awaitable handle. * * @code * coro<void> push_values(coro<double(int)> c) * { * std::optional<double> res = co_await c(42); * } * @endcode */ template <detail::convertible_to<input_type> T> auto operator()(T&& ip) { return detail::coro_with_arg<std::decay_t<T>, coro>{ std::forward<T>(ip), *this}; } /// Check whether the coroutine is open, i.e. can be resumed. bool is_open() const { if (coro_) { auto handle = detail::coroutine_handle<promise_type>::from_promise(*coro_); return handle && !handle.done(); } else return false; } /// Check whether the coroutine is open, i.e. can be resumed. explicit operator bool() const { return is_open(); } private: struct awaitable_t; struct initiate_async_resume; explicit coro(promise_type* const cr) : coro_(cr) {} promise_type* coro_{nullptr}; }; /// A generator is a coro that returns void and yields value. template<typename T, typename Executor = boost::asio::any_io_executor, typename Allocator = std::allocator<void>> using generator = coro<T, void, Executor, Allocator>; /// A task is a coro that does not yield values template<typename T, typename Executor = boost::asio::any_io_executor, typename Allocator = std::allocator<void>> using task = coro<void(), T, Executor, Allocator>; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/coro.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CORO_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/append.hpp
// // experimental/append.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_APPEND_HPP #define BOOST_ASIO_EXPERIMENTAL_APPEND_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/append.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { #if !defined(BOOST_ASIO_NO_DEPRECATED) using boost::asio::append_t; using boost::asio::append; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_APPEND_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/channel.hpp
// // experimental/channel.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CHANNEL_HPP #define BOOST_ASIO_EXPERIMENTAL_CHANNEL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/is_executor.hpp> #include <boost/asio/experimental/basic_channel.hpp> #include <boost/asio/experimental/channel_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename ExecutorOrSignature, typename = void> struct channel_type { template <typename... Signatures> struct inner { typedef basic_channel<any_io_executor, channel_traits<>, ExecutorOrSignature, Signatures...> type; }; }; template <typename ExecutorOrSignature> struct channel_type<ExecutorOrSignature, enable_if_t< is_executor<ExecutorOrSignature>::value || execution::is_executor<ExecutorOrSignature>::value >> { template <typename... Signatures> struct inner { typedef basic_channel<ExecutorOrSignature, channel_traits<>, Signatures...> type; }; }; } // namespace detail /// Template type alias for common use of channel. template <typename ExecutorOrSignature, typename... Signatures> using channel = typename detail::channel_type< ExecutorOrSignature>::template inner<Signatures...>::type; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CHANNEL_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/concurrent_channel.hpp
// // experimental/concurrent_channel.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_CONCURRENT_CHANNEL_HPP #define BOOST_ASIO_EXPERIMENTAL_CONCURRENT_CHANNEL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/is_executor.hpp> #include <boost/asio/experimental/basic_concurrent_channel.hpp> #include <boost/asio/experimental/channel_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename ExecutorOrSignature, typename = void> struct concurrent_channel_type { template <typename... Signatures> struct inner { typedef basic_concurrent_channel<any_io_executor, channel_traits<>, ExecutorOrSignature, Signatures...> type; }; }; template <typename ExecutorOrSignature> struct concurrent_channel_type<ExecutorOrSignature, enable_if_t< is_executor<ExecutorOrSignature>::value || execution::is_executor<ExecutorOrSignature>::value >> { template <typename... Signatures> struct inner { typedef basic_concurrent_channel<ExecutorOrSignature, channel_traits<>, Signatures...> type; }; }; } // namespace detail /// Template type alias for common use of channel. template <typename ExecutorOrSignature, typename... Signatures> using concurrent_channel = typename detail::concurrent_channel_type< ExecutorOrSignature>::template inner<Signatures...>::type; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_CONCURRENT_CHANNEL_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/co_spawn.hpp
// // experimental/co_spawn.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_CO_SPAWN_HPP #define BOOST_ASIO_EXPERIMENTAL_CO_SPAWN_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <utility> #include <boost/asio/compose.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/experimental/coro.hpp> #include <boost/asio/experimental/deferred.hpp> #include <boost/asio/experimental/prepend.hpp> #include <boost/asio/redirect_error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename T, typename U, typename Executor> struct coro_spawn_op { coro<T, U, Executor> c; void operator()(auto& self) { auto op = c.async_resume(deferred); std::move(op)((prepend)(std::move(self), 0)); } void operator()(auto& self, int, auto... res) { self.complete(std::move(res)...); } }; } // namespace detail /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename T, typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE( CompletionToken, void(std::exception_ptr, T)) co_spawn(coro<void, T, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void(std::exception_ptr, T)>( detail::coro_spawn_op<void, T, Executor>{std::move(c)}, token, exec); } /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename T, typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE( CompletionToken, void(std::exception_ptr, T)) co_spawn(coro<void(), T, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void(std::exception_ptr, T)>( detail::coro_spawn_op<void(), T, Executor>{std::move(c)}, token, exec); } /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename T, typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(T)) co_spawn(coro<void() noexcept, T, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void(T)>( detail::coro_spawn_op<void() noexcept, T, Executor>{std::move(c)}, token, exec); } /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE( CompletionToken, void(std::exception_ptr)) co_spawn(coro<void, void, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void(std::exception_ptr)>( detail::coro_spawn_op<void, void, Executor>{std::move(c)}, token, exec); } /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE( CompletionToken, void(std::exception_ptr)) co_spawn(coro<void(), void, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void(std::exception_ptr)>( detail::coro_spawn_op<void(), void, Executor>{std::move(c)}, token, exec); } /// Spawn a resumable coroutine. /** * This function spawns the coroutine for execution on its executor. It binds * the lifetime of the coroutine to the executor. * * @param c The coroutine * * @param token The completion token * * @returns Implementation defined */ template <typename Executor, typename CompletionToken> BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) co_spawn(coro<void() noexcept, void, Executor> c, CompletionToken&& token) { auto exec = c.get_executor(); return async_compose<CompletionToken, void()>( detail::coro_spawn_op<void() noexcept, void, Executor>{std::move(c)}, token, exec); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif //BOOST_ASIO_EXPERIMENTAL_CO_SPAWN_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/use_promise.hpp
// // experimental/use_promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_USE_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_USE_PROMISE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <memory> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { template <typename Allocator = std::allocator<void>> struct use_promise_t { /// The allocator type. The allocator is used when constructing the /// @c promise object for a given asynchronous operation. typedef Allocator allocator_type; /// Construct using default-constructed allocator. constexpr use_promise_t() { } /// Construct using specified allocator. explicit use_promise_t(const Allocator& allocator) : allocator_(allocator) { } /// Obtain allocator. allocator_type get_allocator() const noexcept { return allocator_; } /// Adapts an executor to add the @c use_promise_t completion token as the /// default. template <typename InnerExecutor> struct executor_with_default : InnerExecutor { /// Specify @c use_promise_t as the default completion token type. typedef use_promise_t<Allocator> default_completion_token_type; /// Construct the adapted executor from the inner executor type. executor_with_default(const InnerExecutor& ex) noexcept : InnerExecutor(ex) { } /// Convert the specified executor to the inner executor type, then use /// that to construct the adapted executor. template <typename OtherExecutor> executor_with_default(const OtherExecutor& ex, constraint_t< is_convertible<OtherExecutor, InnerExecutor>::value > = 0) noexcept : InnerExecutor(ex) { } }; /// Function helper to adapt an I/O object to use @c use_promise_t as its /// default completion token type. template <typename T> static typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other as_default_on(T&& object) { return typename decay_t<T>::template rebind_executor< executor_with_default<typename decay_t<T>::executor_type> >::other(static_cast<T&&>(object)); } /// Specify an alternate allocator. template <typename OtherAllocator> use_promise_t<OtherAllocator> rebind(const OtherAllocator& allocator) const { return use_promise_t<OtherAllocator>(allocator); } private: Allocator allocator_; }; constexpr use_promise_t<> use_promise; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/impl/use_promise.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_USE_CORO_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/promise.hpp
// // experimental/impl/promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_IMPL_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_IMPL_PROMISE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/cancellation_signal.hpp> #include <boost/asio/detail/utility.hpp> #include <boost/asio/error.hpp> #include <boost/system/system_error.hpp> #include <tuple> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { template<typename Signature = void(), typename Executor = boost::asio::any_io_executor, typename Allocator = std::allocator<void>> struct promise; namespace detail { template<typename Signature, typename Executor, typename Allocator> struct promise_impl; template<typename... Ts, typename Executor, typename Allocator> struct promise_impl<void(Ts...), Executor, Allocator> { using result_type = std::tuple<Ts...>; promise_impl(Allocator allocator, Executor executor) : allocator(std::move(allocator)), executor(std::move(executor)) { } promise_impl(const promise_impl&) = delete; ~promise_impl() { if (completion) this->cancel_(); if (done) reinterpret_cast<result_type*>(&result)->~result_type(); } aligned_storage_t<sizeof(result_type), alignof(result_type)> result; std::atomic<bool> done{false}; cancellation_signal cancel; Allocator allocator; Executor executor; template<typename Func, std::size_t... Idx> void apply_impl(Func f, boost::asio::detail::index_sequence<Idx...>) { auto& result_type = *reinterpret_cast<promise_impl::result_type*>(&result); f(std::get<Idx>(std::move(result_type))...); } using allocator_type = Allocator; allocator_type get_allocator() {return allocator;} using executor_type = Executor; executor_type get_executor() {return executor;} template<typename Func> void apply(Func f) { apply_impl(std::forward<Func>(f), boost::asio::detail::make_index_sequence<sizeof...(Ts)>{}); } struct completion_base { virtual void invoke(Ts&&...ts) = 0; }; template<typename Alloc, typename WaitHandler_> struct completion_impl final : completion_base { WaitHandler_ handler; Alloc allocator; void invoke(Ts&&... ts) { auto h = std::move(handler); using alloc_t = typename std::allocator_traits< typename boost::asio::decay<Alloc>::type>::template rebind_alloc<completion_impl>; alloc_t alloc_{allocator}; this->~completion_impl(); std::allocator_traits<alloc_t>::deallocate(alloc_, this, 1u); std::move(h)(std::forward<Ts>(ts)...); } template<typename Alloc_, typename Handler_> completion_impl(Alloc_&& alloc, Handler_&& wh) : handler(std::forward<Handler_>(wh)), allocator(std::forward<Alloc_>(alloc)) { } }; completion_base* completion = nullptr; typename boost::asio::aligned_storage<sizeof(void*) * 4, alignof(completion_base)>::type completion_opt; template<typename Alloc, typename Handler> void set_completion(Alloc&& alloc, Handler&& handler) { if (completion) cancel_(); using impl_t = completion_impl< typename boost::asio::decay<Alloc>::type, Handler>; using alloc_t = typename std::allocator_traits< typename boost::asio::decay<Alloc>::type>::template rebind_alloc<impl_t>; alloc_t alloc_{alloc}; auto p = std::allocator_traits<alloc_t>::allocate(alloc_, 1u); completion = new (p) impl_t(std::forward<Alloc>(alloc), std::forward<Handler>(handler)); } template<typename... T_> void complete(T_&&... ts) { assert(completion); std::exchange(completion, nullptr)->invoke(std::forward<T_>(ts)...); } template<std::size_t... Idx> void complete_with_result_impl(boost::asio::detail::index_sequence<Idx...>) { auto& result_type = *reinterpret_cast<promise_impl::result_type*>(&result); this->complete(std::get<Idx>(std::move(result_type))...); } void complete_with_result() { complete_with_result_impl( boost::asio::detail::make_index_sequence<sizeof...(Ts)>{}); } template<typename... T_> void cancel_impl_(std::exception_ptr*, T_*...) { complete( std::make_exception_ptr( boost::system::system_error( boost::asio::error::operation_aborted)), T_{}...); } template<typename... T_> void cancel_impl_(boost::system::error_code*, T_*...) { complete(boost::asio::error::operation_aborted, T_{}...); } template<typename... T_> void cancel_impl_(T_*...) { complete(T_{}...); } void cancel_() { cancel_impl_(static_cast<Ts*>(nullptr)...); } }; template<typename Signature = void(), typename Executor = boost::asio::any_io_executor, typename Allocator = any_io_executor> struct promise_handler; template<typename... Ts, typename Executor, typename Allocator> struct promise_handler<void(Ts...), Executor, Allocator> { using promise_type = promise<void(Ts...), Executor, Allocator>; promise_handler( Allocator allocator, Executor executor) // get_associated_allocator(exec) : impl_( std::allocate_shared<promise_impl<void(Ts...), Executor, Allocator>>( allocator, allocator, executor)) { } std::shared_ptr<promise_impl<void(Ts...), Executor, Allocator>> impl_; using cancellation_slot_type = cancellation_slot; cancellation_slot_type get_cancellation_slot() const noexcept { return impl_->cancel.slot(); } using allocator_type = Allocator; allocator_type get_allocator() const noexcept { return impl_->get_allocator(); } using executor_type = Executor; Executor get_executor() const noexcept { return impl_->get_executor(); } auto make_promise() -> promise<void(Ts...), executor_type, allocator_type> { return promise<void(Ts...), executor_type, allocator_type>{impl_}; } void operator()(std::remove_reference_t<Ts>... ts) { assert(impl_); using result_type = typename promise_impl< void(Ts...), allocator_type, executor_type>::result_type ; new (&impl_->result) result_type(std::move(ts)...); impl_->done = true; if (impl_->completion) impl_->complete_with_result(); } }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_PROMISE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/co_composed.hpp
// // experimental/impl/co_composed.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_IMPL_EXPERIMENTAL_CO_COMPOSED_HPP #define BOOST_ASIO_IMPL_EXPERIMENTAL_CO_COMPOSED_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <new> #include <tuple> #include <variant> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/associator.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/cancellation_state.hpp> #include <boost/asio/detail/composed_work.hpp> #include <boost/asio/detail/recycling_allocator.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/error.hpp> #if defined(BOOST_ASIO_HAS_STD_COROUTINE) # include <coroutine> #else // defined(BOOST_ASIO_HAS_STD_COROUTINE) # include <experimental/coroutine> #endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) # include <boost/asio/detail/source_location.hpp> # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { #if defined(BOOST_ASIO_HAS_STD_COROUTINE) using std::coroutine_handle; using std::suspend_always; using std::suspend_never; #else // defined(BOOST_ASIO_HAS_STD_COROUTINE) using std::experimental::coroutine_handle; using std::experimental::suspend_always; using std::experimental::suspend_never; #endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) using boost::asio::detail::composed_io_executors; using boost::asio::detail::composed_work; using boost::asio::detail::composed_work_guard; using boost::asio::detail::get_composed_io_executor; using boost::asio::detail::make_composed_io_executors; using boost::asio::detail::recycling_allocator; using boost::asio::detail::throw_error; template <typename Executors, typename Handler, typename Return> class co_composed_state; template <typename Executors, typename Handler, typename Return> class co_composed_handler_base; template <typename Executors, typename Handler, typename Return> class co_composed_promise; template <completion_signature... Signatures> class co_composed_returns { }; struct co_composed_on_suspend { void (*fn_)(void*) = nullptr; void* arg_ = nullptr; }; template <typename... T> struct co_composed_completion : std::tuple<T&&...> { template <typename... U> co_composed_completion(U&&... u) noexcept : std::tuple<T&&...>(std::forward<U>(u)...) { } }; template <typename Executors, typename Handler, typename Return, typename Signature> class co_composed_state_return_overload; template <typename Executors, typename Handler, typename Return, typename R, typename... Args> class co_composed_state_return_overload< Executors, Handler, Return, R(Args...)> { public: using derived_type = co_composed_state<Executors, Handler, Return>; using promise_type = co_composed_promise<Executors, Handler, Return>; using return_type = std::tuple<Args...>; void on_cancellation_complete_with(Args... args) { derived_type& state = *static_cast<derived_type*>(this); state.return_value_ = std::make_tuple(std::move(args)...); state.cancellation_on_suspend_fn( [](void* p) { auto& promise = *static_cast<promise_type*>(p); co_composed_handler_base<Executors, Handler, Return> composed_handler(promise); Handler handler(std::move(promise.state().handler_)); return_type result( std::move(std::get<return_type>(promise.state().return_value_))); co_composed_handler_base<Executors, Handler, Return>(std::move(composed_handler)); std::apply(std::move(handler), std::move(result)); }); } }; template <typename Executors, typename Handler, typename Return> class co_composed_state_return; template <typename Executors, typename Handler, typename... Signatures> class co_composed_state_return< Executors, Handler, co_composed_returns<Signatures...>> : public co_composed_state_return_overload<Executors, Handler, co_composed_returns<Signatures...>, Signatures>... { public: using co_composed_state_return_overload<Executors, Handler, co_composed_returns<Signatures...>, Signatures>::on_cancellation_complete_with...; private: template <typename, typename, typename, typename> friend class co_composed_promise_return_overload; template <typename, typename, typename, typename> friend class co_composed_state_return_overload; std::variant<std::monostate, typename co_composed_state_return_overload< Executors, Handler, co_composed_returns<Signatures...>, Signatures>::return_type...> return_value_; }; template <typename Executors, typename Handler, typename Return, typename... Signatures> struct co_composed_state_default_cancellation_on_suspend_impl; template <typename Executors, typename Handler, typename Return> struct co_composed_state_default_cancellation_on_suspend_impl< Executors, Handler, Return> { static constexpr void (*fn())(void*) { return nullptr; } }; template <typename Executors, typename Handler, typename Return, typename R, typename... Args, typename... Signatures> struct co_composed_state_default_cancellation_on_suspend_impl< Executors, Handler, Return, R(Args...), Signatures...> { static constexpr void (*fn())(void*) { return co_composed_state_default_cancellation_on_suspend_impl< Executors, Handler, Return, Signatures...>::fn(); } }; template <typename Executors, typename Handler, typename Return, typename R, typename... Args, typename... Signatures> struct co_composed_state_default_cancellation_on_suspend_impl<Executors, Handler, Return, R(boost::system::error_code, Args...), Signatures...> { using promise_type = co_composed_promise<Executors, Handler, Return>; using return_type = std::tuple<boost::system::error_code, Args...>; static constexpr void (*fn())(void*) { if constexpr ((is_constructible<Args>::value && ...)) { return [](void* p) { auto& promise = *static_cast<promise_type*>(p); co_composed_handler_base<Executors, Handler, Return> composed_handler(promise); Handler handler(std::move(promise.state().handler_)); co_composed_handler_base<Executors, Handler, Return>(std::move(composed_handler)); std::move(handler)( boost::system::error_code(boost::asio::error::operation_aborted), Args{}...); }; } else { return co_composed_state_default_cancellation_on_suspend_impl< Executors, Handler, Return, Signatures...>::fn(); } } }; template <typename Executors, typename Handler, typename Return, typename R, typename... Args, typename... Signatures> struct co_composed_state_default_cancellation_on_suspend_impl<Executors, Handler, Return, R(std::exception_ptr, Args...), Signatures...> { using promise_type = co_composed_promise<Executors, Handler, Return>; using return_type = std::tuple<std::exception_ptr, Args...>; static constexpr void (*fn())(void*) { if constexpr ((is_constructible<Args>::value && ...)) { return [](void* p) { auto& promise = *static_cast<promise_type*>(p); co_composed_handler_base<Executors, Handler, Return> composed_handler(promise); Handler handler(std::move(promise.state().handler_)); co_composed_handler_base<Executors, Handler, Return>(std::move(composed_handler)); std::move(handler)( std::make_exception_ptr( boost::system::system_error( boost::asio::error::operation_aborted, "co_await")), Args{}...); }; } else { return co_composed_state_default_cancellation_on_suspend_impl< Executors, Handler, Return, Signatures...>::fn(); } } }; template <typename Executors, typename Handler, typename Return> struct co_composed_state_default_cancellation_on_suspend; template <typename Executors, typename Handler, typename... Signatures> struct co_composed_state_default_cancellation_on_suspend< Executors, Handler, co_composed_returns<Signatures...>> : co_composed_state_default_cancellation_on_suspend_impl<Executors, Handler, co_composed_returns<Signatures...>, Signatures...> { }; template <typename Executors, typename Handler, typename Return> class co_composed_state_cancellation { public: using cancellation_slot_type = cancellation_slot; cancellation_slot_type get_cancellation_slot() const noexcept { return cancellation_state_.slot(); } cancellation_state get_cancellation_state() const noexcept { return cancellation_state_; } void reset_cancellation_state() { cancellation_state_ = cancellation_state( (get_associated_cancellation_slot)( static_cast<co_composed_state<Executors, Handler, Return>*>( this)->handler())); } template <typename Filter> void reset_cancellation_state(Filter filter) { cancellation_state_ = cancellation_state( (get_associated_cancellation_slot)( static_cast<co_composed_state<Executors, Handler, Return>*>( this)->handler()), filter, filter); } template <typename InFilter, typename OutFilter> void reset_cancellation_state(InFilter&& in_filter, OutFilter&& out_filter) { cancellation_state_ = cancellation_state( (get_associated_cancellation_slot)( static_cast<co_composed_state<Executors, Handler, Return>*>( this)->handler()), std::forward<InFilter>(in_filter), std::forward<OutFilter>(out_filter)); } cancellation_type_t cancelled() const noexcept { return cancellation_state_.cancelled(); } void clear_cancellation_slot() noexcept { cancellation_state_.slot().clear(); } [[nodiscard]] bool throw_if_cancelled() const noexcept { return throw_if_cancelled_; } void throw_if_cancelled(bool b) noexcept { throw_if_cancelled_ = b; } [[nodiscard]] bool complete_if_cancelled() const noexcept { return complete_if_cancelled_; } void complete_if_cancelled(bool b) noexcept { complete_if_cancelled_ = b; } private: template <typename, typename, typename> friend class co_composed_promise; template <typename, typename, typename, typename> friend class co_composed_state_return_overload; void cancellation_on_suspend_fn(void (*fn)(void*)) { cancellation_on_suspend_fn_ = fn; } void check_for_cancellation_on_transform() { if (throw_if_cancelled_ && !!cancelled()) throw_error(boost::asio::error::operation_aborted, "co_await"); } bool check_for_cancellation_on_suspend( co_composed_promise<Executors, Handler, Return>& promise) noexcept { if (complete_if_cancelled_ && !!cancelled() && cancellation_on_suspend_fn_) { promise.state().work_.reset(); promise.state().on_suspend_->fn_ = cancellation_on_suspend_fn_; promise.state().on_suspend_->arg_ = &promise; return false; } return true; } cancellation_state cancellation_state_; void (*cancellation_on_suspend_fn_)(void*) = co_composed_state_default_cancellation_on_suspend< Executors, Handler, Return>::fn(); bool throw_if_cancelled_ = false; bool complete_if_cancelled_ = true; }; template <typename Executors, typename Handler, typename Return> requires is_same< typename associated_cancellation_slot< Handler, cancellation_slot >::asio_associated_cancellation_slot_is_unspecialised, void>::value class co_composed_state_cancellation<Executors, Handler, Return> { public: void reset_cancellation_state() { } template <typename Filter> void reset_cancellation_state(Filter) { } template <typename InFilter, typename OutFilter> void reset_cancellation_state(InFilter&&, OutFilter&&) { } cancellation_type_t cancelled() const noexcept { return cancellation_type::none; } void clear_cancellation_slot() noexcept { } [[nodiscard]] bool throw_if_cancelled() const noexcept { return false; } void throw_if_cancelled(bool) noexcept { } [[nodiscard]] bool complete_if_cancelled() const noexcept { return false; } void complete_if_cancelled(bool) noexcept { } private: template <typename, typename, typename> friend class co_composed_promise; template <typename, typename, typename, typename> friend class co_composed_state_return_overload; void cancellation_on_suspend_fn(void (*)(void*)) { } void check_for_cancellation_on_transform() noexcept { } bool check_for_cancellation_on_suspend( co_composed_promise<Executors, Handler, Return>&) noexcept { return true; } }; template <typename Executors, typename Handler, typename Return> class co_composed_state : public co_composed_state_return<Executors, Handler, Return>, public co_composed_state_cancellation<Executors, Handler, Return> { public: using io_executor_type = typename composed_work_guard< typename composed_work<Executors>::head_type>::executor_type; template <typename H> co_composed_state(composed_io_executors<Executors>&& executors, H&& h, co_composed_on_suspend& on_suspend) : work_(std::move(executors)), handler_(std::forward<H>(h)), on_suspend_(&on_suspend) { this->reset_cancellation_state(enable_terminal_cancellation()); } io_executor_type get_io_executor() const noexcept { return work_.head_.get_executor(); } template <typename... Args> [[nodiscard]] co_composed_completion<Args...> complete(Args&&... args) requires requires { declval<Handler>()(std::forward<Args>(args)...); } { return co_composed_completion<Args...>(std::forward<Args>(args)...); } const Handler& handler() const noexcept { return handler_; } private: template <typename, typename, typename> friend class co_composed_handler_base; template <typename, typename, typename> friend class co_composed_promise; template <typename, typename, typename, typename> friend class co_composed_promise_return_overload; template <typename, typename, typename> friend class co_composed_state_cancellation; template <typename, typename, typename, typename> friend class co_composed_state_return_overload; template <typename, typename, typename, typename...> friend struct co_composed_state_default_cancellation_on_suspend_impl; composed_work<Executors> work_; Handler handler_; co_composed_on_suspend* on_suspend_; }; template <typename Executors, typename Handler, typename Return> class co_composed_handler_cancellation { public: using cancellation_slot_type = cancellation_slot; cancellation_slot_type get_cancellation_slot() const noexcept { return static_cast< const co_composed_handler_base<Executors, Handler, Return>*>( this)->promise().state().get_cancellation_slot(); } }; template <typename Executors, typename Handler, typename Return> requires is_same< typename associated_cancellation_slot< Handler, cancellation_slot >::asio_associated_cancellation_slot_is_unspecialised, void>::value class co_composed_handler_cancellation<Executors, Handler, Return> { }; template <typename Executors, typename Handler, typename Return> class co_composed_handler_base : public co_composed_handler_cancellation<Executors, Handler, Return> { public: co_composed_handler_base( co_composed_promise<Executors, Handler, Return>& p) noexcept : p_(&p) { } co_composed_handler_base(co_composed_handler_base&& other) noexcept : p_(std::exchange(other.p_, nullptr)) { } ~co_composed_handler_base() { if (p_) [[unlikely]] p_->destroy(); } co_composed_promise<Executors, Handler, Return>& promise() const noexcept { return *p_; } protected: void resume(void* result) { co_composed_on_suspend on_suspend{}; std::exchange(p_, nullptr)->resume(p_, result, on_suspend); if (on_suspend.fn_) on_suspend.fn_(on_suspend.arg_); } private: co_composed_promise<Executors, Handler, Return>* p_; }; template <typename Executors, typename Handler, typename Return, typename Signature> class co_composed_handler; template <typename Executors, typename Handler, typename Return, typename R, typename... Args> class co_composed_handler<Executors, Handler, Return, R(Args...)> : public co_composed_handler_base<Executors, Handler, Return> { public: using co_composed_handler_base<Executors, Handler, Return>::co_composed_handler_base; using result_type = std::tuple<decay_t<Args>...>; template <typename... T> void operator()(T&&... args) { result_type result(std::forward<T>(args)...); this->resume(&result); } static auto on_resume(void* result) { auto& args = *static_cast<result_type*>(result); if constexpr (sizeof...(Args) == 0) return; else if constexpr (sizeof...(Args) == 1) return std::move(std::get<0>(args)); else return std::move(args); } }; template <typename Executors, typename Handler, typename Return, typename R, typename... Args> class co_composed_handler<Executors, Handler, Return, R(boost::system::error_code, Args...)> : public co_composed_handler_base<Executors, Handler, Return> { public: using co_composed_handler_base<Executors, Handler, Return>::co_composed_handler_base; using args_type = std::tuple<decay_t<Args>...>; using result_type = std::tuple<boost::system::error_code, args_type>; template <typename... T> void operator()(const boost::system::error_code& ec, T&&... args) { result_type result(ec, args_type(std::forward<T>(args)...)); this->resume(&result); } static auto on_resume(void* result) { auto& [ec, args] = *static_cast<result_type*>(result); throw_error(ec); if constexpr (sizeof...(Args) == 0) return; else if constexpr (sizeof...(Args) == 1) return std::move(std::get<0>(args)); else return std::move(args); } }; template <typename Executors, typename Handler, typename Return, typename R, typename... Args> class co_composed_handler<Executors, Handler, Return, R(std::exception_ptr, Args...)> : public co_composed_handler_base<Executors, Handler, Return> { public: using co_composed_handler_base<Executors, Handler, Return>::co_composed_handler_base; using args_type = std::tuple<decay_t<Args>...>; using result_type = std::tuple<std::exception_ptr, args_type>; template <typename... T> void operator()(std::exception_ptr ex, T&&... args) { result_type result(std::move(ex), args_type(std::forward<T>(args)...)); this->resume(&result); } static auto on_resume(void* result) { auto& [ex, args] = *static_cast<result_type*>(result); if (ex) std::rethrow_exception(ex); if constexpr (sizeof...(Args) == 0) return; else if constexpr (sizeof...(Args) == 1) return std::move(std::get<0>(args)); else return std::move(args); } }; template <typename Executors, typename Handler, typename Return> class co_composed_promise_return; template <typename Executors, typename Handler> class co_composed_promise_return<Executors, Handler, co_composed_returns<>> { public: auto final_suspend() noexcept { return suspend_never(); } void return_void() noexcept { } }; template <typename Executors, typename Handler, typename Return, typename Signature> class co_composed_promise_return_overload; template <typename Executors, typename Handler, typename Return, typename R, typename... Args> class co_composed_promise_return_overload< Executors, Handler, Return, R(Args...)> { public: using derived_type = co_composed_promise<Executors, Handler, Return>; using return_type = std::tuple<Args...>; void return_value(std::tuple<Args...>&& value) { derived_type& promise = *static_cast<derived_type*>(this); promise.state().return_value_ = std::move(value); promise.state().work_.reset(); promise.state().on_suspend_->arg_ = this; promise.state().on_suspend_->fn_ = [](void* p) { auto& promise = *static_cast<derived_type*>(p); co_composed_handler_base<Executors, Handler, Return> composed_handler(promise); Handler handler(std::move(promise.state().handler_)); return_type result( std::move(std::get<return_type>(promise.state().return_value_))); co_composed_handler_base<Executors, Handler, Return>(std::move(composed_handler)); std::apply(std::move(handler), std::move(result)); }; } }; template <typename Executors, typename Handler, typename... Signatures> class co_composed_promise_return<Executors, Handler, co_composed_returns<Signatures...>> : public co_composed_promise_return_overload<Executors, Handler, co_composed_returns<Signatures...>, Signatures>... { public: auto final_suspend() noexcept { return suspend_always(); } using co_composed_promise_return_overload<Executors, Handler, co_composed_returns<Signatures...>, Signatures>::return_value...; private: template <typename, typename, typename, typename> friend class co_composed_promise_return_overload; }; template <typename Executors, typename Handler, typename Return> class co_composed_promise : public co_composed_promise_return<Executors, Handler, Return> { public: template <typename... Args> void* operator new(std::size_t size, co_composed_state<Executors, Handler, Return>& state, Args&&...) { block_allocator_type allocator( (get_associated_allocator)(state.handler_, recycling_allocator<void>())); block* base_ptr = std::allocator_traits<block_allocator_type>::allocate( allocator, blocks(sizeof(allocator_type)) + blocks(size)); new (static_cast<void*>(base_ptr)) allocator_type(std::move(allocator)); return base_ptr + blocks(sizeof(allocator_type)); } template <typename C, typename... Args> void* operator new(std::size_t size, C&&, co_composed_state<Executors, Handler, Return>& state, Args&&...) { return co_composed_promise::operator new(size, state); } void operator delete(void* ptr, std::size_t size) { block* base_ptr = static_cast<block*>(ptr) - blocks(sizeof(allocator_type)); allocator_type* allocator_ptr = std::launder( static_cast<allocator_type*>(static_cast<void*>(base_ptr))); block_allocator_type block_allocator(std::move(*allocator_ptr)); allocator_ptr->~allocator_type(); std::allocator_traits<block_allocator_type>::deallocate(block_allocator, base_ptr, blocks(sizeof(allocator_type)) + blocks(size)); } template <typename... Args> co_composed_promise( co_composed_state<Executors, Handler, Return>& state, Args&&...) : state_(state) { } template <typename C, typename... Args> co_composed_promise(C&&, co_composed_state<Executors, Handler, Return>& state, Args&&...) : state_(state) { } void destroy() noexcept { coroutine_handle<co_composed_promise>::from_promise(*this).destroy(); } void resume(co_composed_promise*& owner, void* result, co_composed_on_suspend& on_suspend) { state_.on_suspend_ = &on_suspend; state_.clear_cancellation_slot(); owner_ = &owner; result_ = result; coroutine_handle<co_composed_promise>::from_promise(*this).resume(); } co_composed_state<Executors, Handler, Return>& state() noexcept { return state_; } void get_return_object() noexcept { } auto initial_suspend() noexcept { return suspend_never(); } void unhandled_exception() { if (owner_) *owner_ = this; throw; } template <async_operation Op> auto await_transform(Op&& op #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , boost::asio::detail::source_location location = boost::asio::detail::source_location::current() # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) ) { class [[nodiscard]] awaitable { public: awaitable(Op&& op, co_composed_promise& promise #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , const boost::asio::detail::source_location& location # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) ) : op_(std::forward<Op>(op)), promise_(promise) #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , location_(location) # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) { } constexpr bool await_ready() const noexcept { return false; } void await_suspend(coroutine_handle<co_composed_promise>) { if (promise_.state_.check_for_cancellation_on_suspend(promise_)) { promise_.state_.on_suspend_->arg_ = this; promise_.state_.on_suspend_->fn_ = [](void* p) { #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) BOOST_ASIO_HANDLER_LOCATION(( static_cast<awaitable*>(p)->location_.file_name(), static_cast<awaitable*>(p)->location_.line(), static_cast<awaitable*>(p)->location_.function_name())); # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) std::forward<Op>(static_cast<awaitable*>(p)->op_)( co_composed_handler<Executors, Handler, Return, completion_signature_of_t<Op>>( static_cast<awaitable*>(p)->promise_)); }; } } auto await_resume() { return co_composed_handler<Executors, Handler, Return, completion_signature_of_t<Op>>::on_resume(promise_.result_); } private: Op&& op_; co_composed_promise& promise_; #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) boost::asio::detail::source_location location_; # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) }; state_.check_for_cancellation_on_transform(); return awaitable{std::forward<Op>(op), *this #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) , location # endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) }; } template <typename... Args> auto yield_value(co_composed_completion<Args...>&& result) { class [[nodiscard]] awaitable { public: awaitable(co_composed_completion<Args...>&& result, co_composed_promise& promise) : result_(std::move(result)), promise_(promise) { } constexpr bool await_ready() const noexcept { return false; } void await_suspend(coroutine_handle<co_composed_promise>) { promise_.state_.work_.reset(); promise_.state_.on_suspend_->arg_ = this; promise_.state_.on_suspend_->fn_ = [](void* p) { awaitable& a = *static_cast<awaitable*>(p); co_composed_handler_base<Executors, Handler, Return> composed_handler(a.promise_); Handler handler(std::move(a.promise_.state_.handler_)); std::tuple<decay_t<Args>...> result( std::move(static_cast<std::tuple<Args&&...>>(a.result_))); co_composed_handler_base<Executors, Handler, Return>(std::move(composed_handler)); std::apply(std::move(handler), std::move(result)); }; } void await_resume() noexcept { } private: co_composed_completion<Args...> result_; co_composed_promise& promise_; }; return awaitable{std::move(result), *this}; } private: using allocator_type = associated_allocator_t<Handler, recycling_allocator<void>>; union block { std::max_align_t max_align; alignas(allocator_type) char pad[alignof(allocator_type)]; }; using block_allocator_type = typename std::allocator_traits<allocator_type> ::template rebind_alloc<block>; static constexpr std::size_t blocks(std::size_t size) { return (size + sizeof(block) - 1) / sizeof(block); } co_composed_state<Executors, Handler, Return>& state_; co_composed_promise** owner_ = nullptr; void* result_ = nullptr; }; template <typename Implementation, typename Executors, typename... Signatures> class initiate_co_composed { public: using executor_type = typename composed_io_executors<Executors>::head_type; template <typename I> initiate_co_composed(I&& impl, composed_io_executors<Executors>&& executors) : implementation_(std::forward<I>(impl)), executors_(std::move(executors)) { } executor_type get_executor() const noexcept { return executors_.head_; } template <typename Handler, typename... InitArgs> void operator()(Handler&& handler, InitArgs&&... init_args) const & { using handler_type = decay_t<Handler>; using returns_type = co_composed_returns<Signatures...>; co_composed_on_suspend on_suspend{}; implementation_( co_composed_state<Executors, handler_type, returns_type>( executors_, std::forward<Handler>(handler), on_suspend), std::forward<InitArgs>(init_args)...); if (on_suspend.fn_) on_suspend.fn_(on_suspend.arg_); } template <typename Handler, typename... InitArgs> void operator()(Handler&& handler, InitArgs&&... init_args) && { using handler_type = decay_t<Handler>; using returns_type = co_composed_returns<Signatures...>; co_composed_on_suspend on_suspend{}; std::move(implementation_)( co_composed_state<Executors, handler_type, returns_type>( std::move(executors_), std::forward<Handler>(handler), on_suspend), std::forward<InitArgs>(init_args)...); if (on_suspend.fn_) on_suspend.fn_(on_suspend.arg_); } private: Implementation implementation_; composed_io_executors<Executors> executors_; }; template <typename... Signatures, typename Implementation, typename Executors> inline initiate_co_composed<Implementation, Executors, Signatures...> make_initiate_co_composed(Implementation&& implementation, composed_io_executors<Executors>&& executors) { return initiate_co_composed< decay_t<Implementation>, Executors, Signatures...>( std::forward<Implementation>(implementation), std::move(executors)); } } // namespace detail template <completion_signature... Signatures, typename Implementation, typename... IoObjectsOrExecutors> inline auto co_composed(Implementation&& implementation, IoObjectsOrExecutors&&... io_objects_or_executors) { return detail::make_initiate_co_composed<Signatures...>( std::forward<Implementation>(implementation), detail::make_composed_io_executors( detail::get_composed_io_executor( std::forward<IoObjectsOrExecutors>( io_objects_or_executors))...)); } } // namespace experimental #if !defined(GENERATING_DOCUMENTATION) template <template <typename, typename> class Associator, typename Executors, typename Handler, typename Return, typename Signature, typename DefaultCandidate> struct associator<Associator, experimental::detail::co_composed_handler< Executors, Handler, Return, Signature>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const experimental::detail::co_composed_handler< Executors, Handler, Return, Signature>& h) noexcept { return Associator<Handler, DefaultCandidate>::get( h.promise().state().handler()); } static auto get( const experimental::detail::co_composed_handler< Executors, Handler, Return, Signature>& h, const DefaultCandidate& c) noexcept -> decltype( Associator<Handler, DefaultCandidate>::get( h.promise().state().handler(), c)) { return Associator<Handler, DefaultCandidate>::get( h.promise().state().handler(), c); } }; #endif // !defined(GENERATING_DOCUMENTATION) } // namespace asio } // namespace boost #if !defined(GENERATING_DOCUMENTATION) # if defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace std { # else // defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace std { namespace experimental { # endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) template <typename C, typename Executors, typename Handler, typename Return, typename... Args> struct coroutine_traits<void, C&, boost::asio::experimental::detail::co_composed_state< Executors, Handler, Return>, Args...> { using promise_type = boost::asio::experimental::detail::co_composed_promise< Executors, Handler, Return>; }; template <typename C, typename Executors, typename Handler, typename Return, typename... Args> struct coroutine_traits<void, C&&, boost::asio::experimental::detail::co_composed_state< Executors, Handler, Return>, Args...> { using promise_type = boost::asio::experimental::detail::co_composed_promise< Executors, Handler, Return>; }; template <typename Executors, typename Handler, typename Return, typename... Args> struct coroutine_traits<void, boost::asio::experimental::detail::co_composed_state< Executors, Handler, Return>, Args...> { using promise_type = boost::asio::experimental::detail::co_composed_promise< Executors, Handler, Return>; }; # if defined(BOOST_ASIO_HAS_STD_COROUTINE) } // namespace std # else // defined(BOOST_ASIO_HAS_STD_COROUTINE) }} // namespace std::experimental # endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) #endif // !defined(GENERATING_DOCUMENTATION) #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_IMPL_EXPERIMENTAL_CO_COMPOSED_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/parallel_group.hpp
// // experimental/impl/parallel_group.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_IMPL_EXPERIMENTAL_PARALLEL_GROUP_HPP #define BOOST_ASIO_IMPL_EXPERIMENTAL_PARALLEL_GROUP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <atomic> #include <deque> #include <memory> #include <new> #include <tuple> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/detail/recycling_allocator.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { // Stores the result from an individual asynchronous operation. template <typename T, typename = void> struct parallel_group_op_result { public: parallel_group_op_result() : has_value_(false) { } parallel_group_op_result(parallel_group_op_result&& other) : has_value_(other.has_value_) { if (has_value_) new (&u_.value_) T(std::move(other.get())); } ~parallel_group_op_result() { if (has_value_) u_.value_.~T(); } T& get() noexcept { return u_.value_; } template <typename... Args> void emplace(Args&&... args) { new (&u_.value_) T(std::forward<Args>(args)...); has_value_ = true; } private: union u { u() {} ~u() {} char c_; T value_; } u_; bool has_value_; }; // Proxy completion handler for the group of parallel operatations. Unpacks and // concatenates the individual operations' results, and invokes the user's // completion handler. template <typename Handler, typename... Ops> struct parallel_group_completion_handler { typedef decay_t< prefer_result_t< associated_executor_t<Handler>, execution::outstanding_work_t::tracked_t > > executor_type; parallel_group_completion_handler(Handler&& h) : handler_(std::move(h)), executor_( boost::asio::prefer( boost::asio::get_associated_executor(handler_), execution::outstanding_work.tracked)) { } executor_type get_executor() const noexcept { return executor_; } void operator()() { this->invoke(boost::asio::detail::make_index_sequence<sizeof...(Ops)>()); } template <std::size_t... I> void invoke(boost::asio::detail::index_sequence<I...>) { this->invoke(std::tuple_cat(std::move(std::get<I>(args_).get())...)); } template <typename... Args> void invoke(std::tuple<Args...>&& args) { this->invoke(std::move(args), boost::asio::detail::index_sequence_for<Args...>()); } template <typename... Args, std::size_t... I> void invoke(std::tuple<Args...>&& args, boost::asio::detail::index_sequence<I...>) { std::move(handler_)(completion_order_, std::move(std::get<I>(args))...); } Handler handler_; executor_type executor_; std::array<std::size_t, sizeof...(Ops)> completion_order_{}; std::tuple< parallel_group_op_result< typename parallel_op_signature_as_tuple< completion_signature_of_t<Ops> >::type >... > args_{}; }; // Shared state for the parallel group. template <typename Condition, typename Handler, typename... Ops> struct parallel_group_state { parallel_group_state(Condition&& c, Handler&& h) : cancellation_condition_(std::move(c)), handler_(std::move(h)) { } // The number of operations that have completed so far. Used to determine the // order of completion. std::atomic<unsigned int> completed_{0}; // The non-none cancellation type that resulted from a cancellation condition. // Stored here for use by the group's initiating function. std::atomic<cancellation_type_t> cancel_type_{cancellation_type::none}; // The number of cancellations that have been requested, either on completion // of the operations within the group, or via the cancellation slot for the // group operation. Initially set to the number of operations to prevent // cancellation signals from being emitted until after all of the group's // operations' initiating functions have completed. std::atomic<unsigned int> cancellations_requested_{sizeof...(Ops)}; // The number of operations that are yet to complete. Used to determine when // it is safe to invoke the user's completion handler. std::atomic<unsigned int> outstanding_{sizeof...(Ops)}; // The cancellation signals for each operation in the group. boost::asio::cancellation_signal cancellation_signals_[sizeof...(Ops)]; // The cancellation condition is used to determine whether the results from an // individual operation warrant a cancellation request for the whole group. Condition cancellation_condition_; // The proxy handler to be invoked once all operations in the group complete. parallel_group_completion_handler<Handler, Ops...> handler_; }; // Handler for an individual operation within the parallel group. template <std::size_t I, typename Condition, typename Handler, typename... Ops> struct parallel_group_op_handler { typedef boost::asio::cancellation_slot cancellation_slot_type; parallel_group_op_handler( std::shared_ptr<parallel_group_state<Condition, Handler, Ops...>> state) : state_(std::move(state)) { } cancellation_slot_type get_cancellation_slot() const noexcept { return state_->cancellation_signals_[I].slot(); } template <typename... Args> void operator()(Args... args) { // Capture this operation into the completion order. state_->handler_.completion_order_[state_->completed_++] = I; // Determine whether the results of this operation require cancellation of // the whole group. cancellation_type_t cancel_type = state_->cancellation_condition_(args...); // Capture the result of the operation into the proxy completion handler. std::get<I>(state_->handler_.args_).emplace(std::move(args)...); if (cancel_type != cancellation_type::none) { // Save the type for potential use by the group's initiating function. state_->cancel_type_ = cancel_type; // If we are the first operation to request cancellation, emit a signal // for each operation in the group. if (state_->cancellations_requested_++ == 0) for (std::size_t i = 0; i < sizeof...(Ops); ++i) if (i != I) state_->cancellation_signals_[i].emit(cancel_type); } // If this is the last outstanding operation, invoke the user's handler. if (--state_->outstanding_ == 0) boost::asio::dispatch(std::move(state_->handler_)); } std::shared_ptr<parallel_group_state<Condition, Handler, Ops...>> state_; }; // Handler for an individual operation within the parallel group that has an // explicitly specified executor. template <typename Executor, std::size_t I, typename Condition, typename Handler, typename... Ops> struct parallel_group_op_handler_with_executor : parallel_group_op_handler<I, Condition, Handler, Ops...> { typedef parallel_group_op_handler<I, Condition, Handler, Ops...> base_type; typedef boost::asio::cancellation_slot cancellation_slot_type; typedef Executor executor_type; parallel_group_op_handler_with_executor( std::shared_ptr<parallel_group_state<Condition, Handler, Ops...>> state, executor_type ex) : parallel_group_op_handler<I, Condition, Handler, Ops...>(std::move(state)) { cancel_proxy_ = &this->state_->cancellation_signals_[I].slot().template emplace<cancel_proxy>(this->state_, std::move(ex)); } cancellation_slot_type get_cancellation_slot() const noexcept { return cancel_proxy_->signal_.slot(); } executor_type get_executor() const noexcept { return cancel_proxy_->executor_; } // Proxy handler that forwards the emitted signal to the correct executor. struct cancel_proxy { cancel_proxy( std::shared_ptr<parallel_group_state< Condition, Handler, Ops...>> state, executor_type ex) : state_(std::move(state)), executor_(std::move(ex)) { } void operator()(cancellation_type_t type) { if (auto state = state_.lock()) { boost::asio::cancellation_signal* sig = &signal_; boost::asio::dispatch(executor_, [state, sig, type]{ sig->emit(type); }); } } std::weak_ptr<parallel_group_state<Condition, Handler, Ops...>> state_; boost::asio::cancellation_signal signal_; executor_type executor_; }; cancel_proxy* cancel_proxy_; }; // Helper to launch an operation using the correct executor, if any. template <std::size_t I, typename Op, typename = void> struct parallel_group_op_launcher { template <typename Condition, typename Handler, typename... Ops> static void launch(Op& op, const std::shared_ptr<parallel_group_state< Condition, Handler, Ops...>>& state) { typedef associated_executor_t<Op> ex_type; ex_type ex = boost::asio::get_associated_executor(op); std::move(op)( parallel_group_op_handler_with_executor<ex_type, I, Condition, Handler, Ops...>(state, std::move(ex))); } }; // Specialised launcher for operations that specify no executor. template <std::size_t I, typename Op> struct parallel_group_op_launcher<I, Op, enable_if_t< is_same< typename associated_executor< Op>::asio_associated_executor_is_unspecialised, void >::value >> { template <typename Condition, typename Handler, typename... Ops> static void launch(Op& op, const std::shared_ptr<parallel_group_state< Condition, Handler, Ops...>>& state) { std::move(op)( parallel_group_op_handler<I, Condition, Handler, Ops...>(state)); } }; template <typename Condition, typename Handler, typename... Ops> struct parallel_group_cancellation_handler { parallel_group_cancellation_handler( std::shared_ptr<parallel_group_state<Condition, Handler, Ops...>> state) : state_(std::move(state)) { } void operator()(cancellation_type_t cancel_type) { // If we are the first place to request cancellation, i.e. no operation has // yet completed and requested cancellation, emit a signal for each // operation in the group. if (cancel_type != cancellation_type::none) if (auto state = state_.lock()) if (state->cancellations_requested_++ == 0) for (std::size_t i = 0; i < sizeof...(Ops); ++i) state->cancellation_signals_[i].emit(cancel_type); } std::weak_ptr<parallel_group_state<Condition, Handler, Ops...>> state_; }; template <typename Condition, typename Handler, typename... Ops, std::size_t... I> void parallel_group_launch(Condition cancellation_condition, Handler handler, std::tuple<Ops...>& ops, boost::asio::detail::index_sequence<I...>) { // Get the user's completion handler's cancellation slot, so that we can allow // cancellation of the entire group. associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Create the shared state for the operation. typedef parallel_group_state<Condition, Handler, Ops...> state_type; std::shared_ptr<state_type> state = std::allocate_shared<state_type>( boost::asio::detail::recycling_allocator<state_type, boost::asio::detail::thread_info_base::parallel_group_tag>(), std::move(cancellation_condition), std::move(handler)); // Initiate each individual operation in the group. int fold[] = { 0, ( parallel_group_op_launcher<I, Ops>::launch(std::get<I>(ops), state), 0 )... }; (void)fold; // Check if any of the operations has already requested cancellation, and if // so, emit a signal for each operation in the group. if ((state->cancellations_requested_ -= sizeof...(Ops)) > 0) for (auto& signal : state->cancellation_signals_) signal.emit(state->cancel_type_); // Register a handler with the user's completion handler's cancellation slot. if (slot.is_connected()) slot.template emplace< parallel_group_cancellation_handler< Condition, Handler, Ops...>>(state); } // Proxy completion handler for the ranged group of parallel operatations. // Unpacks and recombines the individual operations' results, and invokes the // user's completion handler. template <typename Handler, typename Op, typename Allocator> struct ranged_parallel_group_completion_handler { typedef decay_t< prefer_result_t< associated_executor_t<Handler>, execution::outstanding_work_t::tracked_t > > executor_type; typedef typename parallel_op_signature_as_tuple< completion_signature_of_t<Op> >::type op_tuple_type; typedef parallel_group_op_result<op_tuple_type> op_result_type; ranged_parallel_group_completion_handler(Handler&& h, std::size_t size, const Allocator& allocator) : handler_(std::move(h)), executor_( boost::asio::prefer( boost::asio::get_associated_executor(handler_), execution::outstanding_work.tracked)), allocator_(allocator), completion_order_(size, 0, BOOST_ASIO_REBIND_ALLOC(Allocator, std::size_t)(allocator)), args_(BOOST_ASIO_REBIND_ALLOC(Allocator, op_result_type)(allocator)) { for (std::size_t i = 0; i < size; ++i) args_.emplace_back(); } executor_type get_executor() const noexcept { return executor_; } void operator()() { this->invoke( boost::asio::detail::make_index_sequence< std::tuple_size<op_tuple_type>::value>()); } template <std::size_t... I> void invoke(boost::asio::detail::index_sequence<I...>) { typedef typename parallel_op_signature_as_tuple< typename ranged_parallel_group_signature< completion_signature_of_t<Op>, Allocator >::raw_type >::type vectors_type; // Construct all result vectors using the supplied allocator. vectors_type vectors{ typename std::tuple_element<I, vectors_type>::type( BOOST_ASIO_REBIND_ALLOC(Allocator, int)(allocator_))...}; // Reserve sufficient space in each of the result vectors. int reserve_fold[] = { 0, ( std::get<I>(vectors).reserve(completion_order_.size()), 0 )... }; (void)reserve_fold; // Copy the results from all operations into the result vectors. for (std::size_t idx = 0; idx < completion_order_.size(); ++idx) { int pushback_fold[] = { 0, ( std::get<I>(vectors).push_back( std::move(std::get<I>(args_[idx].get()))), 0 )... }; (void)pushback_fold; } std::move(handler_)(std::move(completion_order_), std::move(std::get<I>(vectors))...); } Handler handler_; executor_type executor_; Allocator allocator_; std::vector<std::size_t, BOOST_ASIO_REBIND_ALLOC(Allocator, std::size_t)> completion_order_; std::deque<op_result_type, BOOST_ASIO_REBIND_ALLOC(Allocator, op_result_type)> args_; }; // Shared state for the parallel group. template <typename Condition, typename Handler, typename Op, typename Allocator> struct ranged_parallel_group_state { ranged_parallel_group_state(Condition&& c, Handler&& h, std::size_t size, const Allocator& allocator) : cancellations_requested_(size), outstanding_(size), cancellation_signals_( BOOST_ASIO_REBIND_ALLOC(Allocator, boost::asio::cancellation_signal)(allocator)), cancellation_condition_(std::move(c)), handler_(std::move(h), size, allocator) { for (std::size_t i = 0; i < size; ++i) cancellation_signals_.emplace_back(); } // The number of operations that have completed so far. Used to determine the // order of completion. std::atomic<unsigned int> completed_{0}; // The non-none cancellation type that resulted from a cancellation condition. // Stored here for use by the group's initiating function. std::atomic<cancellation_type_t> cancel_type_{cancellation_type::none}; // The number of cancellations that have been requested, either on completion // of the operations within the group, or via the cancellation slot for the // group operation. Initially set to the number of operations to prevent // cancellation signals from being emitted until after all of the group's // operations' initiating functions have completed. std::atomic<unsigned int> cancellations_requested_; // The number of operations that are yet to complete. Used to determine when // it is safe to invoke the user's completion handler. std::atomic<unsigned int> outstanding_; // The cancellation signals for each operation in the group. std::deque<boost::asio::cancellation_signal, BOOST_ASIO_REBIND_ALLOC(Allocator, boost::asio::cancellation_signal)> cancellation_signals_; // The cancellation condition is used to determine whether the results from an // individual operation warrant a cancellation request for the whole group. Condition cancellation_condition_; // The proxy handler to be invoked once all operations in the group complete. ranged_parallel_group_completion_handler<Handler, Op, Allocator> handler_; }; // Handler for an individual operation within the parallel group. template <typename Condition, typename Handler, typename Op, typename Allocator> struct ranged_parallel_group_op_handler { typedef boost::asio::cancellation_slot cancellation_slot_type; ranged_parallel_group_op_handler( std::shared_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state, std::size_t idx) : state_(std::move(state)), idx_(idx) { } cancellation_slot_type get_cancellation_slot() const noexcept { return state_->cancellation_signals_[idx_].slot(); } template <typename... Args> void operator()(Args... args) { // Capture this operation into the completion order. state_->handler_.completion_order_[state_->completed_++] = idx_; // Determine whether the results of this operation require cancellation of // the whole group. cancellation_type_t cancel_type = state_->cancellation_condition_(args...); // Capture the result of the operation into the proxy completion handler. state_->handler_.args_[idx_].emplace(std::move(args)...); if (cancel_type != cancellation_type::none) { // Save the type for potential use by the group's initiating function. state_->cancel_type_ = cancel_type; // If we are the first operation to request cancellation, emit a signal // for each operation in the group. if (state_->cancellations_requested_++ == 0) for (std::size_t i = 0; i < state_->cancellation_signals_.size(); ++i) if (i != idx_) state_->cancellation_signals_[i].emit(cancel_type); } // If this is the last outstanding operation, invoke the user's handler. if (--state_->outstanding_ == 0) boost::asio::dispatch(std::move(state_->handler_)); } std::shared_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state_; std::size_t idx_; }; // Handler for an individual operation within the parallel group that has an // explicitly specified executor. template <typename Executor, typename Condition, typename Handler, typename Op, typename Allocator> struct ranged_parallel_group_op_handler_with_executor : ranged_parallel_group_op_handler<Condition, Handler, Op, Allocator> { typedef ranged_parallel_group_op_handler< Condition, Handler, Op, Allocator> base_type; typedef boost::asio::cancellation_slot cancellation_slot_type; typedef Executor executor_type; ranged_parallel_group_op_handler_with_executor( std::shared_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state, executor_type ex, std::size_t idx) : ranged_parallel_group_op_handler<Condition, Handler, Op, Allocator>( std::move(state), idx) { cancel_proxy_ = &this->state_->cancellation_signals_[idx].slot().template emplace<cancel_proxy>(this->state_, std::move(ex)); } cancellation_slot_type get_cancellation_slot() const noexcept { return cancel_proxy_->signal_.slot(); } executor_type get_executor() const noexcept { return cancel_proxy_->executor_; } // Proxy handler that forwards the emitted signal to the correct executor. struct cancel_proxy { cancel_proxy( std::shared_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state, executor_type ex) : state_(std::move(state)), executor_(std::move(ex)) { } void operator()(cancellation_type_t type) { if (auto state = state_.lock()) { boost::asio::cancellation_signal* sig = &signal_; boost::asio::dispatch(executor_, [state, sig, type]{ sig->emit(type); }); } } std::weak_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state_; boost::asio::cancellation_signal signal_; executor_type executor_; }; cancel_proxy* cancel_proxy_; }; template <typename Condition, typename Handler, typename Op, typename Allocator> struct ranged_parallel_group_cancellation_handler { ranged_parallel_group_cancellation_handler( std::shared_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state) : state_(std::move(state)) { } void operator()(cancellation_type_t cancel_type) { // If we are the first place to request cancellation, i.e. no operation has // yet completed and requested cancellation, emit a signal for each // operation in the group. if (cancel_type != cancellation_type::none) if (auto state = state_.lock()) if (state->cancellations_requested_++ == 0) for (std::size_t i = 0; i < state->cancellation_signals_.size(); ++i) state->cancellation_signals_[i].emit(cancel_type); } std::weak_ptr<ranged_parallel_group_state< Condition, Handler, Op, Allocator>> state_; }; template <typename Condition, typename Handler, typename Range, typename Allocator> void ranged_parallel_group_launch(Condition cancellation_condition, Handler handler, Range&& range, const Allocator& allocator) { // Get the user's completion handler's cancellation slot, so that we can allow // cancellation of the entire group. associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // The type of the asynchronous operation. typedef decay_t<decltype(*declval<typename Range::iterator>())> op_type; // Create the shared state for the operation. typedef ranged_parallel_group_state<Condition, Handler, op_type, Allocator> state_type; std::shared_ptr<state_type> state = std::allocate_shared<state_type>( boost::asio::detail::recycling_allocator<state_type, boost::asio::detail::thread_info_base::parallel_group_tag>(), std::move(cancellation_condition), std::move(handler), range.size(), allocator); std::size_t idx = 0; for (auto&& op : std::forward<Range>(range)) { typedef associated_executor_t<op_type> ex_type; ex_type ex = boost::asio::get_associated_executor(op); std::move(op)( ranged_parallel_group_op_handler_with_executor< ex_type, Condition, Handler, op_type, Allocator>( state, std::move(ex), idx++)); } // Check if any of the operations has already requested cancellation, and if // so, emit a signal for each operation in the group. if ((state->cancellations_requested_ -= range.size()) > 0) for (auto& signal : state->cancellation_signals_) signal.emit(state->cancel_type_); // Register a handler with the user's completion handler's cancellation slot. if (slot.is_connected()) slot.template emplace< ranged_parallel_group_cancellation_handler< Condition, Handler, op_type, Allocator>>(state); } } // namespace detail } // namespace experimental template <template <typename, typename> class Associator, typename Handler, typename... Ops, typename DefaultCandidate> struct associator<Associator, experimental::detail::parallel_group_completion_handler<Handler, Ops...>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const experimental::detail::parallel_group_completion_handler< Handler, Ops...>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get( const experimental::detail::parallel_group_completion_handler< Handler, Ops...>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Op, typename Allocator, typename DefaultCandidate> struct associator<Associator, experimental::detail::ranged_parallel_group_completion_handler< Handler, Op, Allocator>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const experimental::detail::ranged_parallel_group_completion_handler< Handler, Op, Allocator>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get( const experimental::detail::ranged_parallel_group_completion_handler< Handler, Op, Allocator>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_IMPL_EXPERIMENTAL_PARALLEL_GROUP_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/use_coro.hpp
// // experimental/impl/use_coro.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_IMPL_USE_CORO_HPP #define BOOST_ASIO_EXPERIMENTAL_IMPL_USE_CORO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/deferred.hpp> #include <boost/asio/experimental/coro.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { #if !defined(GENERATING_DOCUMENTATION) template <typename Allocator, typename R> struct async_result<experimental::use_coro_t<Allocator>, R()> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void() noexcept, void, boost::asio::associated_executor_t<Initiation>, Allocator> { co_await deferred_async_operation<R(), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl(boost::asio::detail::initiation_archetype<R()>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), void, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; template <typename Allocator, typename R> struct async_result< experimental::use_coro_t<Allocator>, R(boost::system::error_code)> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void() noexcept, void, boost::asio::associated_executor_t<Initiation>, Allocator> { co_await deferred_async_operation< R(boost::system::error_code), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl( boost::asio::detail::initiation_archetype<R(boost::system::error_code)>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), void, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; template <typename Allocator, typename R> struct async_result< experimental::use_coro_t<Allocator>, R(std::exception_ptr)> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), void, boost::asio::associated_executor_t<Initiation>, Allocator> { co_await deferred_async_operation< R(std::exception_ptr), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl( boost::asio::detail::initiation_archetype<R(std::exception_ptr)>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), void, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; template <typename Allocator, typename R, typename T> struct async_result<experimental::use_coro_t<Allocator>, R(T)> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void() noexcept, T, boost::asio::associated_executor_t<Initiation>, Allocator> { co_return co_await deferred_async_operation<R(T), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl(boost::asio::detail::initiation_archetype<R(T)>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void() noexcept, T, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; template <typename Allocator, typename R, typename T> struct async_result< experimental::use_coro_t<Allocator>, R(boost::system::error_code, T)> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), T, boost::asio::associated_executor_t<Initiation>, Allocator> { co_return co_await deferred_async_operation< R(boost::system::error_code, T), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl( boost::asio::detail::initiation_archetype< R(boost::system::error_code, T)>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), T, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; template <typename Allocator, typename R, typename T> struct async_result< experimental::use_coro_t<Allocator>, R(std::exception_ptr, T)> { template <typename Initiation, typename... InitArgs> static auto initiate_impl(Initiation initiation, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), T, boost::asio::associated_executor_t<Initiation>, Allocator> { co_return co_await deferred_async_operation< R(std::exception_ptr, T), Initiation, InitArgs...>( deferred_init_tag{}, std::move(initiation), std::move(args)...); } template <typename... InitArgs> static auto initiate_impl( boost::asio::detail::initiation_archetype<R(std::exception_ptr, T)>, std::allocator_arg_t, Allocator, InitArgs... args) -> experimental::coro<void(), T, boost::asio::any_io_executor, Allocator>; template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_coro_t<Allocator> tk, InitArgs&&... args) { return initiate_impl(std::move(initiation), std::allocator_arg, tk.get_allocator(), std::forward<InitArgs>(args)...); } }; #endif // !defined(GENERATING_DOCUMENTATION) } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_USE_CORO_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/as_single.hpp
// // experimental/impl/as_single.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP #define BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <tuple> #include <boost/asio/associator.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/handler_cont_helpers.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { // Class to adapt a as_single_t as a completion handler. template <typename Handler> class as_single_handler { public: typedef void result_type; template <typename CompletionToken> as_single_handler(as_single_t<CompletionToken> e) : handler_(static_cast<CompletionToken&&>(e.token_)) { } template <typename RedirectedHandler> as_single_handler(RedirectedHandler&& h) : handler_(static_cast<RedirectedHandler&&>(h)) { } void operator()() { static_cast<Handler&&>(handler_)(); } template <typename Arg> void operator()(Arg&& arg) { static_cast<Handler&&>(handler_)(static_cast<Arg&&>(arg)); } template <typename... Args> void operator()(Args&&... args) { static_cast<Handler&&>(handler_)( std::make_tuple(static_cast<Args&&>(args)...)); } //private: Handler handler_; }; template <typename Handler> inline bool asio_handler_is_continuation( as_single_handler<Handler>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Signature> struct as_single_signature { typedef Signature type; }; template <typename R> struct as_single_signature<R()> { typedef R type(); }; template <typename R, typename Arg> struct as_single_signature<R(Arg)> { typedef R type(Arg); }; template <typename R, typename... Args> struct as_single_signature<R(Args...)> { typedef R type(std::tuple<decay_t<Args>...>); }; } // namespace detail } // namespace experimental #if !defined(GENERATING_DOCUMENTATION) template <typename CompletionToken, typename Signature> struct async_result<experimental::as_single_t<CompletionToken>, Signature> { template <typename Initiation> struct init_wrapper { init_wrapper(Initiation init) : initiation_(static_cast<Initiation&&>(init)) { } template <typename Handler, typename... Args> void operator()(Handler&& handler, Args&&... args) { static_cast<Initiation&&>(initiation_)( experimental::detail::as_single_handler<decay_t<Handler>>( static_cast<Handler&&>(handler)), static_cast<Args&&>(args)...); } Initiation initiation_; }; template <typename Initiation, typename RawCompletionToken, typename... Args> static auto initiate(Initiation&& initiation, RawCompletionToken&& token, Args&&... args) -> decltype( async_initiate<CompletionToken, typename experimental::detail::as_single_signature<Signature>::type>( init_wrapper<decay_t<Initiation>>( static_cast<Initiation&&>(initiation)), token.token_, static_cast<Args&&>(args)...)) { return async_initiate<CompletionToken, typename experimental::detail::as_single_signature<Signature>::type>( init_wrapper<decay_t<Initiation>>( static_cast<Initiation&&>(initiation)), token.token_, static_cast<Args&&>(args)...); } }; template <template <typename, typename> class Associator, typename Handler, typename DefaultCandidate> struct associator<Associator, experimental::detail::as_single_handler<Handler>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const experimental::detail::as_single_handler<Handler>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const experimental::detail::as_single_handler<Handler>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; #endif // !defined(GENERATING_DOCUMENTATION) } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/coro.hpp
// // experimental/impl/coro.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_IMPL_CORO_HPP #define BOOST_ASIO_EXPERIMENTAL_IMPL_CORO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/append.hpp> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/bind_allocator.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/experimental/detail/coro_completion_handler.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { template <typename Yield, typename Return, typename Executor, typename Allocator> struct coro; namespace detail { struct coro_cancellation_source { cancellation_slot slot; cancellation_state state; bool throw_if_cancelled_ = true; void reset_cancellation_state() { state = cancellation_state(slot); } template <typename Filter> void reset_cancellation_state(Filter&& filter) { state = cancellation_state(slot, static_cast<Filter&&>(filter)); } template <typename InFilter, typename OutFilter> void reset_cancellation_state(InFilter&& in_filter, OutFilter&& out_filter) { state = cancellation_state(slot, static_cast<InFilter&&>(in_filter), static_cast<OutFilter&&>(out_filter)); } bool throw_if_cancelled() const { return throw_if_cancelled_; } void throw_if_cancelled(bool value) { throw_if_cancelled_ = value; } }; template <typename Signature, typename Return, typename Executor, typename Allocator> struct coro_promise; template <typename T> struct is_noexcept : std::false_type { }; template <typename Return, typename... Args> struct is_noexcept<Return(Args...)> : std::false_type { }; template <typename Return, typename... Args> struct is_noexcept<Return(Args...) noexcept> : std::true_type { }; template <typename T> constexpr bool is_noexcept_v = is_noexcept<T>::value; template <typename T> struct coro_error; template <> struct coro_error<boost::system::error_code> { static boost::system::error_code invalid() { return boost::asio::error::fault; } static boost::system::error_code cancelled() { return boost::asio::error::operation_aborted; } static boost::system::error_code interrupted() { return boost::asio::error::interrupted; } static boost::system::error_code done() { return boost::asio::error::broken_pipe; } }; template <> struct coro_error<std::exception_ptr> { static std::exception_ptr invalid() { return std::make_exception_ptr( boost::system::system_error( coro_error<boost::system::error_code>::invalid())); } static std::exception_ptr cancelled() { return std::make_exception_ptr( boost::system::system_error( coro_error<boost::system::error_code>::cancelled())); } static std::exception_ptr interrupted() { return std::make_exception_ptr( boost::system::system_error( coro_error<boost::system::error_code>::interrupted())); } static std::exception_ptr done() { return std::make_exception_ptr( boost::system::system_error( coro_error<boost::system::error_code>::done())); } }; template <typename T, typename Coroutine > struct coro_with_arg { using coro_t = Coroutine; T value; coro_t& coro; struct awaitable_t { T value; coro_t& coro; constexpr static bool await_ready() { return false; } template <typename Y, typename R, typename E, typename A> auto await_suspend(coroutine_handle<coro_promise<Y, R, E, A>> h) -> coroutine_handle<> { auto& hp = h.promise(); if constexpr (!coro_promise<Y, R, E, A>::is_noexcept) { if ((hp.cancel->state.cancelled() != cancellation_type::none) && hp.cancel->throw_if_cancelled_) { boost::asio::detail::throw_error( boost::asio::error::operation_aborted, "coro-cancelled"); } } if (hp.get_executor() == coro.get_executor()) { coro.coro_->awaited_from = h; coro.coro_->reset_error(); coro.coro_->input_ = std::move(value); coro.coro_->cancel = hp.cancel; return coro.coro_->get_handle(); } else { coro.coro_->awaited_from = dispatch_coroutine( boost::asio::prefer(hp.get_executor(), execution::outstanding_work.tracked), [h]() mutable { h.resume(); }).handle; coro.coro_->reset_error(); coro.coro_->input_ = std::move(value); struct cancel_handler { using src = std::pair<cancellation_signal, detail::coro_cancellation_source>; std::shared_ptr<src> st = std::make_shared<src>(); cancel_handler(E e, coro_t& coro) : e(e), coro_(coro.coro_) { st->second.state = cancellation_state(st->second.slot = st->first.slot()); } E e; typename coro_t::promise_type* coro_; void operator()(cancellation_type ct) { boost::asio::dispatch(e, [ct, st = st]() mutable { auto & [sig, state] = *st; sig.emit(ct); }); } }; if (hp.cancel->state.slot().is_connected()) { hp.cancel->state.slot().template emplace<cancel_handler>( coro.get_executor(), coro); } auto hh = detail::coroutine_handle< typename coro_t::promise_type>::from_promise(*coro.coro_); return dispatch_coroutine( coro.coro_->get_executor(), [hh]() mutable { hh.resume(); }).handle; } } auto await_resume() -> typename coro_t::result_type { coro.coro_->cancel = nullptr; coro.coro_->rethrow_if(); return std::move(coro.coro_->result_); } }; template <typename CompletionToken> auto async_resume(CompletionToken&& token) && { return coro.async_resume(std::move(value), std::forward<CompletionToken>(token)); } auto operator co_await() && { return awaitable_t{std::move(value), coro}; } }; template <bool IsNoexcept> struct coro_promise_error; template <> struct coro_promise_error<false> { std::exception_ptr error_; void reset_error() { error_ = std::exception_ptr{}; } void unhandled_exception() { error_ = std::current_exception(); } void rethrow_if() { if (error_) std::rethrow_exception(error_); } }; #if defined(__GNUC__) # pragma GCC diagnostic push # if defined(__clang__) # pragma GCC diagnostic ignored "-Wexceptions" # else # pragma GCC diagnostic ignored "-Wterminate" # endif #elif defined(_MSC_VER) # pragma warning(push) # pragma warning (disable:4297) #endif template <> struct coro_promise_error<true> { void reset_error() { } void unhandled_exception() noexcept { throw; } void rethrow_if() { } }; #if defined(__GNUC__) # pragma GCC diagnostic pop #elif defined(_MSC_VER) # pragma warning(pop) #endif template <typename T = void> struct yield_input { T& value; coroutine_handle<> awaited_from{noop_coroutine()}; bool await_ready() const noexcept { return false; } template <typename U> coroutine_handle<> await_suspend(coroutine_handle<U>) noexcept { return std::exchange(awaited_from, noop_coroutine()); } T await_resume() const noexcept { return std::move(value); } }; template <> struct yield_input<void> { coroutine_handle<> awaited_from{noop_coroutine()}; bool await_ready() const noexcept { return false; } auto await_suspend(coroutine_handle<>) noexcept { return std::exchange(awaited_from, noop_coroutine()); } constexpr void await_resume() const noexcept { } }; struct coro_awaited_from { coroutine_handle<> awaited_from{noop_coroutine()}; auto final_suspend() noexcept { struct suspendor { coroutine_handle<> awaited_from; constexpr static bool await_ready() noexcept { return false; } auto await_suspend(coroutine_handle<>) noexcept { return std::exchange(awaited_from, noop_coroutine()); } constexpr static void await_resume() noexcept { } }; return suspendor{std::exchange(awaited_from, noop_coroutine())}; } ~coro_awaited_from() { awaited_from.resume(); }//must be on the right executor }; template <typename Yield, typename Input, typename Return> struct coro_promise_exchange : coro_awaited_from { using result_type = coro_result_t<Yield, Return>; result_type result_; Input input_; auto yield_value(Yield&& y) { result_ = std::move(y); return yield_input<Input>{std::move(input_), std::exchange(awaited_from, noop_coroutine())}; } auto yield_value(const Yield& y) { result_ = y; return yield_input<Input>{std::move(input_), std::exchange(awaited_from, noop_coroutine())}; } void return_value(const Return& r) { result_ = r; } void return_value(Return&& r) { result_ = std::move(r); } }; template <typename YieldReturn> struct coro_promise_exchange<YieldReturn, void, YieldReturn> : coro_awaited_from { using result_type = coro_result_t<YieldReturn, YieldReturn>; result_type result_; auto yield_value(const YieldReturn& y) { result_ = y; return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } auto yield_value(YieldReturn&& y) { result_ = std::move(y); return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } void return_value(const YieldReturn& r) { result_ = r; } void return_value(YieldReturn&& r) { result_ = std::move(r); } }; template <typename Yield, typename Return> struct coro_promise_exchange<Yield, void, Return> : coro_awaited_from { using result_type = coro_result_t<Yield, Return>; result_type result_; auto yield_value(const Yield& y) { result_.template emplace<0>(y); return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } auto yield_value(Yield&& y) { result_.template emplace<0>(std::move(y)); return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } void return_value(const Return& r) { result_.template emplace<1>(r); } void return_value(Return&& r) { result_.template emplace<1>(std::move(r)); } }; template <typename Yield, typename Input> struct coro_promise_exchange<Yield, Input, void> : coro_awaited_from { using result_type = coro_result_t<Yield, void>; result_type result_; Input input_; auto yield_value(Yield&& y) { result_ = std::move(y); return yield_input<Input>{input_, std::exchange(awaited_from, noop_coroutine())}; } auto yield_value(const Yield& y) { result_ = y; return yield_input<Input>{input_, std::exchange(awaited_from, noop_coroutine())}; } void return_void() { result_.reset(); } }; template <typename Return> struct coro_promise_exchange<void, void, Return> : coro_awaited_from { using result_type = coro_result_t<void, Return>; result_type result_; void yield_value(); void return_value(const Return& r) { result_ = r; } void return_value(Return&& r) { result_ = std::move(r); } }; template <> struct coro_promise_exchange<void, void, void> : coro_awaited_from { void return_void() {} void yield_value(); }; template <typename Yield> struct coro_promise_exchange<Yield, void, void> : coro_awaited_from { using result_type = coro_result_t<Yield, void>; result_type result_; auto yield_value(const Yield& y) { result_ = y; return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } auto yield_value(Yield&& y) { result_ = std::move(y); return yield_input<void>{std::exchange(awaited_from, noop_coroutine())}; } void return_void() { result_.reset(); } }; template <typename Yield, typename Return, typename Executor, typename Allocator> struct coro_promise final : coro_promise_allocator<Allocator>, coro_promise_error<coro_traits<Yield, Return, Executor>::is_noexcept>, coro_promise_exchange< typename coro_traits<Yield, Return, Executor>::yield_type, typename coro_traits<Yield, Return, Executor>::input_type, typename coro_traits<Yield, Return, Executor>::return_type> { using coro_type = coro<Yield, Return, Executor, Allocator>; auto handle() { return coroutine_handle<coro_promise>::from_promise(this); } using executor_type = Executor; executor_type executor_; std::optional<coro_cancellation_source> cancel_source; coro_cancellation_source * cancel; using cancellation_slot_type = boost::asio::cancellation_slot; cancellation_slot_type get_cancellation_slot() const noexcept { return cancel ? cancel->slot : cancellation_slot_type{}; } using allocator_type = typename std::allocator_traits<associated_allocator_t<Executor>>:: template rebind_alloc<std::byte>; using traits = coro_traits<Yield, Return, Executor>; using input_type = typename traits::input_type; using yield_type = typename traits::yield_type; using return_type = typename traits::return_type; using error_type = typename traits::error_type; using result_type = typename traits::result_type; constexpr static bool is_noexcept = traits::is_noexcept; auto get_executor() const -> Executor { return executor_; } auto get_handle() { return coroutine_handle<coro_promise>::from_promise(*this); } template <typename... Args> coro_promise(Executor executor, Args&&... args) noexcept : coro_promise_allocator<Allocator>( executor, std::forward<Args>(args)...), executor_(std::move(executor)) { } template <typename First, typename... Args> coro_promise(First&& f, Executor executor, Args&&... args) noexcept : coro_promise_allocator<Allocator>( f, executor, std::forward<Args>(args)...), executor_(std::move(executor)) { } template <typename First, detail::execution_context Context, typename... Args> coro_promise(First&& f, Context&& ctx, Args&&... args) noexcept : coro_promise_allocator<Allocator>( f, ctx, std::forward<Args>(args)...), executor_(ctx.get_executor()) { } template <detail::execution_context Context, typename... Args> coro_promise(Context&& ctx, Args&&... args) noexcept : coro_promise_allocator<Allocator>( ctx, std::forward<Args>(args)...), executor_(ctx.get_executor()) { } auto get_return_object() { return coro<Yield, Return, Executor, Allocator>{this}; } auto initial_suspend() noexcept { return suspend_always{}; } using coro_promise_exchange< typename coro_traits<Yield, Return, Executor>::yield_type, typename coro_traits<Yield, Return, Executor>::input_type, typename coro_traits<Yield, Return, Executor>::return_type>::yield_value; auto await_transform(this_coro::executor_t) const { struct exec_helper { const executor_type& value; constexpr static bool await_ready() noexcept { return true; } constexpr static void await_suspend(coroutine_handle<>) noexcept { } executor_type await_resume() const noexcept { return value; } }; return exec_helper{executor_}; } auto await_transform(this_coro::cancellation_state_t) const { struct exec_helper { const boost::asio::cancellation_state& value; constexpr static bool await_ready() noexcept { return true; } constexpr static void await_suspend(coroutine_handle<>) noexcept { } boost::asio::cancellation_state await_resume() const noexcept { return value; } }; assert(cancel); return exec_helper{cancel->state}; } // This await transformation resets the associated cancellation state. auto await_transform(this_coro::reset_cancellation_state_0_t) noexcept { struct result { detail::coro_cancellation_source * src_; bool await_ready() const noexcept { return true; } void await_suspend(coroutine_handle<void>) noexcept { } auto await_resume() const { return src_->reset_cancellation_state(); } }; return result{cancel}; } // This await transformation resets the associated cancellation state. template <typename Filter> auto await_transform( this_coro::reset_cancellation_state_1_t<Filter> reset) noexcept { struct result { detail::coro_cancellation_source* src_; Filter filter_; bool await_ready() const noexcept { return true; } void await_suspend(coroutine_handle<void>) noexcept { } auto await_resume() { return src_->reset_cancellation_state( static_cast<Filter&&>(filter_)); } }; return result{cancel, static_cast<Filter&&>(reset.filter)}; } // This await transformation resets the associated cancellation state. template <typename InFilter, typename OutFilter> auto await_transform( this_coro::reset_cancellation_state_2_t<InFilter, OutFilter> reset) noexcept { struct result { detail::coro_cancellation_source* src_; InFilter in_filter_; OutFilter out_filter_; bool await_ready() const noexcept { return true; } void await_suspend(coroutine_handle<void>) noexcept { } auto await_resume() { return src_->reset_cancellation_state( static_cast<InFilter&&>(in_filter_), static_cast<OutFilter&&>(out_filter_)); } }; return result{cancel, static_cast<InFilter&&>(reset.in_filter), static_cast<OutFilter&&>(reset.out_filter)}; } // This await transformation determines whether cancellation is propagated as // an exception. auto await_transform(this_coro::throw_if_cancelled_0_t) noexcept requires (!is_noexcept) { struct result { detail::coro_cancellation_source* src_; bool await_ready() const noexcept { return true; } void await_suspend(coroutine_handle<void>) noexcept { } auto await_resume() { return src_->throw_if_cancelled(); } }; return result{cancel}; } // This await transformation sets whether cancellation is propagated as an // exception. auto await_transform( this_coro::throw_if_cancelled_1_t throw_if_cancelled) noexcept requires (!is_noexcept) { struct result { detail::coro_cancellation_source* src_; bool value_; bool await_ready() const noexcept { return true; } void await_suspend(coroutine_handle<void>) noexcept { } auto await_resume() { src_->throw_if_cancelled(value_); } }; return result{cancel, throw_if_cancelled.value}; } template <typename Yield_, typename Return_, typename Executor_, typename Allocator_> auto await_transform(coro<Yield_, Return_, Executor_, Allocator_>& kr) -> decltype(auto) { return kr; } template <typename Yield_, typename Return_, typename Executor_, typename Allocator_> auto await_transform(coro<Yield_, Return_, Executor_, Allocator_>&& kr) { return std::move(kr); } template <typename T_, typename Coroutine > auto await_transform(coro_with_arg<T_, Coroutine>&& kr) -> decltype(auto) { return std::move(kr); } template <typename T_> requires requires(T_ t) {{ t.async_wait(deferred) }; } auto await_transform(T_& t) -> decltype(auto) { return await_transform(t.async_wait(deferred)); } template <typename Op> auto await_transform(Op&& op, constraint_t<is_async_operation<Op>::value> = 0) { if ((cancel->state.cancelled() != cancellation_type::none) && cancel->throw_if_cancelled_) { boost::asio::detail::throw_error( boost::asio::error::operation_aborted, "coro-cancelled"); } using signature = completion_signature_of_t<Op>; using result_type = detail::coro_completion_handler_type_t<signature>; using handler_type = typename detail::coro_completion_handler_type<signature>::template completion_handler<coro_promise>; struct aw_t { Op op; std::optional<result_type> result; constexpr static bool await_ready() { return false; } void await_suspend(coroutine_handle<coro_promise> h) { std::move(op)(handler_type{h, result}); } auto await_resume() { if constexpr (is_noexcept) { if constexpr (std::tuple_size_v<result_type> == 0u) return; else if constexpr (std::tuple_size_v<result_type> == 1u) return std::get<0>(std::move(result).value()); else return std::move(result).value(); } else return detail::coro_interpret_result(std::move(result).value()); } }; return aw_t{std::move(op), {}}; } }; } // namespace detail template <typename Yield, typename Return, typename Executor, typename Allocator> struct coro<Yield, Return, Executor, Allocator>::awaitable_t { coro& coro_; constexpr static bool await_ready() { return false; } template <typename Y, typename R, typename E, typename A> auto await_suspend( detail::coroutine_handle<detail::coro_promise<Y, R, E, A>> h) -> detail::coroutine_handle<> { auto& hp = h.promise(); if constexpr (!detail::coro_promise<Y, R, E, A>::is_noexcept) { if ((hp.cancel->state.cancelled() != cancellation_type::none) && hp.cancel->throw_if_cancelled_) { boost::asio::detail::throw_error( boost::asio::error::operation_aborted, "coro-cancelled"); } } if (hp.get_executor() == coro_.get_executor()) { coro_.coro_->awaited_from = h; coro_.coro_->cancel = hp.cancel; coro_.coro_->reset_error(); return coro_.coro_->get_handle(); } else { coro_.coro_->awaited_from = detail::dispatch_coroutine( boost::asio::prefer(hp.get_executor(), execution::outstanding_work.tracked), [h]() mutable { h.resume(); }).handle; coro_.coro_->reset_error(); struct cancel_handler { std::shared_ptr<std::pair<cancellation_signal, detail::coro_cancellation_source>> st = std::make_shared< std::pair<cancellation_signal, detail::coro_cancellation_source>>(); cancel_handler(E e, coro& coro) : e(e), coro_(coro.coro_) { st->second.state = cancellation_state( st->second.slot = st->first.slot()); } E e; typename coro::promise_type* coro_; void operator()(cancellation_type ct) { boost::asio::dispatch(e, [ct, st = st]() mutable { auto & [sig, state] = *st; sig.emit(ct); }); } }; if (hp.cancel->state.slot().is_connected()) { hp.cancel->state.slot().template emplace<cancel_handler>( coro_.get_executor(), coro_); } auto hh = detail::coroutine_handle< detail::coro_promise<Yield, Return, Executor, Allocator>>::from_promise( *coro_.coro_); return detail::dispatch_coroutine( coro_.coro_->get_executor(), [hh]() mutable { hh.resume(); }).handle; } } auto await_resume() -> result_type { coro_.coro_->cancel = nullptr; coro_.coro_->rethrow_if(); if constexpr (!std::is_void_v<result_type>) return std::move(coro_.coro_->result_); } }; template <typename Yield, typename Return, typename Executor, typename Allocator> struct coro<Yield, Return, Executor, Allocator>::initiate_async_resume { typedef Executor executor_type; typedef Allocator allocator_type; typedef boost::asio::cancellation_slot cancellation_slot_type; explicit initiate_async_resume(coro* self) : coro_(self->coro_) { } executor_type get_executor() const noexcept { return coro_->get_executor(); } allocator_type get_allocator() const noexcept { return coro_->get_allocator(); } template <typename E, typename WaitHandler> auto handle(E exec, WaitHandler&& handler, std::true_type /* error is noexcept */, std::true_type /* result is void */) //noexcept { return [this, the_coro = coro_, h = std::forward<WaitHandler>(handler), exec = std::move(exec)]() mutable { assert(the_coro); auto ch = detail::coroutine_handle<promise_type>::from_promise(*the_coro); assert(ch && !ch.done()); the_coro->awaited_from = post_coroutine(std::move(exec), std::move(h)); the_coro->reset_error(); ch.resume(); }; } template <typename E, typename WaitHandler> requires (!std::is_void_v<result_type>) auto handle(E exec, WaitHandler&& handler, std::true_type /* error is noexcept */, std::false_type /* result is void */) //noexcept { return [the_coro = coro_, h = std::forward<WaitHandler>(handler), exec = std::move(exec)]() mutable { assert(the_coro); auto ch = detail::coroutine_handle<promise_type>::from_promise(*the_coro); assert(ch && !ch.done()); the_coro->awaited_from = detail::post_coroutine( exec, std::move(h), the_coro->result_).handle; the_coro->reset_error(); ch.resume(); }; } template <typename E, typename WaitHandler> auto handle(E exec, WaitHandler&& handler, std::false_type /* error is noexcept */, std::true_type /* result is void */) { return [the_coro = coro_, h = std::forward<WaitHandler>(handler), exec = std::move(exec)]() mutable { if (!the_coro) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::invalid())); auto ch = detail::coroutine_handle<promise_type>::from_promise(*the_coro); if (!ch) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::invalid())); else if (ch.done()) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::done())); else { the_coro->awaited_from = detail::post_coroutine( exec, std::move(h), the_coro->error_).handle; the_coro->reset_error(); ch.resume(); } }; } template <typename E, typename WaitHandler> auto handle(E exec, WaitHandler&& handler, std::false_type /* error is noexcept */, std::false_type /* result is void */) { return [the_coro = coro_, h = std::forward<WaitHandler>(handler), exec = std::move(exec)]() mutable { if (!the_coro) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::invalid(), result_type{})); auto ch = detail::coroutine_handle<promise_type>::from_promise(*the_coro); if (!ch) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::invalid(), result_type{})); else if (ch.done()) return boost::asio::post(exec, boost::asio::append(std::move(h), detail::coro_error<error_type>::done(), result_type{})); else { the_coro->awaited_from = detail::post_coroutine( exec, std::move(h), the_coro->error_, the_coro->result_).handle; the_coro->reset_error(); ch.resume(); } }; } template <typename WaitHandler> void operator()(WaitHandler&& handler) { const auto exec = boost::asio::prefer( get_associated_executor(handler, get_executor()), execution::outstanding_work.tracked); coro_->cancel = &coro_->cancel_source.emplace(); coro_->cancel->state = cancellation_state( coro_->cancel->slot = get_associated_cancellation_slot(handler)); boost::asio::dispatch(get_executor(), handle(exec, std::forward<WaitHandler>(handler), std::integral_constant<bool, is_noexcept>{}, std::is_void<result_type>{})); } template <typename WaitHandler, typename Input> void operator()(WaitHandler&& handler, Input&& input) { const auto exec = boost::asio::prefer( get_associated_executor(handler, get_executor()), execution::outstanding_work.tracked); coro_->cancel = &coro_->cancel_source.emplace(); coro_->cancel->state = cancellation_state( coro_->cancel->slot = get_associated_cancellation_slot(handler)); boost::asio::dispatch(get_executor(), [h = handle(exec, std::forward<WaitHandler>(handler), std::integral_constant<bool, is_noexcept>{}, std::is_void<result_type>{}), in = std::forward<Input>(input), the_coro = coro_]() mutable { the_coro->input_ = std::move(in); std::move(h)(); }); } private: typename coro::promise_type* coro_; }; } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_CORO_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/impl/use_promise.hpp
// // experimental/impl/use_promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <memory> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { template <typename Allocator> struct use_promise_t; namespace detail { template<typename Signature, typename Executor, typename Allocator> struct promise_handler; } // namespace detail } // namespace experimental #if !defined(GENERATING_DOCUMENTATION) template <typename Allocator, typename R, typename... Args> struct async_result<experimental::use_promise_t<Allocator>, R(Args...)> { template <typename Initiation, typename... InitArgs> static auto initiate(Initiation initiation, experimental::use_promise_t<Allocator> up, InitArgs... args) -> experimental::promise<void(decay_t<Args>...), boost::asio::associated_executor_t<Initiation>, Allocator> { using handler_type = experimental::detail::promise_handler< void(decay_t<Args>...), boost::asio::associated_executor_t<Initiation>, Allocator>; handler_type ht{up.get_allocator(), get_associated_executor(initiation)}; std::move(initiation)(ht, std::move(args)...); return ht.make_promise(); } }; #endif // !defined(GENERATING_DOCUMENTATION) } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_USE_PROMISE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_service.hpp
// // experimental/detail/channel_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SERVICE_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/experimental/detail/channel_message.hpp> #include <boost/asio/experimental/detail/channel_receive_op.hpp> #include <boost/asio/experimental/detail/channel_send_op.hpp> #include <boost/asio/experimental/detail/has_signature.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Mutex> class channel_service : public boost::asio::detail::execution_context_service_base< channel_service<Mutex>> { public: // Possible states for a channel end. enum state { buffer = 0, waiter = 1, block = 2, closed = 3 }; // The base implementation type of all channels. struct base_implementation_type { // Default constructor. base_implementation_type() : receive_state_(block), send_state_(block), max_buffer_size_(0), next_(0), prev_(0) { } // The current state of the channel. state receive_state_ : 16; state send_state_ : 16; // The maximum number of elements that may be buffered in the channel. std::size_t max_buffer_size_; // The operations that are waiting on the channel. boost::asio::detail::op_queue<channel_operation> waiters_; // Pointers to adjacent channel implementations in linked list. base_implementation_type* next_; base_implementation_type* prev_; // The mutex type to protect the internal implementation. mutable Mutex mutex_; }; // The implementation for a specific value type. template <typename Traits, typename... Signatures> struct implementation_type; // Constructor. channel_service(execution_context& ctx); // Destroy all user-defined handler objects owned by the service. void shutdown(); // Construct a new channel implementation. void construct(base_implementation_type& impl, std::size_t max_buffer_size); // Destroy a channel implementation. template <typename Traits, typename... Signatures> void destroy(implementation_type<Traits, Signatures...>& impl); // Move-construct a new channel implementation. template <typename Traits, typename... Signatures> void move_construct(implementation_type<Traits, Signatures...>& impl, implementation_type<Traits, Signatures...>& other_impl); // Move-assign from another channel implementation. template <typename Traits, typename... Signatures> void move_assign(implementation_type<Traits, Signatures...>& impl, channel_service& other_service, implementation_type<Traits, Signatures...>& other_impl); // Get the capacity of the channel. std::size_t capacity( const base_implementation_type& impl) const noexcept; // Determine whether the channel is open. bool is_open(const base_implementation_type& impl) const noexcept; // Reset the channel to its initial state. template <typename Traits, typename... Signatures> void reset(implementation_type<Traits, Signatures...>& impl); // Close the channel. template <typename Traits, typename... Signatures> void close(implementation_type<Traits, Signatures...>& impl); // Cancel all operations associated with the channel. template <typename Traits, typename... Signatures> void cancel(implementation_type<Traits, Signatures...>& impl); // Cancel the operation associated with the channel that has the given key. template <typename Traits, typename... Signatures> void cancel_by_key(implementation_type<Traits, Signatures...>& impl, void* cancellation_key); // Determine whether a value can be read from the channel without blocking. bool ready(const base_implementation_type& impl) const noexcept; // Synchronously send a new value into the channel. template <typename Message, typename Traits, typename... Signatures, typename... Args> bool try_send(implementation_type<Traits, Signatures...>& impl, bool via_dispatch, Args&&... args); // Synchronously send a number of new values into the channel. template <typename Message, typename Traits, typename... Signatures, typename... Args> std::size_t try_send_n(implementation_type<Traits, Signatures...>& impl, std::size_t count, bool via_dispatch, Args&&... args); // Asynchronously send a new value into the channel. template <typename Traits, typename... Signatures, typename Handler, typename IoExecutor> void async_send(implementation_type<Traits, Signatures...>& impl, typename implementation_type<Traits, Signatures...>::payload_type&& payload, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef channel_send_op< typename implementation_type<Traits, Signatures...>::payload_type, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(static_cast<typename implementation_type< Traits, Signatures...>::payload_type&&>(payload), handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<op_cancellation<Traits, Signatures...>>( this, &impl); } BOOST_ASIO_HANDLER_CREATION((this->context(), *p.p, "channel", &impl, 0, "async_send")); start_send_op(impl, p.p); p.v = p.p = 0; } // Synchronously receive a value from the channel. template <typename Traits, typename... Signatures, typename Handler> bool try_receive(implementation_type<Traits, Signatures...>& impl, Handler&& handler); // Asynchronously receive a value from the channel. template <typename Traits, typename... Signatures, typename Handler, typename IoExecutor> void async_receive(implementation_type<Traits, Signatures...>& impl, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef channel_receive_op< typename implementation_type<Traits, Signatures...>::payload_type, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<op_cancellation<Traits, Signatures...>>( this, &impl); } BOOST_ASIO_HANDLER_CREATION((this->context(), *p.p, "channel", &impl, 0, "async_receive")); start_receive_op(impl, p.p); p.v = p.p = 0; } private: // Helper function object to handle a closed notification. template <typename Payload, typename Signature> struct post_receive { explicit post_receive(channel_receive<Payload>* op) : op_(op) { } template <typename... Args> void operator()(Args&&... args) { op_->post( channel_message<Signature>(0, static_cast<Args&&>(args)...)); } channel_receive<Payload>* op_; }; // Destroy a base channel implementation. void base_destroy(base_implementation_type& impl); // Helper function to start an asynchronous put operation. template <typename Traits, typename... Signatures> void start_send_op(implementation_type<Traits, Signatures...>& impl, channel_send<typename implementation_type< Traits, Signatures...>::payload_type>* send_op); // Helper function to start an asynchronous get operation. template <typename Traits, typename... Signatures> void start_receive_op(implementation_type<Traits, Signatures...>& impl, channel_receive<typename implementation_type< Traits, Signatures...>::payload_type>* receive_op); // Helper class used to implement per-operation cancellation. template <typename Traits, typename... Signatures> class op_cancellation { public: op_cancellation(channel_service* s, implementation_type<Traits, Signatures...>* impl) : service_(s), impl_(impl) { } void operator()(cancellation_type_t type) { if (!!(type & (cancellation_type::terminal | cancellation_type::partial | cancellation_type::total))) { service_->cancel_by_key(*impl_, this); } } private: channel_service* service_; implementation_type<Traits, Signatures...>* impl_; }; // Mutex to protect access to the linked list of implementations. boost::asio::detail::mutex mutex_; // The head of a linked list of all implementations. base_implementation_type* impl_list_; }; // The implementation for a specific value type. template <typename Mutex> template <typename Traits, typename... Signatures> struct channel_service<Mutex>::implementation_type : base_implementation_type { // The traits type associated with the channel. typedef typename Traits::template rebind<Signatures...>::other traits_type; // Type of an element stored in the buffer. typedef conditional_t< has_signature< typename traits_type::receive_cancelled_signature, Signatures... >::value, conditional_t< has_signature< typename traits_type::receive_closed_signature, Signatures... >::value, channel_payload<Signatures...>, channel_payload< Signatures..., typename traits_type::receive_closed_signature > >, conditional_t< has_signature< typename traits_type::receive_closed_signature, Signatures..., typename traits_type::receive_cancelled_signature >::value, channel_payload< Signatures..., typename traits_type::receive_cancelled_signature >, channel_payload< Signatures..., typename traits_type::receive_cancelled_signature, typename traits_type::receive_closed_signature > > > payload_type; // Move from another buffer. void buffer_move_from(implementation_type& other) { buffer_ = static_cast< typename traits_type::template container<payload_type>::type&&>( other.buffer_); other.buffer_clear(); } // Get number of buffered elements. std::size_t buffer_size() const { return buffer_.size(); } // Push a new value to the back of the buffer. void buffer_push(payload_type payload) { buffer_.push_back(static_cast<payload_type&&>(payload)); } // Push new values to the back of the buffer. std::size_t buffer_push_n(std::size_t count, payload_type payload) { std::size_t i = 0; for (; i < count && buffer_.size() < this->max_buffer_size_; ++i) buffer_.push_back(payload); return i; } // Get the element at the front of the buffer. payload_type buffer_front() { return static_cast<payload_type&&>(buffer_.front()); } // Pop a value from the front of the buffer. void buffer_pop() { buffer_.pop_front(); } // Clear all buffered values. void buffer_clear() { buffer_.clear(); } private: // Buffered values. typename traits_type::template container<payload_type>::type buffer_; }; // The implementation for a void value type. template <typename Mutex> template <typename Traits, typename R> struct channel_service<Mutex>::implementation_type<Traits, R()> : channel_service::base_implementation_type { // The traits type associated with the channel. typedef typename Traits::template rebind<R()>::other traits_type; // Type of an element stored in the buffer. typedef conditional_t< has_signature< typename traits_type::receive_cancelled_signature, R() >::value, conditional_t< has_signature< typename traits_type::receive_closed_signature, R() >::value, channel_payload<R()>, channel_payload< R(), typename traits_type::receive_closed_signature > >, conditional_t< has_signature< typename traits_type::receive_closed_signature, R(), typename traits_type::receive_cancelled_signature >::value, channel_payload< R(), typename traits_type::receive_cancelled_signature >, channel_payload< R(), typename traits_type::receive_cancelled_signature, typename traits_type::receive_closed_signature > > > payload_type; // Construct with empty buffer. implementation_type() : buffer_(0) { } // Move from another buffer. void buffer_move_from(implementation_type& other) { buffer_ = other.buffer_; other.buffer_ = 0; } // Get number of buffered elements. std::size_t buffer_size() const { return buffer_; } // Push a new value to the back of the buffer. void buffer_push(payload_type) { ++buffer_; } // Push new values to the back of the buffer. std::size_t buffer_push_n(std::size_t count, payload_type) { std::size_t available = this->max_buffer_size_ - buffer_; count = (count < available) ? count : available; buffer_ += count; return count; } // Get the element at the front of the buffer. payload_type buffer_front() { return payload_type(channel_message<R()>(0)); } // Pop a value from the front of the buffer. void buffer_pop() { --buffer_; } // Clear all values from the buffer. void buffer_clear() { buffer_ = 0; } private: // Number of buffered "values". std::size_t buffer_; }; // The implementation for an error_code signature. template <typename Mutex> template <typename Traits, typename R> struct channel_service<Mutex>::implementation_type< Traits, R(boost::system::error_code)> : channel_service::base_implementation_type { // The traits type associated with the channel. typedef typename Traits::template rebind<R(boost::system::error_code)>::other traits_type; // Type of an element stored in the buffer. typedef conditional_t< has_signature< typename traits_type::receive_cancelled_signature, R(boost::system::error_code) >::value, conditional_t< has_signature< typename traits_type::receive_closed_signature, R(boost::system::error_code) >::value, channel_payload<R(boost::system::error_code)>, channel_payload< R(boost::system::error_code), typename traits_type::receive_closed_signature > >, conditional_t< has_signature< typename traits_type::receive_closed_signature, R(boost::system::error_code), typename traits_type::receive_cancelled_signature >::value, channel_payload< R(boost::system::error_code), typename traits_type::receive_cancelled_signature >, channel_payload< R(boost::system::error_code), typename traits_type::receive_cancelled_signature, typename traits_type::receive_closed_signature > > > payload_type; // Construct with empty buffer. implementation_type() : size_(0) { first_.count_ = 0; } // Move from another buffer. void buffer_move_from(implementation_type& other) { size_ = other.buffer_; other.size_ = 0; first_ = other.first_; other.first.count_ = 0; rest_ = static_cast< typename traits_type::template container<buffered_value>::type&&>( other.rest_); other.buffer_clear(); } // Get number of buffered elements. std::size_t buffer_size() const { return size_; } // Push a new value to the back of the buffer. void buffer_push(payload_type payload) { buffered_value& last = rest_.empty() ? first_ : rest_.back(); if (last.count_ == 0) { value_handler handler{last.value_}; payload.receive(handler); last.count_ = 1; } else { boost::system::error_code value{last.value_}; value_handler handler{value}; payload.receive(handler); if (last.value_ == value) ++last.count_; else rest_.push_back({value, 1}); } ++size_; } // Push new values to the back of the buffer. std::size_t buffer_push_n(std::size_t count, payload_type payload) { std::size_t available = this->max_buffer_size_ - size_; count = (count < available) ? count : available; if (count > 0) { buffered_value& last = rest_.empty() ? first_ : rest_.back(); if (last.count_ == 0) { payload.receive(value_handler{last.value_}); last.count_ = count; } else { boost::system::error_code value{last.value_}; payload.receive(value_handler{value}); if (last.value_ == value) last.count_ += count; else rest_.push_back({value, count}); } size_ += count; } return count; } // Get the element at the front of the buffer. payload_type buffer_front() { return payload_type({0, first_.value_}); } // Pop a value from the front of the buffer. void buffer_pop() { --size_; if (--first_.count_ == 0 && !rest_.empty()) { first_ = rest_.front(); rest_.pop_front(); } } // Clear all values from the buffer. void buffer_clear() { size_ = 0; first_.count_ == 0; rest_.clear(); } private: struct buffered_value { boost::system::error_code value_; std::size_t count_; }; struct value_handler { boost::system::error_code& target_; template <typename... Args> void operator()(const boost::system::error_code& value, Args&&...) { target_ = value; } }; buffered_value& last_value() { return rest_.empty() ? first_ : rest_.back(); } // Total number of buffered values. std::size_t size_; // The first buffered value is maintained as a separate data member to avoid // allocating space in the container in the common case. buffered_value first_; // The rest of the buffered values. typename traits_type::template container<buffered_value>::type rest_; }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/experimental/detail/impl/channel_service.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/coro_promise_allocator.hpp
// // experimental/detail/coro_promise_allocator.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_PROMISE_ALLOCATOR_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_PROMISE_ALLOCATOR_HPP #include <boost/asio/detail/config.hpp> #include <boost/asio/experimental/coro_traits.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { /// Allocate the memory and put the allocator behind the coro memory template <typename AllocatorType> void* allocate_coroutine(const std::size_t size, AllocatorType alloc_) { using alloc_type = typename std::allocator_traits<AllocatorType>::template rebind_alloc<unsigned char>; alloc_type alloc{alloc_}; const auto align_needed = size % alignof(alloc_type); const auto align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull; const auto alloc_size = size + sizeof(alloc_type) + align_offset; const auto raw = std::allocator_traits<alloc_type>::allocate(alloc, alloc_size); new(raw + size + align_offset) alloc_type(std::move(alloc)); return raw; } /// Deallocate the memory and destroy the allocator in the coro memory. template <typename AllocatorType> void deallocate_coroutine(void* raw_, const std::size_t size) { using alloc_type = typename std::allocator_traits<AllocatorType>::template rebind_alloc<unsigned char>; const auto raw = static_cast<unsigned char *>(raw_); const auto align_needed = size % alignof(alloc_type); const auto align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull; const auto alloc_size = size + sizeof(alloc_type) + align_offset; auto alloc_p = reinterpret_cast<alloc_type *>(raw + size + align_offset); auto alloc = std::move(*alloc_p); alloc_p->~alloc_type(); std::allocator_traits<alloc_type>::deallocate(alloc, raw, alloc_size); } template <typename T> constexpr std::size_t variadic_first(std::size_t = 0u) { return std::numeric_limits<std::size_t>::max(); } template <typename T, typename First, typename... Args> constexpr std::size_t variadic_first(std::size_t pos = 0u) { if constexpr (std::is_same_v<std::decay_t<First>, T>) return pos; else return variadic_first<T, Args...>(pos+1); } template <std::size_t Idx, typename First, typename... Args> requires (Idx <= sizeof...(Args)) constexpr decltype(auto) get_variadic(First&& first, Args&&... args) { if constexpr (Idx == 0u) return static_cast<First>(first); else return get_variadic<Idx-1u>(static_cast<Args>(args)...); } template <std::size_t Idx> constexpr decltype(auto) get_variadic(); template <typename Allocator> struct coro_promise_allocator { using allocator_type = Allocator; allocator_type get_allocator() const {return alloc_;} template <typename... Args> void* operator new(const std::size_t size, Args & ... args) { return allocate_coroutine(size, get_variadic<variadic_first<std::allocator_arg_t, std::decay_t<Args>...>() + 1u>(args...)); } void operator delete(void* raw, const std::size_t size) { deallocate_coroutine<allocator_type>(raw, size); } template <typename... Args> coro_promise_allocator(Args&& ... args) : alloc_( get_variadic<variadic_first<std::allocator_arg_t, std::decay_t<Args>...>() + 1u>(args...)) { } private: allocator_type alloc_; }; template <> struct coro_promise_allocator<std::allocator<void>> { using allocator_type = std::allocator<void>; template <typename... Args> coro_promise_allocator(Args&&...) { } allocator_type get_allocator() const { return {}; } }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_PROMISE_ALLOCATOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_send_op.hpp
// // experimental/detail/channel_send_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/error.hpp> #include <boost/asio/experimental/channel_error.hpp> #include <boost/asio/experimental/detail/channel_operation.hpp> #include <boost/asio/experimental/detail/channel_payload.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Payload> class channel_send : public channel_operation { public: Payload get_payload() { return static_cast<Payload&&>(payload_); } void immediate() { func_(this, immediate_op, 0); } void post() { func_(this, post_op, 0); } void cancel() { func_(this, cancel_op, 0); } void close() { func_(this, close_op, 0); } protected: channel_send(func_type func, Payload&& payload) : channel_operation(func), payload_(static_cast<Payload&&>(payload)) { } private: Payload payload_; }; template <typename Payload, typename Handler, typename IoExecutor> class channel_send_op : public channel_send<Payload> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(channel_send_op); channel_send_op(Payload&& payload, Handler& handler, const IoExecutor& io_ex) : channel_send<Payload>(&channel_send_op::do_action, static_cast<Payload&&>(payload)), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_action(channel_operation* base, channel_operation::action a, void*) { // Take ownership of the operation object. channel_send_op* o(static_cast<channel_send_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. channel_operation::handler_work<Handler, IoExecutor> w( static_cast<channel_operation::handler_work<Handler, IoExecutor>&&>( o->work_)); boost::system::error_code ec; switch (a) { case channel_operation::cancel_op: ec = error::channel_cancelled; break; case channel_operation::close_op: ec = error::channel_closed; break; default: break; } // Make a copy of the handler so that the memory can be deallocated before // the handler is posted. Even if we're not about to post the handler, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. boost::asio::detail::binder1<Handler, boost::system::error_code> handler(o->handler_, ec); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Post the completion if required. if (a != channel_operation::destroy_op) { BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); if (a == channel_operation::immediate_op) w.immediate(handler, handler.handler_, 0); else w.post(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; channel_operation::handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_handler.hpp
// // experimental/detail/channel_handler.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/associator.hpp> #include <boost/asio/experimental/detail/channel_payload.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Payload, typename Handler> class channel_handler { public: channel_handler(Payload&& p, Handler& h) : payload_(static_cast<Payload&&>(p)), handler_(static_cast<Handler&&>(h)) { } void operator()() { payload_.receive(handler_); } //private: Payload payload_; Handler handler_; }; } // namespace detail } // namespace experimental template <template <typename, typename> class Associator, typename Payload, typename Handler, typename DefaultCandidate> struct associator<Associator, experimental::detail::channel_handler<Payload, Handler>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const experimental::detail::channel_handler<Payload, Handler>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get( const experimental::detail::channel_handler<Payload, Handler>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_operation.hpp
// // experimental/detail/channel_operation.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_OPERATION_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_OPERATION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/associated_immediate_executor.hpp> #include <boost/asio/detail/initiate_post.hpp> #include <boost/asio/detail/initiate_dispatch.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution/outstanding_work.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { // Base class for all channel operations. A function pointer is used instead of // virtual functions to avoid the associated overhead. class channel_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER { public: template <typename Executor, typename = void, typename = void> class handler_work_base; template <typename Handler, typename IoExecutor, typename = void> class handler_work; void destroy() { func_(this, destroy_op, 0); } protected: enum action { destroy_op = 0, immediate_op = 1, post_op = 2, dispatch_op = 3, cancel_op = 4, close_op = 5 }; typedef void (*func_type)(channel_operation*, action, void*); channel_operation(func_type func) : next_(0), func_(func), cancellation_key_(0) { } // Prevents deletion through this type. ~channel_operation() { } friend class boost::asio::detail::op_queue_access; channel_operation* next_; func_type func_; public: // The operation key used for targeted cancellation. void* cancellation_key_; }; template <typename Executor, typename, typename> class channel_operation::handler_work_base { public: typedef decay_t< prefer_result_t<Executor, execution::outstanding_work_t::tracked_t > > executor_type; handler_work_base(int, const Executor& ex) : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } const executor_type& get_executor() const noexcept { return executor_; } template <typename IoExecutor, typename Function, typename Handler> void post(const IoExecutor& io_exec, Function& function, Handler&) { (boost::asio::detail::initiate_post_with_executor<IoExecutor>(io_exec))( static_cast<Function&&>(function)); } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { associated_allocator_t<Handler> allocator = (get_associated_allocator)(handler); boost::asio::prefer(executor_, execution::allocator(allocator) ).execute(static_cast<Function&&>(function)); } private: executor_type executor_; }; template <typename Executor> class channel_operation::handler_work_base<Executor, enable_if_t< execution::is_executor<Executor>::value >, enable_if_t< can_require<Executor, execution::blocking_t::never_t>::value > > { public: typedef decay_t< prefer_result_t<Executor, execution::outstanding_work_t::tracked_t > > executor_type; handler_work_base(int, const Executor& ex) : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } const executor_type& get_executor() const noexcept { return executor_; } template <typename IoExecutor, typename Function, typename Handler> void post(const IoExecutor&, Function& function, Handler& handler) { associated_allocator_t<Handler> allocator = (get_associated_allocator)(handler); boost::asio::prefer( boost::asio::require(executor_, execution::blocking.never), execution::allocator(allocator) ).execute(static_cast<Function&&>(function)); } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { associated_allocator_t<Handler> allocator = (get_associated_allocator)(handler); boost::asio::prefer(executor_, execution::allocator(allocator) ).execute(static_cast<Function&&>(function)); } private: executor_type executor_; }; #if !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Executor> class channel_operation::handler_work_base<Executor, enable_if_t< !execution::is_executor<Executor>::value > > { public: typedef Executor executor_type; handler_work_base(int, const Executor& ex) : work_(ex) { } executor_type get_executor() const noexcept { return work_.get_executor(); } template <typename IoExecutor, typename Function, typename Handler> void post(const IoExecutor&, Function& function, Handler& handler) { associated_allocator_t<Handler> allocator = (get_associated_allocator)(handler); work_.get_executor().post( static_cast<Function&&>(function), allocator); } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { associated_allocator_t<Handler> allocator = (get_associated_allocator)(handler); work_.get_executor().dispatch( static_cast<Function&&>(function), allocator); } private: executor_work_guard<Executor> work_; }; #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Handler, typename IoExecutor, typename> class channel_operation::handler_work : channel_operation::handler_work_base<IoExecutor>, channel_operation::handler_work_base< associated_executor_t<Handler, IoExecutor>, IoExecutor> { public: typedef channel_operation::handler_work_base<IoExecutor> base1_type; typedef channel_operation::handler_work_base< associated_executor_t<Handler, IoExecutor>, IoExecutor> base2_type; handler_work(Handler& handler, const IoExecutor& io_ex) noexcept : base1_type(0, io_ex), base2_type(0, (get_associated_executor)(handler, io_ex)) { } template <typename Function> void post(Function& function, Handler& handler) { base2_type::post(base1_type::get_executor(), function, handler); } template <typename Function> void dispatch(Function& function, Handler& handler) { base2_type::dispatch(function, handler); } template <typename Function> void immediate(Function& function, Handler& handler, ...) { typedef associated_immediate_executor_t<Handler, typename base1_type::executor_type> immediate_ex_type; immediate_ex_type immediate_ex = (get_associated_immediate_executor)( handler, base1_type::get_executor()); (boost::asio::detail::initiate_dispatch_with_executor<immediate_ex_type>( immediate_ex))(static_cast<Function&&>(function)); } template <typename Function> void immediate(Function& function, Handler&, enable_if_t< is_same< typename associated_immediate_executor< conditional_t<false, Function, Handler>, typename base1_type::executor_type>:: asio_associated_immediate_executor_is_unspecialised, void >::value >*) { (boost::asio::detail::initiate_post_with_executor< typename base1_type::executor_type>( base1_type::get_executor()))( static_cast<Function&&>(function)); } }; template <typename Handler, typename IoExecutor> class channel_operation::handler_work< Handler, IoExecutor, enable_if_t< is_same< typename associated_executor<Handler, IoExecutor>::asio_associated_executor_is_unspecialised, void >::value > > : handler_work_base<IoExecutor> { public: typedef channel_operation::handler_work_base<IoExecutor> base1_type; handler_work(Handler&, const IoExecutor& io_ex) noexcept : base1_type(0, io_ex) { } template <typename Function> void post(Function& function, Handler& handler) { base1_type::post(base1_type::get_executor(), function, handler); } template <typename Function> void dispatch(Function& function, Handler& handler) { base1_type::dispatch(function, handler); } template <typename Function> void immediate(Function& function, Handler& handler, ...) { typedef associated_immediate_executor_t<Handler, typename base1_type::executor_type> immediate_ex_type; immediate_ex_type immediate_ex = (get_associated_immediate_executor)( handler, base1_type::get_executor()); (boost::asio::detail::initiate_dispatch_with_executor<immediate_ex_type>( immediate_ex))(static_cast<Function&&>(function)); } template <typename Function> void immediate(Function& function, Handler& handler, enable_if_t< is_same< typename associated_immediate_executor< conditional_t<false, Function, Handler>, typename base1_type::executor_type>:: asio_associated_immediate_executor_is_unspecialised, void >::value >*) { base1_type::post(base1_type::get_executor(), function, handler); } }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_OPERATION_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/coro_completion_handler.hpp
// // experimental/detail/coro_completion_handler.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_COMPLETION_HANDLER_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_COMPLETION_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/deferred.hpp> #include <boost/asio/experimental/coro.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Promise, typename... Args> struct coro_completion_handler { coro_completion_handler(coroutine_handle<Promise> h, std::optional<std::tuple<Args...>>& result) : self(h), result(result) { } coro_completion_handler(coro_completion_handler&&) = default; coroutine_handle<Promise> self; std::optional<std::tuple<Args...>>& result; using promise_type = Promise; void operator()(Args... args) { result.emplace(std::move(args)...); self.resume(); } using allocator_type = typename promise_type::allocator_type; allocator_type get_allocator() const noexcept { return self.promise().get_allocator(); } using executor_type = typename promise_type::executor_type; executor_type get_executor() const noexcept { return self.promise().get_executor(); } using cancellation_slot_type = typename promise_type::cancellation_slot_type; cancellation_slot_type get_cancellation_slot() const noexcept { return self.promise().get_cancellation_slot(); } }; template <typename Signature> struct coro_completion_handler_type; template <typename... Args> struct coro_completion_handler_type<void(Args...)> { using type = std::tuple<Args...>; template <typename Promise> using completion_handler = coro_completion_handler<Promise, Args...>; }; template <typename Signature> using coro_completion_handler_type_t = typename coro_completion_handler_type<Signature>::type; inline void coro_interpret_result(std::tuple<>&&) { } template <typename... Args> inline auto coro_interpret_result(std::tuple<Args...>&& args) { return std::move(args); } template <typename... Args> auto coro_interpret_result(std::tuple<std::exception_ptr, Args...>&& args) { if (std::get<0>(args)) std::rethrow_exception(std::get<0>(args)); return std::apply( [](auto, auto&&... rest) { return std::make_tuple(std::move(rest)...); }, std::move(args)); } template <typename... Args> auto coro_interpret_result( std::tuple<boost::system::error_code, Args...>&& args) { if (std::get<0>(args)) boost::asio::detail::throw_exception( boost::system::system_error(std::get<0>(args))); return std::apply( [](auto, auto&&... rest) { return std::make_tuple(std::move(rest)...); }, std::move(args)); } template <typename Arg> inline auto coro_interpret_result(std::tuple<Arg>&& args) { return std::get<0>(std::move(args)); } template <typename Arg> auto coro_interpret_result(std::tuple<std::exception_ptr, Arg>&& args) { if (std::get<0>(args)) std::rethrow_exception(std::get<0>(args)); return std::get<1>(std::move(args)); } inline auto coro_interpret_result( std::tuple<boost::system::error_code>&& args) { if (std::get<0>(args)) boost::asio::detail::throw_exception( boost::system::system_error(std::get<0>(args))); } inline auto coro_interpret_result(std::tuple<std::exception_ptr>&& args) { if (std::get<0>(args)) std::rethrow_exception(std::get<0>(args)); } template <typename Arg> auto coro_interpret_result(std::tuple<boost::system::error_code, Arg>&& args) { if (std::get<0>(args)) boost::asio::detail::throw_exception( boost::system::system_error(std::get<0>(args))); return std::get<1>(std::move(args)); } } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CORO_COMPLETION_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/partial_promise.hpp
// // experimental/detail/partial_promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_PARTIAL_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_PARTIAL_PROMISE_HPP #include <boost/asio/detail/config.hpp> #include <boost/asio/append.hpp> #include <boost/asio/awaitable.hpp> #include <boost/asio/experimental/coro_traits.hpp> #if defined(BOOST_ASIO_HAS_STD_COROUTINE) # include <coroutine> #else // defined(BOOST_ASIO_HAS_STD_COROUTINE) # include <experimental/coroutine> #endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace boost { namespace asio { namespace experimental { namespace detail { #if defined(BOOST_ASIO_HAS_STD_COROUTINE) using std::coroutine_handle; using std::coroutine_traits; using std::suspend_never; using std::suspend_always; using std::noop_coroutine; #else // defined(BOOST_ASIO_HAS_STD_COROUTINE) using std::experimental::coroutine_handle; using std::experimental::coroutine_traits; using std::experimental::suspend_never; using std::experimental::suspend_always; using std::experimental::noop_coroutine; #endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) struct partial_coro { coroutine_handle<void> handle{nullptr}; }; template <typename Allocator> struct partial_promise_base { template <typename Executor, typename Token, typename... Args> void* operator new(const std::size_t size, Executor&, Token& tk, Args&...) { return allocate_coroutine<Allocator>(size, get_associated_allocator(tk)); } void operator delete(void* raw, const std::size_t size) { deallocate_coroutine<Allocator>(raw, size); } }; template <> struct partial_promise_base<std::allocator<void>> { }; template <typename Allocator> struct partial_promise : partial_promise_base<Allocator> { auto initial_suspend() noexcept { return boost::asio::detail::suspend_always{}; } auto final_suspend() noexcept { struct awaitable_t { partial_promise *p; constexpr bool await_ready() noexcept { return true; } auto await_suspend(boost::asio::detail::coroutine_handle<>) noexcept { p->get_return_object().handle.destroy(); } constexpr void await_resume() noexcept {} }; return awaitable_t{this}; } void return_void() {} partial_coro get_return_object() { return partial_coro{coroutine_handle<partial_promise>::from_promise(*this)}; } void unhandled_exception() { assert(false); } }; }; // namespace detail } // namespace experimental } // namespace asio } // namespace boost #if defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace std { template <typename Executor, typename Completion, typename... Args> struct coroutine_traits< boost::asio::experimental::detail::partial_coro, Executor, Completion, Args...> { using promise_type = boost::asio::experimental::detail::partial_promise< boost::asio::associated_allocator_t<Completion>>; }; } // namespace std #else // defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace std { namespace experimental { template <typename Executor, typename Completion, typename... Args> struct coroutine_traits< boost::asio::experimental::detail::partial_coro, Executor, Completion, Args...> { using promise_type = boost::asio::experimental::detail::partial_promise< boost::asio::associated_allocator_t<Completion>>; }; }} // namespace std::experimental #endif // defined(BOOST_ASIO_HAS_STD_COROUTINE) namespace boost { namespace asio { namespace experimental { namespace detail { template <execution::executor Executor, typename CompletionToken, typename... Args> partial_coro post_coroutine(Executor exec, CompletionToken token, Args&&... args) noexcept { post(exec, boost::asio::append(std::move(token), std::move(args)...)); co_return; } template <detail::execution_context Context, typename CompletionToken, typename... Args> partial_coro post_coroutine(Context& ctx, CompletionToken token, Args&&... args) noexcept { post(ctx, boost::asio::append(std::move(token), std::move(args)...)); co_return; } template <execution::executor Executor, typename CompletionToken, typename... Args> partial_coro dispatch_coroutine(Executor exec, CompletionToken token, Args&&... args) noexcept { dispatch(exec, boost::asio::append(std::move(token), std::move(args)...)); co_return; } template <detail::execution_context Context, typename CompletionToken, typename... Args> partial_coro dispatch_coroutine(Context& ctx, CompletionToken token, Args &&... args) noexcept { dispatch(ctx, boost::asio::append(std::move(token), std::move(args)...)); co_return; } } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_PARTIAL_PROMISE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_receive_op.hpp
// // experimental/detail/channel_receive_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_RECEIVE_OP_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_RECEIVE_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/error.hpp> #include <boost/asio/experimental/detail/channel_handler.hpp> #include <boost/asio/experimental/detail/channel_operation.hpp> #include <boost/asio/experimental/detail/channel_payload.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Payload> class channel_receive : public channel_operation { public: void immediate(Payload payload) { func_(this, immediate_op, &payload); } void post(Payload payload) { func_(this, post_op, &payload); } void dispatch(Payload payload) { func_(this, dispatch_op, &payload); } protected: channel_receive(func_type func) : channel_operation(func) { } }; template <typename Payload, typename Handler, typename IoExecutor> class channel_receive_op : public channel_receive<Payload> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(channel_receive_op); template <typename... Args> channel_receive_op(Handler& handler, const IoExecutor& io_ex) : channel_receive<Payload>(&channel_receive_op::do_action), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_action(channel_operation* base, channel_operation::action a, void* v) { // Take ownership of the operation object. channel_receive_op* o(static_cast<channel_receive_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. channel_operation::handler_work<Handler, IoExecutor> w( static_cast<channel_operation::handler_work<Handler, IoExecutor>&&>( o->work_)); // Make a copy of the handler so that the memory can be deallocated before // the handler is posted. Even if we're not about to post the handler, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. if (a != channel_operation::destroy_op) { Payload* payload = static_cast<Payload*>(v); channel_handler<Payload, Handler> handler( static_cast<Payload&&>(*payload), o->handler_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN(()); if (a == channel_operation::immediate_op) w.immediate(handler, handler.handler_, 0); else if (a == channel_operation::dispatch_op) w.dispatch(handler, handler.handler_); else w.post(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } else { boost::asio::detail::binder0<Handler> handler(o->handler_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); } } private: Handler handler_; channel_operation::handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_RECEIVE_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_send_functions.hpp
// // experimental/detail/channel_send_functions.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/async_result.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/experimental/detail/channel_message.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Derived, typename Executor, typename... Signatures> class channel_send_functions; template <typename Derived, typename Executor, typename R, typename... Args> class channel_send_functions<Derived, Executor, R(Args...)> { public: template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, bool > try_send(Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send<message_type>( self->impl_, false, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, bool > try_send_via_dispatch(Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send<message_type>( self->impl_, true, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, std::size_t > try_send_n(std::size_t count, Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send_n<message_type>( self->impl_, count, false, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, std::size_t > try_send_n_via_dispatch(std::size_t count, Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send_n<message_type>( self->impl_, count, true, static_cast<Args2&&>(args)...); } template < BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)> auto async_send(Args... args, CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)) -> decltype( async_initiate<CompletionToken, void (boost::system::error_code)>( declval<typename conditional_t<false, CompletionToken, Derived>::initiate_async_send>(), token, declval<typename conditional_t<false, CompletionToken, Derived>::payload_type>())) { typedef typename Derived::payload_type payload_type; typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return async_initiate<CompletionToken, void (boost::system::error_code)>( typename Derived::initiate_async_send(self), token, payload_type(message_type(0, static_cast<Args&&>(args)...))); } }; template <typename Derived, typename Executor, typename R, typename... Args, typename... Signatures> class channel_send_functions<Derived, Executor, R(Args...), Signatures...> : public channel_send_functions<Derived, Executor, Signatures...> { public: using channel_send_functions<Derived, Executor, Signatures...>::try_send; using channel_send_functions<Derived, Executor, Signatures...>::async_send; template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, bool > try_send(Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send<message_type>( self->impl_, false, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, bool > try_send_via_dispatch(Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send<message_type>( self->impl_, true, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, std::size_t > try_send_n(std::size_t count, Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send_n<message_type>( self->impl_, count, false, static_cast<Args2&&>(args)...); } template <typename... Args2> enable_if_t< is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value, std::size_t > try_send_n_via_dispatch(std::size_t count, Args2&&... args) { typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return self->service_->template try_send_n<message_type>( self->impl_, count, true, static_cast<Args2&&>(args)...); } template < BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)> auto async_send(Args... args, CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)) -> decltype( async_initiate<CompletionToken, void (boost::system::error_code)>( declval<typename conditional_t<false, CompletionToken, Derived>::initiate_async_send>(), token, declval<typename conditional_t<false, CompletionToken, Derived>::payload_type>())) { typedef typename Derived::payload_type payload_type; typedef typename detail::channel_message<R(Args...)> message_type; Derived* self = static_cast<Derived*>(this); return async_initiate<CompletionToken, void (boost::system::error_code)>( typename Derived::initiate_async_send(self), token, payload_type(message_type(0, static_cast<Args&&>(args)...))); } }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/has_signature.hpp
// // experimental/detail/has_signature.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_HAS_SIGNATURE_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_HAS_SIGNATURE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename S, typename... Signatures> struct has_signature; template <typename S, typename... Signatures> struct has_signature; template <typename S> struct has_signature<S> : false_type { }; template <typename S, typename... Signatures> struct has_signature<S, S, Signatures...> : true_type { }; template <typename S, typename Head, typename... Tail> struct has_signature<S, Head, Tail...> : has_signature<S, Tail...> { }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_HAS_SIGNATURE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_payload.hpp
// // experimental/detail/channel_payload.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_PAYLOAD_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_PAYLOAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/experimental/detail/channel_message.hpp> #if defined(BOOST_ASIO_HAS_STD_VARIANT) # include <variant> #else // defined(BOOST_ASIO_HAS_STD_VARIANT) # include <new> #endif // defined(BOOST_ASIO_HAS_STD_VARIANT) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename... Signatures> class channel_payload; template <typename R> class channel_payload<R()> { public: explicit channel_payload(channel_message<R()>) { } template <typename Handler> void receive(Handler& handler) { static_cast<Handler&&>(handler)(); } }; template <typename Signature> class channel_payload<Signature> { public: channel_payload(channel_message<Signature>&& m) : message_(static_cast<channel_message<Signature>&&>(m)) { } template <typename Handler> void receive(Handler& handler) { message_.receive(handler); } private: channel_message<Signature> message_; }; #if defined(BOOST_ASIO_HAS_STD_VARIANT) template <typename... Signatures> class channel_payload { public: template <typename Signature> channel_payload(channel_message<Signature>&& m) : message_(static_cast<channel_message<Signature>&&>(m)) { } template <typename Handler> void receive(Handler& handler) { std::visit( [&](auto& message) { message.receive(handler); }, message_); } private: std::variant<channel_message<Signatures>...> message_; }; #else // defined(BOOST_ASIO_HAS_STD_VARIANT) template <typename R1, typename R2> class channel_payload<R1(), R2(boost::system::error_code)> { public: typedef channel_message<R1()> void_message_type; typedef channel_message<R2(boost::system::error_code)> error_message_type; channel_payload(void_message_type&&) : message_(0, boost::system::error_code()), empty_(true) { } channel_payload(error_message_type&& m) : message_(static_cast<error_message_type&&>(m)), empty_(false) { } template <typename Handler> void receive(Handler& handler) { if (empty_) channel_message<R1()>(0).receive(handler); else message_.receive(handler); } private: error_message_type message_; bool empty_; }; template <typename Sig1, typename Sig2> class channel_payload<Sig1, Sig2> { public: typedef channel_message<Sig1> message_1_type; typedef channel_message<Sig2> message_2_type; channel_payload(message_1_type&& m) : index_(1) { new (&storage_.message_1_) message_1_type(static_cast<message_1_type&&>(m)); } channel_payload(message_2_type&& m) : index_(2) { new (&storage_.message_2_) message_2_type(static_cast<message_2_type&&>(m)); } channel_payload(channel_payload&& other) : index_(other.index_) { switch (index_) { case 1: new (&storage_.message_1_) message_1_type( static_cast<message_1_type&&>(other.storage_.message_1_)); break; case 2: new (&storage_.message_2_) message_2_type( static_cast<message_2_type&&>(other.storage_.message_2_)); break; default: break; } } ~channel_payload() { switch (index_) { case 1: storage_.message_1_.~message_1_type(); break; case 2: storage_.message_2_.~message_2_type(); break; default: break; } } template <typename Handler> void receive(Handler& handler) { switch (index_) { case 1: storage_.message_1_.receive(handler); break; case 2: storage_.message_2_.receive(handler); break; default: break; } } private: union storage { storage() {} ~storage() {} char dummy_; message_1_type message_1_; message_2_type message_2_; } storage_; unsigned char index_; }; #endif // defined(BOOST_ASIO_HAS_STD_VARIANT) } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_PAYLOAD_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/channel_message.hpp
// // experimental/detail/channel_message.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <tuple> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/utility.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Signature> class channel_message; template <typename R> class channel_message<R()> { public: channel_message(int) { } template <typename Handler> void receive(Handler& handler) { static_cast<Handler&&>(handler)(); } }; template <typename R, typename Arg0> class channel_message<R(Arg0)> { public: template <typename T0> channel_message(int, T0&& t0) : arg0_(static_cast<T0&&>(t0)) { } template <typename Handler> void receive(Handler& handler) { static_cast<Handler&&>(handler)( static_cast<arg0_type&&>(arg0_)); } private: typedef decay_t<Arg0> arg0_type; arg0_type arg0_; }; template <typename R, typename Arg0, typename Arg1> class channel_message<R(Arg0, Arg1)> { public: template <typename T0, typename T1> channel_message(int, T0&& t0, T1&& t1) : arg0_(static_cast<T0&&>(t0)), arg1_(static_cast<T1&&>(t1)) { } template <typename Handler> void receive(Handler& handler) { static_cast<Handler&&>(handler)( static_cast<arg0_type&&>(arg0_), static_cast<arg1_type&&>(arg1_)); } private: typedef decay_t<Arg0> arg0_type; arg0_type arg0_; typedef decay_t<Arg1> arg1_type; arg1_type arg1_; }; template <typename R, typename... Args> class channel_message<R(Args...)> { public: template <typename... T> channel_message(int, T&&... t) : args_(static_cast<T&&>(t)...) { } template <typename Handler> void receive(Handler& h) { this->do_receive(h, boost::asio::detail::index_sequence_for<Args...>()); } private: template <typename Handler, std::size_t... I> void do_receive(Handler& h, boost::asio::detail::index_sequence<I...>) { static_cast<Handler&&>(h)( std::get<I>(static_cast<args_type&&>(args_))...); } typedef std::tuple<decay_t<Args>...> args_type; args_type args_; }; } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_HPP
hpp
asio
data/projects/asio/include/boost/asio/experimental/detail/impl/channel_service.hpp
// // experimental/detail/impl/channel_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_IMPL_CHANNEL_SERVICE_HPP #define BOOST_ASIO_EXPERIMENTAL_DETAIL_IMPL_CHANNEL_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace experimental { namespace detail { template <typename Mutex> inline channel_service<Mutex>::channel_service(execution_context& ctx) : boost::asio::detail::execution_context_service_base<channel_service>(ctx), mutex_(), impl_list_(0) { } template <typename Mutex> inline void channel_service<Mutex>::shutdown() { // Abandon all pending operations. boost::asio::detail::op_queue<channel_operation> ops; boost::asio::detail::mutex::scoped_lock lock(mutex_); base_implementation_type* impl = impl_list_; while (impl) { ops.push(impl->waiters_); impl = impl->next_; } } template <typename Mutex> inline void channel_service<Mutex>::construct( channel_service<Mutex>::base_implementation_type& impl, std::size_t max_buffer_size) { impl.max_buffer_size_ = max_buffer_size; impl.receive_state_ = block; impl.send_state_ = max_buffer_size ? buffer : block; // Insert implementation into linked list of all implementations. boost::asio::detail::mutex::scoped_lock lock(mutex_); impl.next_ = impl_list_; impl.prev_ = 0; if (impl_list_) impl_list_->prev_ = &impl; impl_list_ = &impl; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::destroy( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl) { cancel(impl); base_destroy(impl); } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::move_construct( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, channel_service<Mutex>::implementation_type< Traits, Signatures...>& other_impl) { impl.max_buffer_size_ = other_impl.max_buffer_size_; impl.receive_state_ = other_impl.receive_state_; other_impl.receive_state_ = block; impl.send_state_ = other_impl.send_state_; other_impl.send_state_ = other_impl.max_buffer_size_ ? buffer : block; impl.buffer_move_from(other_impl); // Insert implementation into linked list of all implementations. boost::asio::detail::mutex::scoped_lock lock(mutex_); impl.next_ = impl_list_; impl.prev_ = 0; if (impl_list_) impl_list_->prev_ = &impl; impl_list_ = &impl; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::move_assign( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, channel_service& other_service, channel_service<Mutex>::implementation_type< Traits, Signatures...>& other_impl) { cancel(impl); if (this != &other_service) { // Remove implementation from linked list of all implementations. boost::asio::detail::mutex::scoped_lock lock(mutex_); if (impl_list_ == &impl) impl_list_ = impl.next_; if (impl.prev_) impl.prev_->next_ = impl.next_; if (impl.next_) impl.next_->prev_= impl.prev_; impl.next_ = 0; impl.prev_ = 0; } impl.max_buffer_size_ = other_impl.max_buffer_size_; impl.receive_state_ = other_impl.receive_state_; other_impl.receive_state_ = block; impl.send_state_ = other_impl.send_state_; other_impl.send_state_ = other_impl.max_buffer_size_ ? buffer : block; impl.buffer_move_from(other_impl); if (this != &other_service) { // Insert implementation into linked list of all implementations. boost::asio::detail::mutex::scoped_lock lock(other_service.mutex_); impl.next_ = other_service.impl_list_; impl.prev_ = 0; if (other_service.impl_list_) other_service.impl_list_->prev_ = &impl; other_service.impl_list_ = &impl; } } template <typename Mutex> inline void channel_service<Mutex>::base_destroy( channel_service<Mutex>::base_implementation_type& impl) { // Remove implementation from linked list of all implementations. boost::asio::detail::mutex::scoped_lock lock(mutex_); if (impl_list_ == &impl) impl_list_ = impl.next_; if (impl.prev_) impl.prev_->next_ = impl.next_; if (impl.next_) impl.next_->prev_= impl.prev_; impl.next_ = 0; impl.prev_ = 0; } template <typename Mutex> inline std::size_t channel_service<Mutex>::capacity( const channel_service<Mutex>::base_implementation_type& impl) const noexcept { typename Mutex::scoped_lock lock(impl.mutex_); return impl.max_buffer_size_; } template <typename Mutex> inline bool channel_service<Mutex>::is_open( const channel_service<Mutex>::base_implementation_type& impl) const noexcept { typename Mutex::scoped_lock lock(impl.mutex_); return impl.send_state_ != closed; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::reset( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl) { cancel(impl); typename Mutex::scoped_lock lock(impl.mutex_); impl.receive_state_ = block; impl.send_state_ = impl.max_buffer_size_ ? buffer : block; impl.buffer_clear(); } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::close( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl) { typedef typename implementation_type<Traits, Signatures...>::traits_type traits_type; typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); if (impl.receive_state_ == block) { while (channel_operation* op = impl.waiters_.front()) { impl.waiters_.pop(); traits_type::invoke_receive_closed( post_receive<payload_type, typename traits_type::receive_closed_signature>( static_cast<channel_receive<payload_type>*>(op))); } } impl.send_state_ = closed; if (impl.receive_state_ != buffer) impl.receive_state_ = closed; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::cancel( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl) { typedef typename implementation_type<Traits, Signatures...>::traits_type traits_type; typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); while (channel_operation* op = impl.waiters_.front()) { if (impl.send_state_ == block) { impl.waiters_.pop(); static_cast<channel_send<payload_type>*>(op)->cancel(); } else { impl.waiters_.pop(); traits_type::invoke_receive_cancelled( post_receive<payload_type, typename traits_type::receive_cancelled_signature>( static_cast<channel_receive<payload_type>*>(op))); } } if (impl.receive_state_ == waiter) impl.receive_state_ = block; if (impl.send_state_ == waiter) impl.send_state_ = impl.max_buffer_size_ ? buffer : block; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::cancel_by_key( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, void* cancellation_key) { typedef typename implementation_type<Traits, Signatures...>::traits_type traits_type; typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); boost::asio::detail::op_queue<channel_operation> other_ops; while (channel_operation* op = impl.waiters_.front()) { if (op->cancellation_key_ == cancellation_key) { if (impl.send_state_ == block) { impl.waiters_.pop(); static_cast<channel_send<payload_type>*>(op)->cancel(); } else { impl.waiters_.pop(); traits_type::invoke_receive_cancelled( post_receive<payload_type, typename traits_type::receive_cancelled_signature>( static_cast<channel_receive<payload_type>*>(op))); } } else { impl.waiters_.pop(); other_ops.push(op); } } impl.waiters_.push(other_ops); if (impl.waiters_.empty()) { if (impl.receive_state_ == waiter) impl.receive_state_ = block; if (impl.send_state_ == waiter) impl.send_state_ = impl.max_buffer_size_ ? buffer : block; } } template <typename Mutex> inline bool channel_service<Mutex>::ready( const channel_service<Mutex>::base_implementation_type& impl) const noexcept { typename Mutex::scoped_lock lock(impl.mutex_); return impl.receive_state_ != block; } template <typename Mutex> template <typename Message, typename Traits, typename... Signatures, typename... Args> bool channel_service<Mutex>::try_send( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, bool via_dispatch, Args&&... args) { typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); switch (impl.send_state_) { case block: { return false; } case buffer: { impl.buffer_push(Message(0, static_cast<Args&&>(args)...)); impl.receive_state_ = buffer; if (impl.buffer_size() == impl.max_buffer_size_) impl.send_state_ = block; return true; } case waiter: { payload_type payload(Message(0, static_cast<Args&&>(args)...)); channel_receive<payload_type>* receive_op = static_cast<channel_receive<payload_type>*>(impl.waiters_.front()); impl.waiters_.pop(); if (impl.waiters_.empty()) impl.send_state_ = impl.max_buffer_size_ ? buffer : block; lock.unlock(); if (via_dispatch) receive_op->dispatch(static_cast<payload_type&&>(payload)); else receive_op->post(static_cast<payload_type&&>(payload)); return true; } case closed: default: { return false; } } } template <typename Mutex> template <typename Message, typename Traits, typename... Signatures, typename... Args> std::size_t channel_service<Mutex>::try_send_n( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, std::size_t count, bool via_dispatch, Args&&... args) { typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); if (count == 0) return 0; switch (impl.send_state_) { case block: return 0; case buffer: case waiter: break; case closed: default: return 0; } payload_type payload(Message(0, static_cast<Args&&>(args)...)); for (std::size_t i = 0; i < count; ++i) { switch (impl.send_state_) { case block: { return i; } case buffer: { i += impl.buffer_push_n(count - i, static_cast<payload_type&&>(payload)); impl.receive_state_ = buffer; if (impl.buffer_size() == impl.max_buffer_size_) impl.send_state_ = block; return i; } case waiter: { channel_receive<payload_type>* receive_op = static_cast<channel_receive<payload_type>*>(impl.waiters_.front()); impl.waiters_.pop(); if (impl.waiters_.empty()) impl.send_state_ = impl.max_buffer_size_ ? buffer : block; lock.unlock(); if (via_dispatch) receive_op->dispatch(payload); else receive_op->post(payload); break; } case closed: default: { return i; } } } return count; } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::start_send_op( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, channel_send<typename implementation_type< Traits, Signatures...>::payload_type>* send_op) { typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); switch (impl.send_state_) { case block: { impl.waiters_.push(send_op); if (impl.receive_state_ == block) impl.receive_state_ = waiter; return; } case buffer: { impl.buffer_push(send_op->get_payload()); impl.receive_state_ = buffer; if (impl.buffer_size() == impl.max_buffer_size_) impl.send_state_ = block; send_op->immediate(); break; } case waiter: { channel_receive<payload_type>* receive_op = static_cast<channel_receive<payload_type>*>(impl.waiters_.front()); impl.waiters_.pop(); if (impl.waiters_.empty()) impl.send_state_ = impl.max_buffer_size_ ? buffer : block; receive_op->post(send_op->get_payload()); send_op->immediate(); break; } case closed: default: { send_op->close(); break; } } } template <typename Mutex> template <typename Traits, typename... Signatures, typename Handler> bool channel_service<Mutex>::try_receive( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, Handler&& handler) { typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); switch (impl.receive_state_) { case block: { return false; } case buffer: { payload_type payload(impl.buffer_front()); if (channel_send<payload_type>* send_op = static_cast<channel_send<payload_type>*>(impl.waiters_.front())) { impl.buffer_pop(); impl.buffer_push(send_op->get_payload()); impl.waiters_.pop(); send_op->post(); } else { impl.buffer_pop(); if (impl.buffer_size() == 0) impl.receive_state_ = (impl.send_state_ == closed) ? closed : block; impl.send_state_ = (impl.send_state_ == closed) ? closed : buffer; } lock.unlock(); boost::asio::detail::non_const_lvalue<Handler> handler2(handler); channel_handler<payload_type, decay_t<Handler>>( static_cast<payload_type&&>(payload), handler2.value)(); return true; } case waiter: { channel_send<payload_type>* send_op = static_cast<channel_send<payload_type>*>(impl.waiters_.front()); payload_type payload = send_op->get_payload(); impl.waiters_.pop(); if (impl.waiters_.front() == 0) impl.receive_state_ = (impl.send_state_ == closed) ? closed : block; send_op->post(); lock.unlock(); boost::asio::detail::non_const_lvalue<Handler> handler2(handler); channel_handler<payload_type, decay_t<Handler>>( static_cast<payload_type&&>(payload), handler2.value)(); return true; } case closed: default: { return false; } } } template <typename Mutex> template <typename Traits, typename... Signatures> void channel_service<Mutex>::start_receive_op( channel_service<Mutex>::implementation_type<Traits, Signatures...>& impl, channel_receive<typename implementation_type< Traits, Signatures...>::payload_type>* receive_op) { typedef typename implementation_type<Traits, Signatures...>::traits_type traits_type; typedef typename implementation_type<Traits, Signatures...>::payload_type payload_type; typename Mutex::scoped_lock lock(impl.mutex_); switch (impl.receive_state_) { case block: { impl.waiters_.push(receive_op); if (impl.send_state_ != closed) impl.send_state_ = waiter; return; } case buffer: { payload_type payload( static_cast<payload_type&&>(impl.buffer_front())); if (channel_send<payload_type>* send_op = static_cast<channel_send<payload_type>*>(impl.waiters_.front())) { impl.buffer_pop(); impl.buffer_push(send_op->get_payload()); impl.waiters_.pop(); send_op->post(); } else { impl.buffer_pop(); if (impl.buffer_size() == 0) impl.receive_state_ = (impl.send_state_ == closed) ? closed : block; impl.send_state_ = (impl.send_state_ == closed) ? closed : buffer; } receive_op->immediate(static_cast<payload_type&&>(payload)); break; } case waiter: { channel_send<payload_type>* send_op = static_cast<channel_send<payload_type>*>(impl.waiters_.front()); payload_type payload = send_op->get_payload(); impl.waiters_.pop(); if (impl.waiters_.front() == 0) impl.receive_state_ = (impl.send_state_ == closed) ? closed : block; send_op->post(); receive_op->immediate(static_cast<payload_type&&>(payload)); break; } case closed: default: { traits_type::invoke_receive_closed( post_receive<payload_type, typename traits_type::receive_closed_signature>(receive_op)); break; } } } } // namespace detail } // namespace experimental } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_IMPL_CHANNEL_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/seq_packet_protocol.hpp
// // local/seq_packet_protocol.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_LOCAL_SEQ_PACKET_PROTOCOL_HPP #define BOOST_ASIO_LOCAL_SEQ_PACKET_PROTOCOL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/basic_socket_acceptor.hpp> #include <boost/asio/basic_seq_packet_socket.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/local/basic_endpoint.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { /// Encapsulates the flags needed for seq_packet UNIX sockets. /** * The boost::asio::local::seq_packet_protocol class contains flags necessary * for sequenced packet UNIX domain sockets. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Safe. * * @par Concepts: * Protocol. */ class seq_packet_protocol { public: /// Obtain an identifier for the type of the protocol. int type() const noexcept { return SOCK_SEQPACKET; } /// Obtain an identifier for the protocol. int protocol() const noexcept { return 0; } /// Obtain an identifier for the protocol family. int family() const noexcept { return AF_UNIX; } /// The type of a UNIX domain endpoint. typedef basic_endpoint<seq_packet_protocol> endpoint; /// The UNIX domain socket type. typedef basic_seq_packet_socket<seq_packet_protocol> socket; /// The UNIX domain acceptor type. typedef basic_socket_acceptor<seq_packet_protocol> acceptor; }; } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_SEQ_PACKET_PROTOCOL_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/stream_protocol.hpp
// // local/stream_protocol.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP #define BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/basic_socket_acceptor.hpp> #include <boost/asio/basic_socket_iostream.hpp> #include <boost/asio/basic_stream_socket.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/local/basic_endpoint.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { /// Encapsulates the flags needed for stream-oriented UNIX sockets. /** * The boost::asio::local::stream_protocol class contains flags necessary for * stream-oriented UNIX domain sockets. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Safe. * * @par Concepts: * Protocol. */ class stream_protocol { public: /// Obtain an identifier for the type of the protocol. int type() const noexcept { return SOCK_STREAM; } /// Obtain an identifier for the protocol. int protocol() const noexcept { return 0; } /// Obtain an identifier for the protocol family. int family() const noexcept { return AF_UNIX; } /// The type of a UNIX domain endpoint. typedef basic_endpoint<stream_protocol> endpoint; /// The UNIX domain socket type. typedef basic_stream_socket<stream_protocol> socket; /// The UNIX domain acceptor type. typedef basic_socket_acceptor<stream_protocol> acceptor; #if !defined(BOOST_ASIO_NO_IOSTREAM) /// The UNIX domain iostream type. typedef basic_socket_iostream<stream_protocol> iostream; #endif // !defined(BOOST_ASIO_NO_IOSTREAM) }; } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/basic_endpoint.hpp
// // local/basic_endpoint.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Derived from a public domain implementation written by Daniel Casimiro. // // 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 BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP #define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/local/detail/endpoint.hpp> #if !defined(BOOST_ASIO_NO_IOSTREAM) # include <iosfwd> #endif // !defined(BOOST_ASIO_NO_IOSTREAM) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { /// Describes an endpoint for a UNIX socket. /** * The boost::asio::local::basic_endpoint class template describes an endpoint * that may be associated with a particular UNIX socket. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. * * @par Concepts: * Endpoint. */ template <typename Protocol> class basic_endpoint { public: /// The protocol type associated with the endpoint. typedef Protocol protocol_type; /// The type of the endpoint structure. This type is dependent on the /// underlying implementation of the socket layer. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined data_type; #else typedef boost::asio::detail::socket_addr_type data_type; #endif /// Default constructor. basic_endpoint() noexcept { } /// Construct an endpoint using the specified path name. basic_endpoint(const char* path_name) : impl_(path_name) { } /// Construct an endpoint using the specified path name. basic_endpoint(const std::string& path_name) : impl_(path_name) { } #if defined(BOOST_ASIO_HAS_STRING_VIEW) /// Construct an endpoint using the specified path name. basic_endpoint(string_view path_name) : impl_(path_name) { } #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) /// Copy constructor. basic_endpoint(const basic_endpoint& other) : impl_(other.impl_) { } /// Move constructor. basic_endpoint(basic_endpoint&& other) : impl_(other.impl_) { } /// Assign from another endpoint. basic_endpoint& operator=(const basic_endpoint& other) { impl_ = other.impl_; return *this; } /// Move-assign from another endpoint. basic_endpoint& operator=(basic_endpoint&& other) { impl_ = other.impl_; return *this; } /// The protocol associated with the endpoint. protocol_type protocol() const { return protocol_type(); } /// Get the underlying endpoint in the native type. data_type* data() { return impl_.data(); } /// Get the underlying endpoint in the native type. const data_type* data() const { return impl_.data(); } /// Get the underlying size of the endpoint in the native type. std::size_t size() const { return impl_.size(); } /// Set the underlying size of the endpoint in the native type. void resize(std::size_t new_size) { impl_.resize(new_size); } /// Get the capacity of the endpoint in the native type. std::size_t capacity() const { return impl_.capacity(); } /// Get the path associated with the endpoint. std::string path() const { return impl_.path(); } /// Set the path associated with the endpoint. void path(const char* p) { impl_.path(p); } /// Set the path associated with the endpoint. void path(const std::string& p) { impl_.path(p); } /// Compare two endpoints for equality. friend bool operator==(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return e1.impl_ == e2.impl_; } /// Compare two endpoints for inequality. friend bool operator!=(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return !(e1.impl_ == e2.impl_); } /// Compare endpoints for ordering. friend bool operator<(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return e1.impl_ < e2.impl_; } /// Compare endpoints for ordering. friend bool operator>(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return e2.impl_ < e1.impl_; } /// Compare endpoints for ordering. friend bool operator<=(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return !(e2 < e1); } /// Compare endpoints for ordering. friend bool operator>=(const basic_endpoint<Protocol>& e1, const basic_endpoint<Protocol>& e2) { return !(e1 < e2); } private: // The underlying UNIX domain endpoint. boost::asio::local::detail::endpoint impl_; }; /// Output an endpoint as a string. /** * Used to output a human-readable string for a specified endpoint. * * @param os The output stream to which the string will be written. * * @param endpoint The endpoint to be written. * * @return The output stream. * * @relates boost::asio::local::basic_endpoint */ template <typename Elem, typename Traits, typename Protocol> std::basic_ostream<Elem, Traits>& operator<<( std::basic_ostream<Elem, Traits>& os, const basic_endpoint<Protocol>& endpoint) { os << endpoint.path(); return os; } } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/datagram_protocol.hpp
// // local/datagram_protocol.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP #define BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/basic_datagram_socket.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/local/basic_endpoint.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { /// Encapsulates the flags needed for datagram-oriented UNIX sockets. /** * The boost::asio::local::datagram_protocol class contains flags necessary for * datagram-oriented UNIX domain sockets. * * @par Thread Safety * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Safe. * * @par Concepts: * Protocol. */ class datagram_protocol { public: /// Obtain an identifier for the type of the protocol. int type() const noexcept { return SOCK_DGRAM; } /// Obtain an identifier for the protocol. int protocol() const noexcept { return 0; } /// Obtain an identifier for the protocol family. int family() const noexcept { return AF_UNIX; } /// The type of a UNIX domain endpoint. typedef basic_endpoint<datagram_protocol> endpoint; /// The UNIX domain socket type. typedef basic_datagram_socket<datagram_protocol> socket; }; } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/connect_pair.hpp
// // local/connect_pair.hpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP #define BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include <boost/asio/basic_socket.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/error.hpp> #include <boost/asio/local/basic_endpoint.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { /// Create a pair of connected sockets. template <typename Protocol, typename Executor1, typename Executor2> void connect_pair(basic_socket<Protocol, Executor1>& socket1, basic_socket<Protocol, Executor2>& socket2); /// Create a pair of connected sockets. template <typename Protocol, typename Executor1, typename Executor2> BOOST_ASIO_SYNC_OP_VOID connect_pair(basic_socket<Protocol, Executor1>& socket1, basic_socket<Protocol, Executor2>& socket2, boost::system::error_code& ec); template <typename Protocol, typename Executor1, typename Executor2> inline void connect_pair(basic_socket<Protocol, Executor1>& socket1, basic_socket<Protocol, Executor2>& socket2) { boost::system::error_code ec; connect_pair(socket1, socket2, ec); boost::asio::detail::throw_error(ec, "connect_pair"); } template <typename Protocol, typename Executor1, typename Executor2> inline BOOST_ASIO_SYNC_OP_VOID connect_pair( basic_socket<Protocol, Executor1>& socket1, basic_socket<Protocol, Executor2>& socket2, boost::system::error_code& ec) { // Check that this function is only being used with a UNIX domain socket. boost::asio::local::basic_endpoint<Protocol>* tmp = static_cast<typename Protocol::endpoint*>(0); (void)tmp; Protocol protocol; boost::asio::detail::socket_type sv[2]; if (boost::asio::detail::socket_ops::socketpair(protocol.family(), protocol.type(), protocol.protocol(), sv, ec) == boost::asio::detail::socket_error_retval) BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); socket1.assign(protocol, sv[0], ec); if (ec) { boost::system::error_code temp_ec; boost::asio::detail::socket_ops::state_type state[2] = { 0, 0 }; boost::asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec); boost::asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } socket2.assign(protocol, sv[1], ec); if (ec) { boost::system::error_code temp_ec; socket1.close(temp_ec); boost::asio::detail::socket_ops::state_type state = 0; boost::asio::detail::socket_ops::close(sv[1], state, true, temp_ec); BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); } } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP
hpp
asio
data/projects/asio/include/boost/asio/local/detail/endpoint.hpp
// // local/detail/endpoint.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Derived from a public domain implementation written by Daniel Casimiro. // // 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 BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP #define BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) #include <cstddef> #include <string> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/string_view.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace local { namespace detail { // Helper class for implementing a UNIX domain endpoint. class endpoint { public: // Default constructor. BOOST_ASIO_DECL endpoint(); // Construct an endpoint using the specified path name. BOOST_ASIO_DECL endpoint(const char* path_name); // Construct an endpoint using the specified path name. BOOST_ASIO_DECL endpoint(const std::string& path_name); #if defined(BOOST_ASIO_HAS_STRING_VIEW) // Construct an endpoint using the specified path name. BOOST_ASIO_DECL endpoint(string_view path_name); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) // Copy constructor. endpoint(const endpoint& other) : data_(other.data_), path_length_(other.path_length_) { } // Assign from another endpoint. endpoint& operator=(const endpoint& other) { data_ = other.data_; path_length_ = other.path_length_; return *this; } // Get the underlying endpoint in the native type. boost::asio::detail::socket_addr_type* data() { return &data_.base; } // Get the underlying endpoint in the native type. const boost::asio::detail::socket_addr_type* data() const { return &data_.base; } // Get the underlying size of the endpoint in the native type. std::size_t size() const { return path_length_ + offsetof(boost::asio::detail::sockaddr_un_type, sun_path); } // Set the underlying size of the endpoint in the native type. BOOST_ASIO_DECL void resize(std::size_t size); // Get the capacity of the endpoint in the native type. std::size_t capacity() const { return sizeof(boost::asio::detail::sockaddr_un_type); } // Get the path associated with the endpoint. BOOST_ASIO_DECL std::string path() const; // Set the path associated with the endpoint. BOOST_ASIO_DECL void path(const char* p); // Set the path associated with the endpoint. BOOST_ASIO_DECL void path(const std::string& p); // Compare two endpoints for equality. BOOST_ASIO_DECL friend bool operator==( const endpoint& e1, const endpoint& e2); // Compare endpoints for ordering. BOOST_ASIO_DECL friend bool operator<( const endpoint& e1, const endpoint& e2); private: // The underlying UNIX socket address. union data_union { boost::asio::detail::socket_addr_type base; boost::asio::detail::sockaddr_un_type local; } data_; // The length of the path associated with the endpoint. std::size_t path_length_; // Initialise with a specified path. BOOST_ASIO_DECL void init(const char* path, std::size_t path_length); }; } // namespace detail } // namespace local } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/local/detail/impl/endpoint.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/socket.hpp
// // ts/socket.hpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_SOCKET_HPP #define BOOST_ASIO_TS_SOCKET_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/socket_base.hpp> #include <boost/asio/basic_socket.hpp> #include <boost/asio/basic_datagram_socket.hpp> #include <boost/asio/basic_stream_socket.hpp> #include <boost/asio/basic_socket_acceptor.hpp> #include <boost/asio/basic_socket_streambuf.hpp> #include <boost/asio/basic_socket_iostream.hpp> #include <boost/asio/connect.hpp> #endif // BOOST_ASIO_TS_SOCKET_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/executor.hpp
// // ts/executor.hpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_EXECUTOR_HPP #define BOOST_ASIO_TS_EXECUTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/async_result.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/is_executor.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/bind_executor.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/system_executor.hpp> #include <boost/asio/executor.hpp> #include <boost/asio/any_io_executor.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/post.hpp> #include <boost/asio/defer.hpp> #include <boost/asio/strand.hpp> #include <boost/asio/packaged_task.hpp> #include <boost/asio/use_future.hpp> #endif // BOOST_ASIO_TS_EXECUTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/internet.hpp
// // ts/internet.hpp // ~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_INTERNET_HPP #define BOOST_ASIO_TS_INTERNET_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/ip/address.hpp> #include <boost/asio/ip/address_v4.hpp> #include <boost/asio/ip/address_v4_iterator.hpp> #include <boost/asio/ip/address_v4_range.hpp> #include <boost/asio/ip/address_v6.hpp> #include <boost/asio/ip/address_v6_iterator.hpp> #include <boost/asio/ip/address_v6_range.hpp> #include <boost/asio/ip/bad_address_cast.hpp> #include <boost/asio/ip/basic_endpoint.hpp> #include <boost/asio/ip/basic_resolver_query.hpp> #include <boost/asio/ip/basic_resolver_entry.hpp> #include <boost/asio/ip/basic_resolver_iterator.hpp> #include <boost/asio/ip/basic_resolver.hpp> #include <boost/asio/ip/host_name.hpp> #include <boost/asio/ip/network_v4.hpp> #include <boost/asio/ip/network_v6.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/udp.hpp> #include <boost/asio/ip/v6_only.hpp> #include <boost/asio/ip/unicast.hpp> #include <boost/asio/ip/multicast.hpp> #endif // BOOST_ASIO_TS_INTERNET_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/buffer.hpp
// // ts/buffer.hpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_BUFFER_HPP #define BOOST_ASIO_TS_BUFFER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/buffer.hpp> #include <boost/asio/completion_condition.hpp> #include <boost/asio/read.hpp> #include <boost/asio/write.hpp> #include <boost/asio/read_until.hpp> #endif // BOOST_ASIO_TS_BUFFER_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/net.hpp
// // ts/net.hpp // ~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_NET_HPP #define BOOST_ASIO_TS_NET_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/ts/netfwd.hpp> #include <boost/asio/ts/executor.hpp> #include <boost/asio/ts/io_context.hpp> #include <boost/asio/ts/timer.hpp> #include <boost/asio/ts/buffer.hpp> #include <boost/asio/ts/socket.hpp> #include <boost/asio/ts/internet.hpp> #endif // BOOST_ASIO_TS_NET_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/io_context.hpp
// // ts/io_context.hpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_IO_CONTEXT_HPP #define BOOST_ASIO_TS_IO_CONTEXT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/io_context.hpp> #endif // BOOST_ASIO_TS_IO_CONTEXT_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/timer.hpp
// // ts/timer.hpp // ~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_TIMER_HPP #define BOOST_ASIO_TS_TIMER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/chrono.hpp> #include <boost/asio/wait_traits.hpp> #include <boost/asio/basic_waitable_timer.hpp> #include <boost/asio/system_timer.hpp> #include <boost/asio/steady_timer.hpp> #include <boost/asio/high_resolution_timer.hpp> #endif // BOOST_ASIO_TS_TIMER_HPP
hpp
asio
data/projects/asio/include/boost/asio/ts/netfwd.hpp
// // ts/netfwd.hpp // ~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_TS_NETFWD_HPP #define BOOST_ASIO_TS_NETFWD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/chrono.hpp> #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # include <boost/asio/detail/date_time_fwd.hpp> #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) #if !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) #include <boost/asio/execution/blocking.hpp> #include <boost/asio/execution/outstanding_work.hpp> #include <boost/asio/execution/relationship.hpp> #endif // !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) #if !defined(GENERATING_DOCUMENTATION) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class execution_context; template <typename T, typename Executor> class executor_binder; #if !defined(BOOST_ASIO_EXECUTOR_WORK_GUARD_DECL) #define BOOST_ASIO_EXECUTOR_WORK_GUARD_DECL template <typename Executor, typename = void, typename = void> class executor_work_guard; #endif // !defined(BOOST_ASIO_EXECUTOR_WORK_GUARD_DECL) template <typename Blocking, typename Relationship, typename Allocator> class basic_system_executor; #if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) class executor; typedef executor any_io_executor; #else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) namespace execution { #if !defined(BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL) #define BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL template <typename... SupportableProperties> class any_executor; #endif // !defined(BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL) template <typename U> struct context_as_t; template <typename Property> struct prefer_only; } // namespace execution class any_io_executor; #endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) template <typename Executor> class strand; class io_context; template <typename Clock> struct wait_traits; #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) template <typename Time> struct time_traits; #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) #if !defined(BOOST_ASIO_BASIC_WAITABLE_TIMER_FWD_DECL) #define BOOST_ASIO_BASIC_WAITABLE_TIMER_FWD_DECL template <typename Clock, typename WaitTraits = wait_traits<Clock>, typename Executor = any_io_executor> class basic_waitable_timer; #endif // !defined(BOOST_ASIO_BASIC_WAITABLE_TIMER_FWD_DECL) typedef basic_waitable_timer<chrono::system_clock> system_timer; typedef basic_waitable_timer<chrono::steady_clock> steady_timer; typedef basic_waitable_timer<chrono::high_resolution_clock> high_resolution_timer; #if !defined(BOOST_ASIO_BASIC_SOCKET_FWD_DECL) #define BOOST_ASIO_BASIC_SOCKET_FWD_DECL template <typename Protocol, typename Executor = any_io_executor> class basic_socket; #endif // !defined(BOOST_ASIO_BASIC_SOCKET_FWD_DECL) #if !defined(BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) #define BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL template <typename Protocol, typename Executor = any_io_executor> class basic_datagram_socket; #endif // !defined(BOOST_ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) #if !defined(BOOST_ASIO_BASIC_STREAM_SOCKET_FWD_DECL) #define BOOST_ASIO_BASIC_STREAM_SOCKET_FWD_DECL // Forward declaration with defaulted arguments. template <typename Protocol, typename Executor = any_io_executor> class basic_stream_socket; #endif // !defined(BOOST_ASIO_BASIC_STREAM_SOCKET_FWD_DECL) #if !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL) #define BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL template <typename Protocol, typename Executor = any_io_executor> class basic_socket_acceptor; #endif // !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL) #if !defined(BOOST_ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL) #define BOOST_ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL // Forward declaration with defaulted arguments. template <typename Protocol, #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \ || defined(GENERATING_DOCUMENTATION) typename Clock = boost::posix_time::ptime, typename WaitTraits = time_traits<Clock>> #else typename Clock = chrono::steady_clock, typename WaitTraits = wait_traits<Clock>> #endif class basic_socket_streambuf; #endif // !defined(BOOST_ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL) #if !defined(BOOST_ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL) #define BOOST_ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL // Forward declaration with defaulted arguments. template <typename Protocol, #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \ || defined(GENERATING_DOCUMENTATION) typename Clock = boost::posix_time::ptime, typename WaitTraits = time_traits<Clock>> #else typename Clock = chrono::steady_clock, typename WaitTraits = wait_traits<Clock>> #endif class basic_socket_iostream; #endif // !defined(BOOST_ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL) namespace ip { class address; class address_v4; class address_v6; template <typename Address> class basic_address_iterator; typedef basic_address_iterator<address_v4> address_v4_iterator; typedef basic_address_iterator<address_v6> address_v6_iterator; template <typename Address> class basic_address_range; typedef basic_address_range<address_v4> address_v4_range; typedef basic_address_range<address_v6> address_v6_range; class network_v4; class network_v6; template <typename InternetProtocol> class basic_endpoint; template <typename InternetProtocol> class basic_resolver_entry; template <typename InternetProtocol> class basic_resolver_results; #if !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL) #define BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL template <typename InternetProtocol, typename Executor = any_io_executor> class basic_resolver; #endif // !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL) class tcp; class udp; } // namespace ip } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_TS_NETFWD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_descriptor_service.hpp
// // detail/reactive_descriptor_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_REACTIVE_DESCRIPTOR_SERVICE_HPP #define BOOST_ASIO_DETAIL_REACTIVE_DESCRIPTOR_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) \ && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/associated_immediate_executor.hpp> #include <boost/asio/buffer.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/descriptor_ops.hpp> #include <boost/asio/detail/descriptor_read_op.hpp> #include <boost/asio/detail/descriptor_write_op.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/reactive_null_buffers_op.hpp> #include <boost/asio/detail/reactive_wait_op.hpp> #include <boost/asio/detail/reactor.hpp> #include <boost/asio/posix/descriptor_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class reactive_descriptor_service : public execution_context_service_base<reactive_descriptor_service> { public: // The native type of a descriptor. typedef int native_handle_type; // The implementation type of the descriptor. class implementation_type : private boost::asio::detail::noncopyable { public: // Default constructor. implementation_type() : descriptor_(-1), state_(0) { } private: // Only this service will have access to the internal values. friend class reactive_descriptor_service; // The native descriptor representation. int descriptor_; // The current state of the descriptor. descriptor_ops::state_type state_; // Per-descriptor data used by the reactor. reactor::per_descriptor_data reactor_data_; }; // Constructor. BOOST_ASIO_DECL reactive_descriptor_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new descriptor implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Move-construct a new descriptor implementation. BOOST_ASIO_DECL void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept; // Move-assign from another descriptor implementation. BOOST_ASIO_DECL void move_assign(implementation_type& impl, reactive_descriptor_service& other_service, implementation_type& other_impl); // Destroy a descriptor implementation. BOOST_ASIO_DECL void destroy(implementation_type& impl); // Assign a native descriptor to a descriptor implementation. BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl, const native_handle_type& native_descriptor, boost::system::error_code& ec); // Determine whether the descriptor is open. bool is_open(const implementation_type& impl) const { return impl.descriptor_ != -1; } // Destroy a descriptor implementation. BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec); // Get the native descriptor representation. native_handle_type native_handle(const implementation_type& impl) const { return impl.descriptor_; } // Release ownership of the native descriptor representation. BOOST_ASIO_DECL native_handle_type release(implementation_type& impl); // Release ownership of the native descriptor representation. native_handle_type release(implementation_type& impl, boost::system::error_code& ec) { ec = success_ec_; return release(impl); } // Cancel all operations associated with the descriptor. BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec); // Perform an IO control command on the descriptor. template <typename IO_Control_Command> boost::system::error_code io_control(implementation_type& impl, IO_Control_Command& command, boost::system::error_code& ec) { descriptor_ops::ioctl(impl.descriptor_, impl.state_, command.name(), static_cast<ioctl_arg_type*>(command.data()), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Gets the non-blocking mode of the descriptor. bool non_blocking(const implementation_type& impl) const { return (impl.state_ & descriptor_ops::user_set_non_blocking) != 0; } // Sets the non-blocking mode of the descriptor. boost::system::error_code non_blocking(implementation_type& impl, bool mode, boost::system::error_code& ec) { descriptor_ops::set_user_non_blocking( impl.descriptor_, impl.state_, mode, ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Gets the non-blocking mode of the native descriptor implementation. bool native_non_blocking(const implementation_type& impl) const { return (impl.state_ & descriptor_ops::internal_non_blocking) != 0; } // Sets the non-blocking mode of the native descriptor implementation. boost::system::error_code native_non_blocking(implementation_type& impl, bool mode, boost::system::error_code& ec) { descriptor_ops::set_internal_non_blocking( impl.descriptor_, impl.state_, mode, ec); return ec; } // Wait for the descriptor to become ready to read, ready to write, or to have // pending error conditions. boost::system::error_code wait(implementation_type& impl, posix::descriptor_base::wait_type w, boost::system::error_code& ec) { switch (w) { case posix::descriptor_base::wait_read: descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec); break; case posix::descriptor_base::wait_write: descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec); break; case posix::descriptor_base::wait_error: descriptor_ops::poll_error(impl.descriptor_, impl.state_, ec); break; default: ec = boost::asio::error::invalid_argument; break; } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Asynchronously wait for the descriptor to become ready to read, ready to // write, or to have pending error conditions. template <typename Handler, typename IoExecutor> void async_wait(implementation_type& impl, posix::descriptor_base::wait_type w, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_wait_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_wait")); int op_type; switch (w) { case posix::descriptor_base::wait_read: op_type = reactor::read_op; break; case posix::descriptor_base::wait_write: op_type = reactor::write_op; break; case posix::descriptor_base::wait_error: op_type = reactor::except_op; break; default: p.p->ec_ = boost::asio::error::invalid_argument; start_op(impl, reactor::read_op, p.p, is_continuation, false, true, &io_ex, 0); p.v = p.p = 0; return; } // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.descriptor_, op_type); } start_op(impl, op_type, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } // Write some data to the descriptor. template <typename ConstBufferSequence> size_t write_some(implementation_type& impl, const ConstBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = descriptor_ops::sync_write1(impl.descriptor_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); n = descriptor_ops::sync_write(impl.descriptor_, impl.state_, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be written without blocking. size_t write_some(implementation_type& impl, const null_buffers&, boost::system::error_code& ec) { // Wait for descriptor to become ready. descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous write. The data being sent must be valid for the // lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef descriptor_write_op<ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.descriptor_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_write_some")); start_op(impl, reactor::write_op, p.p, is_continuation, true, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::all_empty(buffers), &io_ex, 0); p.v = p.p = 0; } // Start an asynchronous wait until data can be written without blocking. template <typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const null_buffers&, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.descriptor_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_write_some(null_buffers)")); start_op(impl, reactor::write_op, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } // Read some data from the stream. Returns the number of bytes read. template <typename MutableBufferSequence> size_t read_some(implementation_type& impl, const MutableBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = descriptor_ops::sync_read1(impl.descriptor_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); n = descriptor_ops::sync_read(impl.descriptor_, impl.state_, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be read without blocking. size_t read_some(implementation_type& impl, const null_buffers&, boost::system::error_code& ec) { // Wait for descriptor to become ready. descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous read. The buffer for the data being read must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef descriptor_read_op<MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.descriptor_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_read_some")); start_op(impl, reactor::read_op, p.p, is_continuation, true, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(buffers), &io_ex, 0); p.v = p.p = 0; } // Wait until data can be read without blocking. template <typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const null_buffers&, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.descriptor_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_read_some(null_buffers)")); start_op(impl, reactor::read_op, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } private: // Start the asynchronous operation. BOOST_ASIO_DECL void do_start_op(implementation_type& impl, int op_type, reactor_op* op, bool is_continuation, bool is_non_blocking, bool noop, void (*on_immediate)(operation* op, bool, const void*), const void* immediate_arg); // Start the asynchronous operation for handlers that are specialised for // immediate completion. template <typename Op> void start_op(implementation_type& impl, int op_type, Op* op, bool is_continuation, bool is_non_blocking, bool noop, const void* io_ex, ...) { return do_start_op(impl, op_type, op, is_continuation, is_non_blocking, noop, &Op::do_immediate, io_ex); } // Start the asynchronous operation for handlers that are not specialised for // immediate completion. template <typename Op> void start_op(implementation_type& impl, int op_type, Op* op, bool is_continuation, bool is_non_blocking, bool noop, const void*, enable_if_t< is_same< typename associated_immediate_executor< typename Op::handler_type, typename Op::io_executor_type >::asio_associated_immediate_executor_is_unspecialised, void >::value >*) { return do_start_op(impl, op_type, op, is_continuation, is_non_blocking, noop, &reactor::call_post_immediate_completion, &reactor_); } // Helper class used to implement per-operation cancellation class reactor_op_cancellation { public: reactor_op_cancellation(reactor* r, reactor::per_descriptor_data* p, int d, int o) : reactor_(r), reactor_data_(p), descriptor_(d), op_type_(o) { } void operator()(cancellation_type_t type) { if (!!(type & (cancellation_type::terminal | cancellation_type::partial | cancellation_type::total))) { reactor_->cancel_ops_by_key(descriptor_, *reactor_data_, op_type_, this); } } private: reactor* reactor_; reactor::per_descriptor_data* reactor_data_; int descriptor_; int op_type_; }; // The selector that performs event demultiplexing for the service. reactor& reactor_; // Cached success value to avoid accessing category singleton. const boost::system::error_code success_ec_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/reactive_descriptor_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) // && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // BOOST_ASIO_DETAIL_REACTIVE_DESCRIPTOR_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_recv_op.hpp
// // detail/win_iocp_socket_recv_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECV_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECV_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class win_iocp_socket_recv_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recv_op); win_iocp_socket_recv_op(socket_ops::state_type state, socket_ops::weak_cancel_token_type cancel_token, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_socket_recv_op::do_complete), state_(state), cancel_token_(cancel_token), buffers_(buffers), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& result_ec, std::size_t bytes_transferred) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_socket_recv_op* o(static_cast<win_iocp_socket_recv_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Check whether buffers are still valid. if (owner) { buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) socket_ops::complete_iocp_recv(o->state_, o->cancel_token_, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(o->buffers_), ec, bytes_transferred); BOOST_ASIO_ERROR_LOCATION(ec); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, ec, bytes_transferred); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: socket_ops::state_type state_; socket_ops::weak_cancel_token_type cancel_token_; MutableBufferSequence buffers_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECV_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/std_mutex.hpp
// // detail/std_mutex.hpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_STD_MUTEX_HPP #define BOOST_ASIO_DETAIL_STD_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <mutex> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class std_event; class std_mutex : private noncopyable { public: typedef boost::asio::detail::scoped_lock<std_mutex> scoped_lock; // Constructor. std_mutex() { } // Destructor. ~std_mutex() { } // Lock the mutex. void lock() { mutex_.lock(); } // Unlock the mutex. void unlock() { mutex_.unlock(); } private: friend class std_event; std::mutex mutex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_socket_connect_op.hpp
// // detail/winrt_socket_connect_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP #define BOOST_ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/winrt_async_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class winrt_socket_connect_op : public winrt_async_op<void> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_socket_connect_op); winrt_socket_connect_op(Handler& handler, const IoExecutor& io_ex) : winrt_async_op<void>(&winrt_socket_connect_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code&, std::size_t) { // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); winrt_socket_connect_op* o(static_cast<winrt_socket_connect_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder1<Handler, boost::system::error_code> handler(o->handler_, o->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> executor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/is_buffer_sequence.hpp
// // detail/is_buffer_sequence.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP #define BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class mutable_buffer; class const_buffer; class mutable_registered_buffer; class const_registered_buffer; namespace detail { struct buffer_sequence_memfns_base { void begin(); void end(); void size(); void max_size(); void capacity(); void data(); void prepare(); void commit(); void consume(); void grow(); void shrink(); }; template <typename T> struct buffer_sequence_memfns_derived : T, buffer_sequence_memfns_base { }; template <typename T, T> struct buffer_sequence_memfns_check { }; template <typename> char buffer_sequence_begin_helper(...); template <typename T> char (&buffer_sequence_begin_helper(T* t, enable_if_t<!is_same< decltype(boost::asio::buffer_sequence_begin(*t)), void>::value>*))[2]; template <typename> char buffer_sequence_end_helper(...); template <typename T> char (&buffer_sequence_end_helper(T* t, enable_if_t<!is_same< decltype(boost::asio::buffer_sequence_end(*t)), void>::value>*))[2]; template <typename> char (&size_memfn_helper(...))[2]; template <typename T> char size_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::size>*); template <typename> char (&max_size_memfn_helper(...))[2]; template <typename T> char max_size_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::max_size>*); template <typename> char (&capacity_memfn_helper(...))[2]; template <typename T> char capacity_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::capacity>*); template <typename> char (&data_memfn_helper(...))[2]; template <typename T> char data_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::data>*); template <typename> char (&prepare_memfn_helper(...))[2]; template <typename T> char prepare_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::prepare>*); template <typename> char (&commit_memfn_helper(...))[2]; template <typename T> char commit_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::commit>*); template <typename> char (&consume_memfn_helper(...))[2]; template <typename T> char consume_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::consume>*); template <typename> char (&grow_memfn_helper(...))[2]; template <typename T> char grow_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::grow>*); template <typename> char (&shrink_memfn_helper(...))[2]; template <typename T> char shrink_memfn_helper( buffer_sequence_memfns_check< void (buffer_sequence_memfns_base::*)(), &buffer_sequence_memfns_derived<T>::shrink>*); template <typename, typename> char (&buffer_sequence_element_type_helper(...))[2]; template <typename T, typename Buffer> char buffer_sequence_element_type_helper(T* t, enable_if_t<is_convertible< decltype(*boost::asio::buffer_sequence_begin(*t)), Buffer>::value>*); template <typename> char (&const_buffers_type_typedef_helper(...))[2]; template <typename T> char const_buffers_type_typedef_helper( typename T::const_buffers_type*); template <typename> char (&mutable_buffers_type_typedef_helper(...))[2]; template <typename T> char mutable_buffers_type_typedef_helper( typename T::mutable_buffers_type*); template <typename T, typename Buffer> struct is_buffer_sequence_class : integral_constant<bool, sizeof(buffer_sequence_begin_helper<T>(0, 0)) != 1 && sizeof(buffer_sequence_end_helper<T>(0, 0)) != 1 && sizeof(buffer_sequence_element_type_helper<T, Buffer>(0, 0)) == 1> { }; template <typename T, typename Buffer> struct is_buffer_sequence : conditional<is_class<T>::value, is_buffer_sequence_class<T, Buffer>, false_type>::type { }; template <> struct is_buffer_sequence<mutable_buffer, mutable_buffer> : true_type { }; template <> struct is_buffer_sequence<mutable_buffer, const_buffer> : true_type { }; template <> struct is_buffer_sequence<const_buffer, const_buffer> : true_type { }; template <> struct is_buffer_sequence<const_buffer, mutable_buffer> : false_type { }; template <> struct is_buffer_sequence<mutable_registered_buffer, mutable_buffer> : true_type { }; template <> struct is_buffer_sequence<mutable_registered_buffer, const_buffer> : true_type { }; template <> struct is_buffer_sequence<const_registered_buffer, const_buffer> : true_type { }; template <> struct is_buffer_sequence<const_registered_buffer, mutable_buffer> : false_type { }; template <typename T> struct is_dynamic_buffer_class_v1 : integral_constant<bool, sizeof(size_memfn_helper<T>(0)) != 1 && sizeof(max_size_memfn_helper<T>(0)) != 1 && sizeof(capacity_memfn_helper<T>(0)) != 1 && sizeof(data_memfn_helper<T>(0)) != 1 && sizeof(consume_memfn_helper<T>(0)) != 1 && sizeof(prepare_memfn_helper<T>(0)) != 1 && sizeof(commit_memfn_helper<T>(0)) != 1 && sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 && sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1> { }; template <typename T> struct is_dynamic_buffer_v1 : conditional<is_class<T>::value, is_dynamic_buffer_class_v1<T>, false_type>::type { }; template <typename T> struct is_dynamic_buffer_class_v2 : integral_constant<bool, sizeof(size_memfn_helper<T>(0)) != 1 && sizeof(max_size_memfn_helper<T>(0)) != 1 && sizeof(capacity_memfn_helper<T>(0)) != 1 && sizeof(data_memfn_helper<T>(0)) != 1 && sizeof(consume_memfn_helper<T>(0)) != 1 && sizeof(grow_memfn_helper<T>(0)) != 1 && sizeof(shrink_memfn_helper<T>(0)) != 1 && sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 && sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1> { }; template <typename T> struct is_dynamic_buffer_v2 : conditional<is_class<T>::value, is_dynamic_buffer_class_v2<T>, false_type>::type { }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/functional.hpp
// // detail/functional.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_FUNCTIONAL_HPP #define BOOST_ASIO_DETAIL_FUNCTIONAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <functional> namespace boost { namespace asio { namespace detail { using std::function; } // namespace detail using std::ref; using std::reference_wrapper; } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_FUNCTIONAL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_signal_blocker.hpp
// // detail/null_signal_blocker.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_NULL_SIGNAL_BLOCKER_HPP #define BOOST_ASIO_DETAIL_NULL_SIGNAL_BLOCKER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) \ || defined(BOOST_ASIO_WINDOWS) \ || defined(BOOST_ASIO_WINDOWS_RUNTIME) \ || defined(__CYGWIN__) \ || defined(__SYMBIAN32__) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class null_signal_blocker : private noncopyable { public: // Constructor blocks all signals for the calling thread. null_signal_blocker() { } // Destructor restores the previous signal mask. ~null_signal_blocker() { } // Block all signals for the calling thread. void block() { } // Restore the previous signal mask. void unblock() { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_HAS_THREADS) // || defined(BOOST_ASIO_WINDOWS) // || defined(BOOST_ASIO_WINDOWS_RUNTIME) // || defined(__CYGWIN__) // || defined(__SYMBIAN32__) #endif // BOOST_ASIO_DETAIL_NULL_SIGNAL_BLOCKER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_global.hpp
// // detail/posix_global.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_POSIX_GLOBAL_HPP #define BOOST_ASIO_DETAIL_POSIX_GLOBAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <exception> #include <pthread.h> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> struct posix_global_impl { // Helper function to perform initialisation. static void do_init() { instance_.static_ptr_ = instance_.ptr_ = new T; } // Destructor automatically cleans up the global. ~posix_global_impl() { delete static_ptr_; } static ::pthread_once_t init_once_; static T* static_ptr_; static posix_global_impl instance_; T* ptr_; }; template <typename T> ::pthread_once_t posix_global_impl<T>::init_once_ = PTHREAD_ONCE_INIT; template <typename T> T* posix_global_impl<T>::static_ptr_ = 0; template <typename T> posix_global_impl<T> posix_global_impl<T>::instance_; template <typename T> T& posix_global() { int result = ::pthread_once( &posix_global_impl<T>::init_once_, &posix_global_impl<T>::do_init); if (result != 0) std::terminate(); return *posix_global_impl<T>::instance_.ptr_; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_GLOBAL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/regex_fwd.hpp
// // detail/regex_fwd.hpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_REGEX_FWD_HPP #define BOOST_ASIO_DETAIL_REGEX_FWD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #if defined(BOOST_ASIO_HAS_BOOST_REGEX) namespace boost { template <class BidiIterator> struct sub_match; template <class BidiIterator, class Allocator> class match_results; template <class CharT, class Traits> class basic_regex; } // namespace boost #endif // defined(BOOST_ASIO_HAS_BOOST_REGEX) #endif // BOOST_ASIO_DETAIL_REGEX_FWD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/timer_scheduler_fwd.hpp
// // detail/timer_scheduler_fwd.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP #define BOOST_ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_WINDOWS_RUNTIME) typedef class winrt_timer_scheduler timer_scheduler; #elif defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context timer_scheduler; #elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) typedef class io_uring_service timer_scheduler; #elif defined(BOOST_ASIO_HAS_EPOLL) typedef class epoll_reactor timer_scheduler; #elif defined(BOOST_ASIO_HAS_KQUEUE) typedef class kqueue_reactor timer_scheduler; #elif defined(BOOST_ASIO_HAS_DEV_POLL) typedef class dev_poll_reactor timer_scheduler; #else typedef class select_reactor timer_scheduler; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/strand_executor_service.hpp
// // detail/strand_executor_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP #define BOOST_ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/executor_op.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/scheduler_operation.hpp> #include <boost/asio/detail/scoped_ptr.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Default service implementation for a strand. class strand_executor_service : public execution_context_service_base<strand_executor_service> { public: // The underlying implementation of a strand. class strand_impl { public: BOOST_ASIO_DECL ~strand_impl(); private: friend class strand_executor_service; // Mutex to protect access to internal data. mutex* mutex_; // Indicates whether the strand is currently "locked" by a handler. This // means that there is a handler upcall in progress, or that the strand // itself has been scheduled in order to invoke some pending handlers. bool locked_; // Indicates that the strand has been shut down and will accept no further // handlers. bool shutdown_; // The handlers that are waiting on the strand but should not be run until // after the next time the strand is scheduled. This queue must only be // modified while the mutex is locked. op_queue<scheduler_operation> waiting_queue_; // The handlers that are ready to be run. Logically speaking, these are the // handlers that hold the strand's lock. The ready queue is only modified // from within the strand and so may be accessed without locking the mutex. op_queue<scheduler_operation> ready_queue_; // Pointers to adjacent handle implementations in linked list. strand_impl* next_; strand_impl* prev_; // The strand service in where the implementation is held. strand_executor_service* service_; }; typedef shared_ptr<strand_impl> implementation_type; // Construct a new strand service for the specified context. BOOST_ASIO_DECL explicit strand_executor_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Create a new strand_executor implementation. BOOST_ASIO_DECL implementation_type create_implementation(); // Request invocation of the given function. template <typename Executor, typename Function> static void execute(const implementation_type& impl, Executor& ex, Function&& function, enable_if_t< can_query<Executor, execution::allocator_t<void>>::value >* = 0); // Request invocation of the given function. template <typename Executor, typename Function> static void execute(const implementation_type& impl, Executor& ex, Function&& function, enable_if_t< !can_query<Executor, execution::allocator_t<void>>::value >* = 0); // Request invocation of the given function. template <typename Executor, typename Function, typename Allocator> static void dispatch(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a); // Request invocation of the given function and return immediately. template <typename Executor, typename Function, typename Allocator> static void post(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a); // Request invocation of the given function and return immediately. template <typename Executor, typename Function, typename Allocator> static void defer(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a); // Determine whether the strand is running in the current thread. BOOST_ASIO_DECL static bool running_in_this_thread( const implementation_type& impl); private: friend class strand_impl; template <typename F, typename Allocator> class allocator_binder; template <typename Executor, typename = void> class invoker; // Adds a function to the strand. Returns true if it acquires the lock. BOOST_ASIO_DECL static bool enqueue(const implementation_type& impl, scheduler_operation* op); // Transfers waiting handlers to the ready queue. Returns true if one or more // handlers were transferred. BOOST_ASIO_DECL static bool push_waiting_to_ready(implementation_type& impl); // Invokes all ready-to-run handlers. BOOST_ASIO_DECL static void run_ready_handlers(implementation_type& impl); // Helper function to request invocation of the given function. template <typename Executor, typename Function, typename Allocator> static void do_execute(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a); // Mutex to protect access to the service-wide state. mutex mutex_; // Number of mutexes shared between all strand objects. enum { num_mutexes = 193 }; // Pool of mutexes. scoped_ptr<mutex> mutexes_[num_mutexes]; // Extra value used when hashing to prevent recycled memory locations from // getting the same mutex. std::size_t salt_; // The head of a linked list of all implementations. strand_impl* impl_list_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/strand_executor_service.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/strand_executor_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_static_mutex.hpp
// // detail/posix_static_mutex.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_POSIX_STATIC_MUTEX_HPP #define BOOST_ASIO_DETAIL_POSIX_STATIC_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <pthread.h> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct posix_static_mutex { typedef boost::asio::detail::scoped_lock<posix_static_mutex> scoped_lock; // Initialise the mutex. void init() { // Nothing to do. } // Lock the mutex. void lock() { (void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL. } // Unlock the mutex. void unlock() { (void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL. } ::pthread_mutex_t mutex_; }; #define BOOST_ASIO_POSIX_STATIC_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_STATIC_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/select_interrupter.hpp
// // detail/select_interrupter.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_SELECT_INTERRUPTER_HPP #define BOOST_ASIO_DETAIL_SELECT_INTERRUPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) || defined(__SYMBIAN32__) # include <boost/asio/detail/socket_select_interrupter.hpp> #elif defined(BOOST_ASIO_HAS_EVENTFD) # include <boost/asio/detail/eventfd_select_interrupter.hpp> #else # include <boost/asio/detail/pipe_select_interrupter.hpp> #endif namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) || defined(__SYMBIAN32__) typedef socket_select_interrupter select_interrupter; #elif defined(BOOST_ASIO_HAS_EVENTFD) typedef eventfd_select_interrupter select_interrupter; #else typedef pipe_select_interrupter select_interrupter; #endif } // namespace detail } // namespace asio } // namespace boost #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_SELECT_INTERRUPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/scoped_lock.hpp
// // detail/scoped_lock.hpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_SCOPED_LOCK_HPP #define BOOST_ASIO_DETAIL_SCOPED_LOCK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Helper class to lock and unlock a mutex automatically. template <typename Mutex> class scoped_lock : private noncopyable { public: // Tag type used to distinguish constructors. enum adopt_lock_t { adopt_lock }; // Constructor adopts a lock that is already held. scoped_lock(Mutex& m, adopt_lock_t) : mutex_(m), locked_(true) { } // Constructor acquires the lock. explicit scoped_lock(Mutex& m) : mutex_(m) { mutex_.lock(); locked_ = true; } // Destructor releases the lock. ~scoped_lock() { if (locked_) mutex_.unlock(); } // Explicitly acquire the lock. void lock() { if (!locked_) { mutex_.lock(); locked_ = true; } } // Explicitly release the lock. void unlock() { if (locked_) { mutex_.unlock(); locked_ = false; } } // Test whether the lock is held. bool locked() const { return locked_; } // Get the underlying mutex. Mutex& mutex() { return mutex_; } private: // The underlying mutex. Mutex& mutex_; // Whether the mutex is currently locked or unlocked. bool locked_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SCOPED_LOCK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_sendto_op.hpp
// // detail/reactive_socket_sendto_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename ConstBufferSequence, typename Endpoint> class reactive_socket_sendto_op_base : public reactor_op { public: reactive_socket_sendto_op_base(const boost::system::error_code& success_ec, socket_type socket, const ConstBufferSequence& buffers, const Endpoint& endpoint, socket_base::message_flags flags, func_type complete_func) : reactor_op(success_ec, &reactive_socket_sendto_op_base::do_perform, complete_func), socket_(socket), buffers_(buffers), destination_(endpoint), flags_(flags) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_sendto_op_base* o( static_cast<reactive_socket_sendto_op_base*>(base)); typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; status result; if (bufs_type::is_single_buffer) { result = socket_ops::non_blocking_sendto1(o->socket_, bufs_type::first(o->buffers_).data(), bufs_type::first(o->buffers_).size(), o->flags_, o->destination_.data(), o->destination_.size(), o->ec_, o->bytes_transferred_) ? done : not_done; } else { bufs_type bufs(o->buffers_); result = socket_ops::non_blocking_sendto(o->socket_, bufs.buffers(), bufs.count(), o->flags_, o->destination_.data(), o->destination_.size(), o->ec_, o->bytes_transferred_) ? done : not_done; } BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_sendto", o->ec_, o->bytes_transferred_)); return result; } private: socket_type socket_; ConstBufferSequence buffers_; Endpoint destination_; socket_base::message_flags flags_; }; template <typename ConstBufferSequence, typename Endpoint, typename Handler, typename IoExecutor> class reactive_socket_sendto_op : public reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_sendto_op); reactive_socket_sendto_op(const boost::system::error_code& success_ec, socket_type socket, const ConstBufferSequence& buffers, const Endpoint& endpoint, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint>( success_ec, socket, buffers, endpoint, flags, &reactive_socket_sendto_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_sendto_op* o(static_cast<reactive_socket_sendto_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); BOOST_ASIO_ERROR_LOCATION(o->ec_); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_sendto_op* o(static_cast<reactive_socket_sendto_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. immediate_handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); BOOST_ASIO_ERROR_LOCATION(o->ec_); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_, io_ex); BOOST_ASIO_HANDLER_INVOCATION_END; } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_mutex.hpp
// // detail/null_mutex.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_NULL_MUTEX_HPP #define BOOST_ASIO_DETAIL_NULL_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class null_mutex : private noncopyable { public: typedef boost::asio::detail::scoped_lock<null_mutex> scoped_lock; // Constructor. null_mutex() { } // Destructor. ~null_mutex() { } // Lock the mutex. void lock() { } // Unlock the mutex. void unlock() { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_NULL_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/scheduler_thread_info.hpp
// // detail/scheduler_thread_info.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP #define BOOST_ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/thread_info_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class scheduler; class scheduler_operation; struct scheduler_thread_info : public thread_info_base { op_queue<scheduler_operation> private_op_queue; long private_outstanding_work; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_object_handle_service.hpp
// // detail/win_object_handle_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2011 Boris Schaeling ([email protected]) // // 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 BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP #define BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/wait_handler.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #else // defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/scheduler.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class win_object_handle_service : public execution_context_service_base<win_object_handle_service> { public: // The native type of an object handle. typedef HANDLE native_handle_type; // The implementation type of the object handle. class implementation_type { public: // Default constructor. implementation_type() : handle_(INVALID_HANDLE_VALUE), wait_handle_(INVALID_HANDLE_VALUE), owner_(0), next_(0), prev_(0) { } private: // Only this service will have access to the internal values. friend class win_object_handle_service; // The native object handle representation. May be accessed or modified // without locking the mutex. native_handle_type handle_; // The handle used to unregister the wait operation. The mutex must be // locked when accessing or modifying this member. HANDLE wait_handle_; // The operations waiting on the object handle. If there is a registered // wait then the mutex must be locked when accessing or modifying this // member op_queue<wait_op> op_queue_; // The service instance that owns the object handle implementation. win_object_handle_service* owner_; // Pointers to adjacent handle implementations in linked list. The mutex // must be locked when accessing or modifying these members. implementation_type* next_; implementation_type* prev_; }; // Constructor. BOOST_ASIO_DECL win_object_handle_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new handle implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Move-construct a new handle implementation. BOOST_ASIO_DECL void move_construct(implementation_type& impl, implementation_type& other_impl); // Move-assign from another handle implementation. BOOST_ASIO_DECL void move_assign(implementation_type& impl, win_object_handle_service& other_service, implementation_type& other_impl); // Destroy a handle implementation. BOOST_ASIO_DECL void destroy(implementation_type& impl); // Assign a native handle to a handle implementation. BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl, const native_handle_type& handle, boost::system::error_code& ec); // Determine whether the handle is open. bool is_open(const implementation_type& impl) const { return impl.handle_ != INVALID_HANDLE_VALUE && impl.handle_ != 0; } // Destroy a handle implementation. BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec); // Get the native handle representation. native_handle_type native_handle(const implementation_type& impl) const { return impl.handle_; } // Cancel all operations associated with the handle. BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec); // Perform a synchronous wait for the object to enter a signalled state. BOOST_ASIO_DECL void wait(implementation_type& impl, boost::system::error_code& ec); /// Start an asynchronous wait. template <typename Handler, typename IoExecutor> void async_wait(implementation_type& impl, Handler& handler, const IoExecutor& io_ex) { // Allocate and construct an operation to wrap the handler. typedef wait_handler<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(handler, io_ex); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "object_handle", &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "async_wait")); start_wait_op(impl, p.p); p.v = p.p = 0; } private: // Helper function to start an asynchronous wait operation. BOOST_ASIO_DECL void start_wait_op(implementation_type& impl, wait_op* op); // Helper function to register a wait operation. BOOST_ASIO_DECL void register_wait_callback( implementation_type& impl, mutex::scoped_lock& lock); // Callback function invoked when the registered wait completes. static BOOST_ASIO_DECL VOID CALLBACK wait_callback( PVOID param, BOOLEAN timeout); // The scheduler used to post completions. #if defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_impl; #else typedef class scheduler scheduler_impl; #endif scheduler_impl& scheduler_; // Mutex to protect access to internal state. mutex mutex_; // The head of a linked list of all implementations. implementation_type* impl_list_; // Flag to indicate that the dispatcher has been shut down. bool shutdown_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_object_handle_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) #endif // BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/array.hpp
// // detail/array.hpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_ARRAY_HPP #define BOOST_ASIO_DETAIL_ARRAY_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <array> namespace boost { namespace asio { namespace detail { using std::array; } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_ARRAY_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/config.hpp
// // detail/config.hpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_CONFIG_HPP #define BOOST_ASIO_DETAIL_CONFIG_HPP #if defined(BOOST_ASIO_STANDALONE) # define BOOST_ASIO_DISABLE_BOOST_ALIGN 1 # define BOOST_ASIO_DISABLE_BOOST_ARRAY 1 # define BOOST_ASIO_DISABLE_BOOST_ASSERT 1 # define BOOST_ASIO_DISABLE_BOOST_BIND 1 # define BOOST_ASIO_DISABLE_BOOST_CHRONO 1 # define BOOST_ASIO_DISABLE_BOOST_DATE_TIME 1 # define BOOST_ASIO_DISABLE_BOOST_LIMITS 1 # define BOOST_ASIO_DISABLE_BOOST_REGEX 1 # define BOOST_ASIO_DISABLE_BOOST_STATIC_CONSTANT 1 # define BOOST_ASIO_DISABLE_BOOST_THROW_EXCEPTION 1 # define BOOST_ASIO_DISABLE_BOOST_WORKAROUND 1 #else // defined(BOOST_ASIO_STANDALONE) // Boost.Config library is available. # include <boost/config.hpp> # include <boost/version.hpp> # define BOOST_ASIO_HAS_BOOST_CONFIG 1 #endif // defined(BOOST_ASIO_STANDALONE) // Default to a header-only implementation. The user must specifically request // separate compilation by defining either BOOST_ASIO_SEPARATE_COMPILATION or // BOOST_ASIO_DYN_LINK (as a DLL/shared library implies separate compilation). #if !defined(BOOST_ASIO_HEADER_ONLY) # if !defined(BOOST_ASIO_SEPARATE_COMPILATION) # if !defined(BOOST_ASIO_DYN_LINK) # define BOOST_ASIO_HEADER_ONLY 1 # endif // !defined(BOOST_ASIO_DYN_LINK) # endif // !defined(BOOST_ASIO_SEPARATE_COMPILATION) #endif // !defined(BOOST_ASIO_HEADER_ONLY) #if defined(BOOST_ASIO_HEADER_ONLY) # define BOOST_ASIO_DECL inline #else // defined(BOOST_ASIO_HEADER_ONLY) # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__) // We need to import/export our code only if the user has specifically asked // for it by defining BOOST_ASIO_DYN_LINK. # if defined(BOOST_ASIO_DYN_LINK) // Export if this is our own source, otherwise import. # if defined(BOOST_ASIO_SOURCE) # define BOOST_ASIO_DECL __declspec(dllexport) # else // defined(BOOST_ASIO_SOURCE) # define BOOST_ASIO_DECL __declspec(dllimport) # endif // defined(BOOST_ASIO_SOURCE) # endif // defined(BOOST_ASIO_DYN_LINK) # endif // defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__) #endif // defined(BOOST_ASIO_HEADER_ONLY) // If BOOST_ASIO_DECL isn't defined yet define it now. #if !defined(BOOST_ASIO_DECL) # define BOOST_ASIO_DECL #endif // !defined(BOOST_ASIO_DECL) // Helper macro for documentation. #define BOOST_ASIO_UNSPECIFIED(e) e // Microsoft Visual C++ detection. #if !defined(BOOST_ASIO_MSVC) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC) # define BOOST_ASIO_MSVC BOOST_MSVC # elif defined(_MSC_VER) && (defined(__INTELLISENSE__) \ || (!defined(__MWERKS__) && !defined(__EDG_VERSION__))) # define BOOST_ASIO_MSVC _MSC_VER # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC) #endif // !defined(BOOST_ASIO_MSVC) // Clang / libc++ detection. #if defined(__clang__) # if (__cplusplus >= 201103) # if __has_include(<__config>) # include <__config> # if defined(_LIBCPP_VERSION) # define BOOST_ASIO_HAS_CLANG_LIBCXX 1 # endif // defined(_LIBCPP_VERSION) # endif // __has_include(<__config>) # endif // (__cplusplus >= 201103) #endif // defined(__clang__) // Android platform detection. #if defined(__ANDROID__) # include <android/api-level.h> #endif // defined(__ANDROID__) // Always enabled. Retained for backwards compatibility in user code. #if !defined(BOOST_ASIO_DISABLE_CXX11_MACROS) # define BOOST_ASIO_HAS_MOVE 1 # define BOOST_ASIO_MOVE_ARG(type) type&& # define BOOST_ASIO_MOVE_ARG2(type1, type2) type1, type2&& # define BOOST_ASIO_NONDEDUCED_MOVE_ARG(type) type& # define BOOST_ASIO_MOVE_CAST(type) static_cast<type&&> # define BOOST_ASIO_MOVE_CAST2(type1, type2) static_cast<type1, type2&&> # define BOOST_ASIO_MOVE_OR_LVALUE(type) static_cast<type&&> # define BOOST_ASIO_MOVE_OR_LVALUE_ARG(type) type&& # define BOOST_ASIO_MOVE_OR_LVALUE_TYPE(type) type # define BOOST_ASIO_DELETED = delete # define BOOST_ASIO_HAS_VARIADIC_TEMPLATES 1 # define BOOST_ASIO_HAS_CONSTEXPR 1 # define BOOST_ASIO_STATIC_CONSTEXPR(type, assignment) \ static constexpr type assignment # define BOOST_ASIO_HAS_NOEXCEPT 1 # define BOOST_ASIO_NOEXCEPT noexcept(true) # define BOOST_ASIO_NOEXCEPT_OR_NOTHROW noexcept(true) # define BOOST_ASIO_NOEXCEPT_IF(c) noexcept(c) # define BOOST_ASIO_HAS_DECLTYPE 1 # define BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX(t) auto # define BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX2(t0, t1) auto # define BOOST_ASIO_AUTO_RETURN_TYPE_PREFIX3(t0, t1, t2) auto # define BOOST_ASIO_AUTO_RETURN_TYPE_SUFFIX(expr) -> decltype expr # define BOOST_ASIO_HAS_ALIAS_TEMPLATES 1 # define BOOST_ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS 1 # define BOOST_ASIO_HAS_ENUM_CLASS 1 # define BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS 1 # define BOOST_ASIO_LVALUE_REF_QUAL & # define BOOST_ASIO_RVALUE_REF_QUAL && # define BOOST_ASIO_HAS_USER_DEFINED_LITERALS 1 # define BOOST_ASIO_HAS_ALIGNOF 1 # define BOOST_ASIO_ALIGNOF(T) alignof(T) # define BOOST_ASIO_HAS_STD_ALIGN 1 # define BOOST_ASIO_HAS_STD_SYSTEM_ERROR 1 # define BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT noexcept(true) # define BOOST_ASIO_HAS_STD_ARRAY 1 # define BOOST_ASIO_HAS_STD_SHARED_PTR 1 # define BOOST_ASIO_HAS_STD_ALLOCATOR_ARG 1 # define BOOST_ASIO_HAS_STD_ATOMIC 1 # define BOOST_ASIO_HAS_STD_CHRONO 1 # define BOOST_ASIO_HAS_STD_ADDRESSOF 1 # define BOOST_ASIO_HAS_STD_FUNCTION 1 # define BOOST_ASIO_HAS_STD_REFERENCE_WRAPPER 1 # define BOOST_ASIO_HAS_STD_TYPE_TRAITS 1 # define BOOST_ASIO_HAS_NULLPTR 1 # define BOOST_ASIO_HAS_CXX11_ALLOCATORS 1 # define BOOST_ASIO_HAS_CSTDINT 1 # define BOOST_ASIO_HAS_STD_THREAD 1 # define BOOST_ASIO_HAS_STD_MUTEX_AND_CONDVAR 1 # define BOOST_ASIO_HAS_STD_CALL_ONCE 1 # define BOOST_ASIO_HAS_STD_FUTURE 1 # define BOOST_ASIO_HAS_STD_TUPLE 1 # define BOOST_ASIO_HAS_STD_IOSTREAM_MOVE 1 # define BOOST_ASIO_HAS_STD_EXCEPTION_PTR 1 # define BOOST_ASIO_HAS_STD_NESTED_EXCEPTION 1 # define BOOST_ASIO_HAS_STD_HASH 1 #endif // !defined(BOOST_ASIO_DISABLE_CXX11_MACROS) // Support for static constexpr with default initialisation. #if !defined(BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT) # if defined(__GNUC__) # if (__GNUC__ >= 8) # define BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \ static constexpr const type name{} # else // (__GNUC__ >= 8) # define BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \ static const type name # endif // (__GNUC__ >= 8) # elif defined(BOOST_ASIO_MSVC) # define BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \ static const type name # else // defined(BOOST_ASIO_MSVC) # define BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \ static constexpr const type name{} # endif // defined(BOOST_ASIO_MSVC) #endif // !defined(BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT) // Support noexcept on function types on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) # if !defined(BOOST_ASIO_DISABLE_NOEXCEPT_FUNCTION_TYPE) # if defined(__clang__) # if (__cplusplus >= 202002) # define BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1 # endif // (__cplusplus >= 202002) # elif defined(__GNUC__) # if (__cplusplus >= 202002) # define BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1 # endif // (__cplusplus >= 202002) # elif defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1900 && _MSVC_LANG >= 202002) # define BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1 # endif // (_MSC_VER >= 1900 && _MSVC_LANG >= 202002) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_NOEXCEPT_FUNCTION_TYPE) #endif // !defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) // Support return type deduction on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) # if !defined(BOOST_ASIO_DISABLE_RETURN_TYPE_DEDUCTION) # if defined(__clang__) # if __has_feature(__cxx_return_type_deduction__) # define BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION 1 # endif // __has_feature(__cxx_return_type_deduction__) # elif (__cplusplus >= 201402) # define BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION 1 # elif defined(__cpp_return_type_deduction) # if (__cpp_return_type_deduction >= 201304) # define BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION 1 # endif // (__cpp_return_type_deduction >= 201304) # elif defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1900 && _MSVC_LANG >= 201402) # define BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION 1 # endif // (_MSC_VER >= 1900 && _MSVC_LANG >= 201402) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_RETURN_TYPE_DEDUCTION) #endif // !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION) // Support concepts on compilers known to allow them. #if !defined(BOOST_ASIO_HAS_CONCEPTS) # if !defined(BOOST_ASIO_DISABLE_CONCEPTS) # if defined(__cpp_concepts) # define BOOST_ASIO_HAS_CONCEPTS 1 # if (__cpp_concepts >= 201707) # define BOOST_ASIO_CONCEPT concept # else // (__cpp_concepts >= 201707) # define BOOST_ASIO_CONCEPT concept bool # endif // (__cpp_concepts >= 201707) # endif // defined(__cpp_concepts) # endif // !defined(BOOST_ASIO_DISABLE_CONCEPTS) #endif // !defined(BOOST_ASIO_HAS_CONCEPTS) // Support concepts on compilers known to allow them. #if !defined(BOOST_ASIO_HAS_STD_CONCEPTS) # if !defined(BOOST_ASIO_DISABLE_STD_CONCEPTS) # if defined(BOOST_ASIO_HAS_CONCEPTS) # if (__cpp_lib_concepts >= 202002L) # define BOOST_ASIO_HAS_STD_CONCEPTS 1 # endif // (__cpp_concepts >= 202002L) # endif // defined(BOOST_ASIO_HAS_CONCEPTS) # endif // !defined(BOOST_ASIO_DISABLE_STD_CONCEPTS) #endif // !defined(BOOST_ASIO_HAS_STD_CONCEPTS) // Support template variables on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) # if !defined(BOOST_ASIO_DISABLE_VARIABLE_TEMPLATES) # if defined(__clang__) # if (__cplusplus >= 201402) # if __has_feature(__cxx_variable_templates__) # define BOOST_ASIO_HAS_VARIABLE_TEMPLATES 1 # endif // __has_feature(__cxx_variable_templates__) # endif // (__cplusplus >= 201402) # elif defined(__GNUC__) && !defined(__INTEL_COMPILER) # if (__GNUC__ >= 6) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_VARIABLE_TEMPLATES 1 # endif // (__cplusplus >= 201402) # endif // (__GNUC__ >= 6) # endif // defined(__GNUC__) && !defined(__INTEL_COMPILER) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1901) # define BOOST_ASIO_HAS_VARIABLE_TEMPLATES 1 # endif // (_MSC_VER >= 1901) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_VARIABLE_TEMPLATES) #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) // Support SFINAEd template variables on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) # if !defined(BOOST_ASIO_DISABLE_SFINAE_VARIABLE_TEMPLATES) # if defined(__clang__) # if (__cplusplus >= 201703) # if __has_feature(__cxx_variable_templates__) # define BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1 # endif // __has_feature(__cxx_variable_templates__) # endif // (__cplusplus >= 201703) # elif defined(__GNUC__) # if ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 8) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1 # endif // (__cplusplus >= 201402) # endif // ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 8) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1901) # define BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1 # endif // (_MSC_VER >= 1901) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_SFINAE_VARIABLE_TEMPLATES) #endif // !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES) // Support SFINAE use of constant expressions on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE) # if !defined(BOOST_ASIO_DISABLE_CONSTANT_EXPRESSION_SFINAE) # if defined(__clang__) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1 # endif // (__cplusplus >= 201402) # elif defined(__GNUC__) && !defined(__INTEL_COMPILER) # if (__GNUC__ >= 7) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1 # endif // (__cplusplus >= 201402) # endif // (__GNUC__ >= 7) # endif // defined(__GNUC__) && !defined(__INTEL_COMPILER) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1901) # define BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1 # endif // (_MSC_VER >= 1901) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_CONSTANT_EXPRESSION_SFINAE) #endif // !defined(BOOST_ASIO_HAS_CONSTANT_EXPRESSION_SFINAE) // Enable workarounds for lack of working expression SFINAE. #if !defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) # if !defined(BOOST_ASIO_DISABLE_WORKING_EXPRESSION_SFINAE) # if !defined(BOOST_ASIO_MSVC) && !defined(__INTEL_COMPILER) # if (__cplusplus >= 201103) # define BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE 1 # endif // (__cplusplus >= 201103) # elif defined(BOOST_ASIO_MSVC) && (_MSC_VER >= 1929) # if (_MSVC_LANG >= 202000) # define BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE 1 # endif // (_MSVC_LANG >= 202000) # endif // defined(BOOST_ASIO_MSVC) && (_MSC_VER >= 1929) # endif // !defined(BOOST_ASIO_DISABLE_WORKING_EXPRESSION_SFINAE) #endif // !defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) // Support for capturing parameter packs in lambdas. #if !defined(BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES) # if !defined(BOOST_ASIO_DISABLE_VARIADIC_LAMBDA_CAPTURES) # if defined(__GNUC__) # if (__GNUC__ >= 6) # define BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1 # endif // (__GNUC__ >= 6) # elif defined(BOOST_ASIO_MSVC) # if (_MSVC_LANG >= 201103) # define BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1 # endif // (_MSC_LANG >= 201103) # else // defined(BOOST_ASIO_MSVC) # if (__cplusplus >= 201103) # define BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1 # endif // (__cplusplus >= 201103) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_VARIADIC_LAMBDA_CAPTURES) #endif // !defined(BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES) // Default alignment. #if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__) # define BOOST_ASIO_DEFAULT_ALIGN __STDCPP_DEFAULT_NEW_ALIGNMENT__ #elif defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4) # define BOOST_ASIO_DEFAULT_ALIGN alignof(std::max_align_t) # else // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4) # define BOOST_ASIO_DEFAULT_ALIGN alignof(max_align_t) # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4) #else // defined(__GNUC__) # define BOOST_ASIO_DEFAULT_ALIGN alignof(std::max_align_t) #endif // defined(__GNUC__) // Standard library support for aligned allocation. #if !defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) # if !defined(BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC) # if (__cplusplus >= 201703) # if defined(__clang__) # if defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if (_LIBCPP_STD_VER > 14) && defined(_LIBCPP_HAS_ALIGNED_ALLOC) \ && !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__) # if defined(__APPLE__) # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) # if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) # elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) # if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // (__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) # elif defined(__TV_OS_VERSION_MIN_REQUIRED) # if (__TV_OS_VERSION_MIN_REQUIRED >= 130000) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // (__TV_OS_VERSION_MIN_REQUIRED >= 130000) # elif defined(__WATCH_OS_VERSION_MIN_REQUIRED) # if (__WATCH_OS_VERSION_MIN_REQUIRED >= 60000) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // (__WATCH_OS_VERSION_MIN_REQUIRED >= 60000) # endif // defined(__WATCH_OS_X_VERSION_MIN_REQUIRED) # else // defined(__APPLE__) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // defined(__APPLE__) # endif // (_LIBCPP_STD_VER > 14) && defined(_LIBCPP_HAS_ALIGNED_ALLOC) // && !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__) # elif defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) # elif defined(__GNUC__) # if ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 7) # if defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) # define BOOST_ASIO_HAS_STD_ALIGNED_ALLOC 1 # endif // defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) # endif // ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 7) # endif // defined(__GNUC__) # endif // (__cplusplus >= 201703) # endif // !defined(BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC) #endif // !defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) // Boost support for chrono. #if !defined(BOOST_ASIO_HAS_BOOST_CHRONO) # if !defined(BOOST_ASIO_DISABLE_BOOST_CHRONO) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 104700) # define BOOST_ASIO_HAS_BOOST_CHRONO 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 104700) # endif // !defined(BOOST_ASIO_DISABLE_BOOST_CHRONO) #endif // !defined(BOOST_ASIO_HAS_BOOST_CHRONO) // Some form of chrono library is available. #if !defined(BOOST_ASIO_HAS_CHRONO) # if defined(BOOST_ASIO_HAS_STD_CHRONO) \ || defined(BOOST_ASIO_HAS_BOOST_CHRONO) # define BOOST_ASIO_HAS_CHRONO 1 # endif // defined(BOOST_ASIO_HAS_STD_CHRONO) // || defined(BOOST_ASIO_HAS_BOOST_CHRONO) #endif // !defined(BOOST_ASIO_HAS_CHRONO) // Boost support for the DateTime library. #if !defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) # if !defined(BOOST_ASIO_DISABLE_BOOST_DATE_TIME) # define BOOST_ASIO_HAS_BOOST_DATE_TIME 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_DATE_TIME) #endif // !defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) // Boost support for the Coroutine library. #if !defined(BOOST_ASIO_HAS_BOOST_COROUTINE) # if !defined(BOOST_ASIO_DISABLE_BOOST_COROUTINE) # define BOOST_ASIO_HAS_BOOST_COROUTINE 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_COROUTINE) #endif // !defined(BOOST_ASIO_HAS_BOOST_COROUTINE) // Boost support for the Context library's fibers. #if !defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER) # if !defined(BOOST_ASIO_DISABLE_BOOST_CONTEXT_FIBER) # if defined(__clang__) # if (__cplusplus >= 201103) # define BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER 1 # endif // (__cplusplus >= 201103) # elif defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4) # if (__cplusplus >= 201103) || defined(__GXX_EXPERIMENTAL_CXX0X__) # define BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER 1 # endif // (__cplusplus >= 201103) || defined(__GXX_EXPERIMENTAL_CXX0X__) # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSVC_LANG >= 201103) # define BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER 1 # endif // (_MSC_LANG >= 201103) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_BOOST_CONTEXT_FIBER) #endif // !defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER) // Standard library support for std::string_view. #if !defined(BOOST_ASIO_HAS_STD_STRING_VIEW) # if !defined(BOOST_ASIO_DISABLE_STD_STRING_VIEW) # if defined(__clang__) # if defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if (__cplusplus >= 201402) # if __has_include(<string_view>) # define BOOST_ASIO_HAS_STD_STRING_VIEW 1 # endif // __has_include(<string_view>) # endif // (__cplusplus >= 201402) # else // defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if (__cplusplus >= 201703) # if __has_include(<string_view>) # define BOOST_ASIO_HAS_STD_STRING_VIEW 1 # endif // __has_include(<string_view>) # endif // (__cplusplus >= 201703) # endif // defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # elif defined(__GNUC__) # if (__GNUC__ >= 7) # if (__cplusplus >= 201703) # define BOOST_ASIO_HAS_STD_STRING_VIEW 1 # endif // (__cplusplus >= 201703) # endif // (__GNUC__ >= 7) # elif defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1910 && _MSVC_LANG >= 201703) # define BOOST_ASIO_HAS_STD_STRING_VIEW 1 # endif // (_MSC_VER >= 1910 && _MSVC_LANG >= 201703) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_STRING_VIEW) #endif // !defined(BOOST_ASIO_HAS_STD_STRING_VIEW) // Standard library support for std::experimental::string_view. #if !defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) # if !defined(BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW) # if defined(__clang__) # if defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if (_LIBCPP_VERSION < 7000) # if (__cplusplus >= 201402) # if __has_include(<experimental/string_view>) # define BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1 # endif // __has_include(<experimental/string_view>) # endif // (__cplusplus >= 201402) # endif // (_LIBCPP_VERSION < 7000) # else // defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if (__cplusplus >= 201402) # if __has_include(<experimental/string_view>) # define BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1 # endif // __has_include(<experimental/string_view>) # endif // (__cplusplus >= 201402) # endif // // defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # elif defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1 # endif // (__cplusplus >= 201402) # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4) # endif // defined(__GNUC__) # endif // !defined(BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW) #endif // !defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) // Standard library has a string_view that we can use. #if !defined(BOOST_ASIO_HAS_STRING_VIEW) # if !defined(BOOST_ASIO_DISABLE_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) # define BOOST_ASIO_HAS_STRING_VIEW 1 # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) # define BOOST_ASIO_HAS_STRING_VIEW 1 # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) # endif // !defined(BOOST_ASIO_DISABLE_STRING_VIEW) #endif // !defined(BOOST_ASIO_HAS_STRING_VIEW) // Standard library has invoke_result (which supersedes result_of). #if !defined(BOOST_ASIO_HAS_STD_INVOKE_RESULT) # if !defined(BOOST_ASIO_DISABLE_STD_INVOKE_RESULT) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1911 && _MSVC_LANG >= 201703) # define BOOST_ASIO_HAS_STD_INVOKE_RESULT 1 # endif // (_MSC_VER >= 1911 && _MSVC_LANG >= 201703) # else // defined(BOOST_ASIO_MSVC) # if (__cplusplus >= 201703) # define BOOST_ASIO_HAS_STD_INVOKE_RESULT 1 # endif // (__cplusplus >= 201703) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_INVOKE_RESULT) #endif // !defined(BOOST_ASIO_HAS_STD_INVOKE_RESULT) // Standard library support for std::any. #if !defined(BOOST_ASIO_HAS_STD_ANY) # if !defined(BOOST_ASIO_DISABLE_STD_ANY) # if defined(__clang__) # if (__cplusplus >= 201703) # if __has_include(<any>) # define BOOST_ASIO_HAS_STD_ANY 1 # endif // __has_include(<any>) # endif // (__cplusplus >= 201703) # elif defined(__GNUC__) # if (__GNUC__ >= 7) # if (__cplusplus >= 201703) # define BOOST_ASIO_HAS_STD_ANY 1 # endif // (__cplusplus >= 201703) # endif // (__GNUC__ >= 7) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703) # define BOOST_ASIO_HAS_STD_ANY 1 # endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_ANY) #endif // !defined(BOOST_ASIO_HAS_STD_ANY) // Standard library support for std::variant. #if !defined(BOOST_ASIO_HAS_STD_VARIANT) # if !defined(BOOST_ASIO_DISABLE_STD_VARIANT) # if defined(__clang__) # if (__cplusplus >= 201703) # if __has_include(<variant>) # define BOOST_ASIO_HAS_STD_VARIANT 1 # endif // __has_include(<variant>) # endif // (__cplusplus >= 201703) # elif defined(__GNUC__) # if (__GNUC__ >= 7) # if (__cplusplus >= 201703) # define BOOST_ASIO_HAS_STD_VARIANT 1 # endif // (__cplusplus >= 201703) # endif // (__GNUC__ >= 7) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703) # define BOOST_ASIO_HAS_STD_VARIANT 1 # endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_VARIANT) #endif // !defined(BOOST_ASIO_HAS_STD_VARIANT) // Standard library support for std::source_location. #if !defined(BOOST_ASIO_HAS_STD_SOURCE_LOCATION) # if !defined(BOOST_ASIO_DISABLE_STD_SOURCE_LOCATION) // ... # endif // !defined(BOOST_ASIO_DISABLE_STD_SOURCE_LOCATION) #endif // !defined(BOOST_ASIO_HAS_STD_SOURCE_LOCATION) // Standard library support for std::experimental::source_location. #if !defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) # if !defined(BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_SOURCE_LOCATION) # if defined(__GNUC__) # if (__cplusplus >= 201709) # if __has_include(<experimental/source_location>) # define BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION 1 # endif // __has_include(<experimental/source_location>) # endif // (__cplusplus >= 201709) # endif // defined(__GNUC__) # endif // !defined(BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_SOURCE_LOCATION) #endif // !defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) // Standard library has a source_location that we can use. #if !defined(BOOST_ASIO_HAS_SOURCE_LOCATION) # if !defined(BOOST_ASIO_DISABLE_SOURCE_LOCATION) # if defined(BOOST_ASIO_HAS_STD_SOURCE_LOCATION) # define BOOST_ASIO_HAS_SOURCE_LOCATION 1 # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) # define BOOST_ASIO_HAS_SOURCE_LOCATION 1 # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) # endif // !defined(BOOST_ASIO_DISABLE_SOURCE_LOCATION) #endif // !defined(BOOST_ASIO_HAS_SOURCE_LOCATION) // Boost support for source_location and system errors. #if !defined(BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION) # if !defined(BOOST_ASIO_DISABLE_BOOST_SOURCE_LOCATION) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 107900) # define BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 107900) # endif // !defined(BOOST_ASIO_DISABLE_BOOST_SOURCE_LOCATION) #endif // !defined(BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION) // Helper macros for working with Boost source locations. #if defined(BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION) # define BOOST_ASIO_SOURCE_LOCATION_PARAM \ , const boost::source_location& loc # define BOOST_ASIO_SOURCE_LOCATION_DEFAULTED_PARAM \ , const boost::source_location& loc = BOOST_CURRENT_LOCATION # define BOOST_ASIO_SOURCE_LOCATION_ARG , loc #else // if defined(BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION) # define BOOST_ASIO_SOURCE_LOCATION_PARAM # define BOOST_ASIO_SOURCE_LOCATION_DEFAULTED_PARAM # define BOOST_ASIO_SOURCE_LOCATION_ARG #endif // if defined(BOOST_ASIO_HAS_BOOST_SOURCE_LOCATION) // Standard library support for std::index_sequence. #if !defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE) # if !defined(BOOST_ASIO_DISABLE_STD_INDEX_SEQUENCE) # if defined(__clang__) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_STD_INDEX_SEQUENCE 1 # endif // (__cplusplus >= 201402) # elif defined(__GNUC__) # if (__GNUC__ >= 7) # if (__cplusplus >= 201402) # define BOOST_ASIO_HAS_STD_INDEX_SEQUENCE 1 # endif // (__cplusplus >= 201402) # endif // (__GNUC__ >= 7) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201402) # define BOOST_ASIO_HAS_STD_INDEX_SEQUENCE 1 # endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201402) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_INDEX_SEQUENCE) #endif // !defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE) // Windows App target. Windows but with a limited API. #if !defined(BOOST_ASIO_WINDOWS_APP) # if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0603) # include <winapifamily.h> # if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \ || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)) \ && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # define BOOST_ASIO_WINDOWS_APP 1 # endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) // && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0603) #endif // !defined(BOOST_ASIO_WINDOWS_APP) // Legacy WinRT target. Windows App is preferred. #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) # if !defined(BOOST_ASIO_WINDOWS_APP) # if defined(__cplusplus_winrt) # include <winapifamily.h> # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \ && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # define BOOST_ASIO_WINDOWS_RUNTIME 1 # endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) // && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) # endif // defined(__cplusplus_winrt) # endif // !defined(BOOST_ASIO_WINDOWS_APP) #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) // Windows target. Excludes WinRT but includes Windows App targets. #if !defined(BOOST_ASIO_WINDOWS) # if !defined(BOOST_ASIO_WINDOWS_RUNTIME) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS) # define BOOST_ASIO_WINDOWS 1 # elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) # define BOOST_ASIO_WINDOWS 1 # elif defined(BOOST_ASIO_WINDOWS_APP) # define BOOST_ASIO_WINDOWS 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS) # endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // !defined(BOOST_ASIO_WINDOWS) // Windows: target OS version. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS) # if defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__)) # pragma message( \ "Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:\n"\ "- add -D_WIN32_WINNT=0x0601 to the compiler command line; or\n"\ "- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.\n"\ "Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).") # else // defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__)) # warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. # warning For example, add -D_WIN32_WINNT=0x0601 to the compiler command line. # warning Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target). # endif // defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__)) # define _WIN32_WINNT 0x0601 # endif // !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS) # if defined(_MSC_VER) # if defined(_WIN32) && !defined(WIN32) # if !defined(_WINSOCK2API_) # define WIN32 // Needed for correct types in winsock2.h # else // !defined(_WINSOCK2API_) # error Please define the macro WIN32 in your compiler options # endif // !defined(_WINSOCK2API_) # endif // defined(_WIN32) && !defined(WIN32) # endif // defined(_MSC_VER) # if defined(__BORLANDC__) # if defined(__WIN32__) && !defined(WIN32) # if !defined(_WINSOCK2API_) # define WIN32 // Needed for correct types in winsock2.h # else // !defined(_WINSOCK2API_) # error Please define the macro WIN32 in your compiler options # endif // !defined(_WINSOCK2API_) # endif // defined(__WIN32__) && !defined(WIN32) # endif // defined(__BORLANDC__) # if defined(__CYGWIN__) # if !defined(__USE_W32_SOCKETS) # error You must add -D__USE_W32_SOCKETS to your compiler options. # endif // !defined(__USE_W32_SOCKETS) # endif // defined(__CYGWIN__) #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Windows: minimise header inclusion. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if !defined(BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN) # if !defined(WIN32_LEAN_AND_MEAN) # define WIN32_LEAN_AND_MEAN # endif // !defined(WIN32_LEAN_AND_MEAN) # endif // !defined(BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN) #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Windows: suppress definition of "min" and "max" macros. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if !defined(BOOST_ASIO_NO_NOMINMAX) # if !defined(NOMINMAX) # define NOMINMAX 1 # endif // !defined(NOMINMAX) # endif // !defined(BOOST_ASIO_NO_NOMINMAX) #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Windows: IO Completion Ports. #if !defined(BOOST_ASIO_HAS_IOCP) # if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400) # if !defined(UNDER_CE) && !defined(BOOST_ASIO_WINDOWS_APP) # if !defined(BOOST_ASIO_DISABLE_IOCP) # define BOOST_ASIO_HAS_IOCP 1 # endif // !defined(BOOST_ASIO_DISABLE_IOCP) # endif // !defined(UNDER_CE) && !defined(BOOST_ASIO_WINDOWS_APP) # endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400) # endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #endif // !defined(BOOST_ASIO_HAS_IOCP) // On POSIX (and POSIX-like) platforms we need to include unistd.h in order to // get access to the various platform feature macros, e.g. to be able to test // for threads support. #if !defined(BOOST_ASIO_HAS_UNISTD_H) # if !defined(BOOST_ASIO_HAS_BOOST_CONFIG) # if defined(unix) \ || defined(__unix) \ || defined(_XOPEN_SOURCE) \ || defined(_POSIX_SOURCE) \ || (defined(__MACH__) && defined(__APPLE__)) \ || defined(__FreeBSD__) \ || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ || defined(__HAIKU__) # define BOOST_ASIO_HAS_UNISTD_H 1 # endif # endif // !defined(BOOST_ASIO_HAS_BOOST_CONFIG) #endif // !defined(BOOST_ASIO_HAS_UNISTD_H) #if defined(BOOST_ASIO_HAS_UNISTD_H) # include <unistd.h> #endif // defined(BOOST_ASIO_HAS_UNISTD_H) // Linux: epoll, eventfd, timerfd and io_uring. #if defined(__linux__) # include <linux/version.h> # if !defined(BOOST_ASIO_HAS_EPOLL) # if !defined(BOOST_ASIO_DISABLE_EPOLL) # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45) # define BOOST_ASIO_HAS_EPOLL 1 # endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45) # endif // !defined(BOOST_ASIO_DISABLE_EPOLL) # endif // !defined(BOOST_ASIO_HAS_EPOLL) # if !defined(BOOST_ASIO_HAS_EVENTFD) # if !defined(BOOST_ASIO_DISABLE_EVENTFD) # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) # define BOOST_ASIO_HAS_EVENTFD 1 # endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) # endif // !defined(BOOST_ASIO_DISABLE_EVENTFD) # endif // !defined(BOOST_ASIO_HAS_EVENTFD) # if !defined(BOOST_ASIO_HAS_TIMERFD) # if defined(BOOST_ASIO_HAS_EPOLL) # if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) # define BOOST_ASIO_HAS_TIMERFD 1 # endif // (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) # endif // defined(BOOST_ASIO_HAS_EPOLL) # endif // !defined(BOOST_ASIO_HAS_TIMERFD) # if defined(BOOST_ASIO_HAS_IO_URING) # if LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0) # error Linux kernel 5.10 or later is required to support io_uring # endif // LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0) # endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // defined(__linux__) // Linux: io_uring is used instead of epoll. #if !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # if !defined(BOOST_ASIO_HAS_EPOLL) && defined(BOOST_ASIO_HAS_IO_URING) # define BOOST_ASIO_HAS_IO_URING_AS_DEFAULT 1 # endif // !defined(BOOST_ASIO_HAS_EPOLL) && defined(BOOST_ASIO_HAS_IO_URING) #endif // !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) // Mac OS X, FreeBSD, NetBSD, OpenBSD: kqueue. #if (defined(__MACH__) && defined(__APPLE__)) \ || defined(__FreeBSD__) \ || defined(__NetBSD__) \ || defined(__OpenBSD__) # if !defined(BOOST_ASIO_HAS_KQUEUE) # if !defined(BOOST_ASIO_DISABLE_KQUEUE) # define BOOST_ASIO_HAS_KQUEUE 1 # endif // !defined(BOOST_ASIO_DISABLE_KQUEUE) # endif // !defined(BOOST_ASIO_HAS_KQUEUE) #endif // (defined(__MACH__) && defined(__APPLE__)) // || defined(__FreeBSD__) // || defined(__NetBSD__) // || defined(__OpenBSD__) // Solaris: /dev/poll. #if defined(__sun) # if !defined(BOOST_ASIO_HAS_DEV_POLL) # if !defined(BOOST_ASIO_DISABLE_DEV_POLL) # define BOOST_ASIO_HAS_DEV_POLL 1 # endif // !defined(BOOST_ASIO_DISABLE_DEV_POLL) # endif // !defined(BOOST_ASIO_HAS_DEV_POLL) #endif // defined(__sun) // Serial ports. #if !defined(BOOST_ASIO_HAS_SERIAL_PORT) # if defined(BOOST_ASIO_HAS_IOCP) \ || !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) # if !defined(__SYMBIAN32__) # if !defined(BOOST_ASIO_DISABLE_SERIAL_PORT) # define BOOST_ASIO_HAS_SERIAL_PORT 1 # endif // !defined(BOOST_ASIO_DISABLE_SERIAL_PORT) # endif // !defined(__SYMBIAN32__) # endif // defined(BOOST_ASIO_HAS_IOCP) // || !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) #endif // !defined(BOOST_ASIO_HAS_SERIAL_PORT) // Windows: stream handles. #if !defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) # if !defined(BOOST_ASIO_DISABLE_WINDOWS_STREAM_HANDLE) # if defined(BOOST_ASIO_HAS_IOCP) # define BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE 1 # endif // defined(BOOST_ASIO_HAS_IOCP) # endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_STREAM_HANDLE) #endif // !defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) // Windows: random access handles. #if !defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) # if !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE) # if defined(BOOST_ASIO_HAS_IOCP) # define BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE 1 # endif // defined(BOOST_ASIO_HAS_IOCP) # endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE) #endif // !defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) // Windows: object handles. #if !defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) # if !defined(BOOST_ASIO_DISABLE_WINDOWS_OBJECT_HANDLE) # if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if !defined(UNDER_CE) && !defined(BOOST_ASIO_WINDOWS_APP) # define BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE 1 # endif // !defined(UNDER_CE) && !defined(BOOST_ASIO_WINDOWS_APP) # endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_OBJECT_HANDLE) #endif // !defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) // Windows: OVERLAPPED wrapper. #if !defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) # if !defined(BOOST_ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR) # if defined(BOOST_ASIO_HAS_IOCP) # define BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR 1 # endif // defined(BOOST_ASIO_HAS_IOCP) # endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR) #endif // !defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) // POSIX: stream-oriented file descriptors. #if !defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) # if !defined(BOOST_ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR) # if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) # define BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1 # endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) # endif // !defined(BOOST_ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR) #endif // !defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) // UNIX domain sockets. #if !defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) # if !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS) # if !defined(BOOST_ASIO_WINDOWS_RUNTIME) # define BOOST_ASIO_HAS_LOCAL_SOCKETS 1 # endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) # endif // !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS) #endif // !defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // Files. #if !defined(BOOST_ASIO_HAS_FILE) # if !defined(BOOST_ASIO_DISABLE_FILE) # if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) # define BOOST_ASIO_HAS_FILE 1 # elif defined(BOOST_ASIO_HAS_IO_URING) # define BOOST_ASIO_HAS_FILE 1 # endif // defined(BOOST_ASIO_HAS_IO_URING) # endif // !defined(BOOST_ASIO_DISABLE_FILE) #endif // !defined(BOOST_ASIO_HAS_FILE) // Pipes. #if !defined(BOOST_ASIO_HAS_PIPE) # if defined(BOOST_ASIO_HAS_IOCP) \ || !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) # if !defined(__SYMBIAN32__) # if !defined(BOOST_ASIO_DISABLE_PIPE) # define BOOST_ASIO_HAS_PIPE 1 # endif // !defined(BOOST_ASIO_DISABLE_PIPE) # endif // !defined(__SYMBIAN32__) # endif // defined(BOOST_ASIO_HAS_IOCP) // || !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) #endif // !defined(BOOST_ASIO_HAS_PIPE) // Can use sigaction() instead of signal(). #if !defined(BOOST_ASIO_HAS_SIGACTION) # if !defined(BOOST_ASIO_DISABLE_SIGACTION) # if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) # define BOOST_ASIO_HAS_SIGACTION 1 # endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) # endif // !defined(BOOST_ASIO_DISABLE_SIGACTION) #endif // !defined(BOOST_ASIO_HAS_SIGACTION) // Can use signal(). #if !defined(BOOST_ASIO_HAS_SIGNAL) # if !defined(BOOST_ASIO_DISABLE_SIGNAL) # if !defined(UNDER_CE) # define BOOST_ASIO_HAS_SIGNAL 1 # endif // !defined(UNDER_CE) # endif // !defined(BOOST_ASIO_DISABLE_SIGNAL) #endif // !defined(BOOST_ASIO_HAS_SIGNAL) // Can use getaddrinfo() and getnameinfo(). #if !defined(BOOST_ASIO_HAS_GETADDRINFO) # if !defined(BOOST_ASIO_DISABLE_GETADDRINFO) # if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0501) # define BOOST_ASIO_HAS_GETADDRINFO 1 # elif defined(UNDER_CE) # define BOOST_ASIO_HAS_GETADDRINFO 1 # endif // defined(UNDER_CE) # elif defined(__MACH__) && defined(__APPLE__) # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) # if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1050) # define BOOST_ASIO_HAS_GETADDRINFO 1 # endif // (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1050) # else // defined(__MAC_OS_X_VERSION_MIN_REQUIRED) # define BOOST_ASIO_HAS_GETADDRINFO 1 # endif // defined(__MAC_OS_X_VERSION_MIN_REQUIRED) # else // defined(__MACH__) && defined(__APPLE__) # define BOOST_ASIO_HAS_GETADDRINFO 1 # endif // defined(__MACH__) && defined(__APPLE__) # endif // !defined(BOOST_ASIO_DISABLE_GETADDRINFO) #endif // !defined(BOOST_ASIO_HAS_GETADDRINFO) // Whether standard iostreams are disabled. #if !defined(BOOST_ASIO_NO_IOSTREAM) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_IOSTREAM) # define BOOST_ASIO_NO_IOSTREAM 1 # endif // !defined(BOOST_NO_IOSTREAM) #endif // !defined(BOOST_ASIO_NO_IOSTREAM) // Whether exception handling is disabled. #if !defined(BOOST_ASIO_NO_EXCEPTIONS) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_EXCEPTIONS) # define BOOST_ASIO_NO_EXCEPTIONS 1 # endif // !defined(BOOST_NO_EXCEPTIONS) #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) // Whether the typeid operator is supported. #if !defined(BOOST_ASIO_NO_TYPEID) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_TYPEID) # define BOOST_ASIO_NO_TYPEID 1 # endif // !defined(BOOST_NO_TYPEID) #endif // !defined(BOOST_ASIO_NO_TYPEID) // Threads. #if !defined(BOOST_ASIO_HAS_THREADS) # if !defined(BOOST_ASIO_DISABLE_THREADS) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(__GNUC__) && !defined(__MINGW32__) \ && !defined(linux) && !defined(__linux) && !defined(__linux__) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(_MT) || defined(__MT__) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(_REENTRANT) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(__APPLE__) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(__HAIKU__) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0) # define BOOST_ASIO_HAS_THREADS 1 # elif defined(_PTHREADS) # define BOOST_ASIO_HAS_THREADS 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS) # endif // !defined(BOOST_ASIO_DISABLE_THREADS) #endif // !defined(BOOST_ASIO_HAS_THREADS) // POSIX threads. #if !defined(BOOST_ASIO_HAS_PTHREADS) # if defined(BOOST_ASIO_HAS_THREADS) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS) # define BOOST_ASIO_HAS_PTHREADS 1 # elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0) # define BOOST_ASIO_HAS_PTHREADS 1 # elif defined(__HAIKU__) # define BOOST_ASIO_HAS_PTHREADS 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS) # endif // defined(BOOST_ASIO_HAS_THREADS) #endif // !defined(BOOST_ASIO_HAS_PTHREADS) // Helper to prevent macro expansion. #define BOOST_ASIO_PREVENT_MACRO_SUBSTITUTION // Helper to define in-class constants. #if !defined(BOOST_ASIO_STATIC_CONSTANT) # if !defined(BOOST_ASIO_DISABLE_BOOST_STATIC_CONSTANT) # define BOOST_ASIO_STATIC_CONSTANT(type, assignment) \ BOOST_STATIC_CONSTANT(type, assignment) # else // !defined(BOOST_ASIO_DISABLE_BOOST_STATIC_CONSTANT) # define BOOST_ASIO_STATIC_CONSTANT(type, assignment) \ static const type assignment # endif // !defined(BOOST_ASIO_DISABLE_BOOST_STATIC_CONSTANT) #endif // !defined(BOOST_ASIO_STATIC_CONSTANT) // Boost align library. #if !defined(BOOST_ASIO_HAS_BOOST_ALIGN) # if !defined(BOOST_ASIO_DISABLE_BOOST_ALIGN) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 105600) # define BOOST_ASIO_HAS_BOOST_ALIGN 1 # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 105600) # endif // !defined(BOOST_ASIO_DISABLE_BOOST_ALIGN) #endif // !defined(BOOST_ASIO_HAS_BOOST_ALIGN) // Boost array library. #if !defined(BOOST_ASIO_HAS_BOOST_ARRAY) # if !defined(BOOST_ASIO_DISABLE_BOOST_ARRAY) # define BOOST_ASIO_HAS_BOOST_ARRAY 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_ARRAY) #endif // !defined(BOOST_ASIO_HAS_BOOST_ARRAY) // Boost assert macro. #if !defined(BOOST_ASIO_HAS_BOOST_ASSERT) # if !defined(BOOST_ASIO_DISABLE_BOOST_ASSERT) # define BOOST_ASIO_HAS_BOOST_ASSERT 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_ASSERT) #endif // !defined(BOOST_ASIO_HAS_BOOST_ASSERT) // Boost limits header. #if !defined(BOOST_ASIO_HAS_BOOST_LIMITS) # if !defined(BOOST_ASIO_DISABLE_BOOST_LIMITS) # define BOOST_ASIO_HAS_BOOST_LIMITS 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_LIMITS) #endif // !defined(BOOST_ASIO_HAS_BOOST_LIMITS) // Boost throw_exception function. #if !defined(BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION) # if !defined(BOOST_ASIO_DISABLE_BOOST_THROW_EXCEPTION) # define BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_THROW_EXCEPTION) #endif // !defined(BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION) // Boost regex library. #if !defined(BOOST_ASIO_HAS_BOOST_REGEX) # if !defined(BOOST_ASIO_DISABLE_BOOST_REGEX) # define BOOST_ASIO_HAS_BOOST_REGEX 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_REGEX) #endif // !defined(BOOST_ASIO_HAS_BOOST_REGEX) // Boost bind function. #if !defined(BOOST_ASIO_HAS_BOOST_BIND) # if !defined(BOOST_ASIO_DISABLE_BOOST_BIND) # define BOOST_ASIO_HAS_BOOST_BIND 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_BIND) #endif // !defined(BOOST_ASIO_HAS_BOOST_BIND) // Boost's BOOST_WORKAROUND macro. #if !defined(BOOST_ASIO_HAS_BOOST_WORKAROUND) # if !defined(BOOST_ASIO_DISABLE_BOOST_WORKAROUND) # define BOOST_ASIO_HAS_BOOST_WORKAROUND 1 # endif // !defined(BOOST_ASIO_DISABLE_BOOST_WORKAROUND) #endif // !defined(BOOST_ASIO_HAS_BOOST_WORKAROUND) // Microsoft Visual C++'s secure C runtime library. #if !defined(BOOST_ASIO_HAS_SECURE_RTL) # if !defined(BOOST_ASIO_DISABLE_SECURE_RTL) # if defined(BOOST_ASIO_MSVC) \ && (BOOST_ASIO_MSVC >= 1400) \ && !defined(UNDER_CE) # define BOOST_ASIO_HAS_SECURE_RTL 1 # endif // defined(BOOST_ASIO_MSVC) // && (BOOST_ASIO_MSVC >= 1400) // && !defined(UNDER_CE) # endif // !defined(BOOST_ASIO_DISABLE_SECURE_RTL) #endif // !defined(BOOST_ASIO_HAS_SECURE_RTL) // Handler hooking. Disabled for ancient Borland C++ and gcc compilers. #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS) # if !defined(BOOST_ASIO_DISABLE_HANDLER_HOOKS) # if defined(__GNUC__) # if (__GNUC__ >= 3) # define BOOST_ASIO_HAS_HANDLER_HOOKS 1 # endif // (__GNUC__ >= 3) # elif !defined(__BORLANDC__) || defined(__clang__) # define BOOST_ASIO_HAS_HANDLER_HOOKS 1 # endif // !defined(__BORLANDC__) || defined(__clang__) # endif // !defined(BOOST_ASIO_DISABLE_HANDLER_HOOKS) #endif // !defined(BOOST_ASIO_HAS_HANDLER_HOOKS) // Support for the __thread keyword extension, or equivalent. #if !defined(BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION) # if defined(__linux__) # if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) # if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3) # if !defined(__INTEL_COMPILER) && !defined(__ICL) \ && !(defined(__clang__) && defined(__ANDROID__)) # define BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION 1 # define BOOST_ASIO_THREAD_KEYWORD __thread # elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100) # define BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION 1 # endif // defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100) // && !(defined(__clang__) && defined(__ANDROID__)) # endif // ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3) # endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) # endif // defined(__linux__) # if defined(BOOST_ASIO_MSVC) && defined(BOOST_ASIO_WINDOWS_RUNTIME) # if (_MSC_VER >= 1700) # define BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION 1 # define BOOST_ASIO_THREAD_KEYWORD __declspec(thread) # endif // (_MSC_VER >= 1700) # endif // defined(BOOST_ASIO_MSVC) && defined(BOOST_ASIO_WINDOWS_RUNTIME) # if defined(__APPLE__) # if defined(__clang__) # if defined(__apple_build_version__) # define BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION 1 # define BOOST_ASIO_THREAD_KEYWORD __thread # endif // defined(__apple_build_version__) # endif // defined(__clang__) # endif // defined(__APPLE__) # if !defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) # if defined(BOOST_ASIO_HAS_BOOST_CONFIG) # if !defined(BOOST_NO_CXX11_THREAD_LOCAL) # define BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION 1 # define BOOST_ASIO_THREAD_KEYWORD thread_local # endif // !defined(BOOST_NO_CXX11_THREAD_LOCAL) # endif // defined(BOOST_ASIO_HAS_BOOST_CONFIG) # endif // !defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) #endif // !defined(BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION) #if !defined(BOOST_ASIO_THREAD_KEYWORD) # define BOOST_ASIO_THREAD_KEYWORD __thread #endif // !defined(BOOST_ASIO_THREAD_KEYWORD) // Support for POSIX ssize_t typedef. #if !defined(BOOST_ASIO_DISABLE_SSIZE_T) # if defined(__linux__) \ || (defined(__MACH__) && defined(__APPLE__)) # define BOOST_ASIO_HAS_SSIZE_T 1 # endif // defined(__linux__) // || (defined(__MACH__) && defined(__APPLE__)) #endif // !defined(BOOST_ASIO_DISABLE_SSIZE_T) // Helper macros to manage transition away from error_code return values. #if defined(BOOST_ASIO_NO_DEPRECATED) # define BOOST_ASIO_SYNC_OP_VOID void # define BOOST_ASIO_SYNC_OP_VOID_RETURN(e) return #else // defined(BOOST_ASIO_NO_DEPRECATED) # define BOOST_ASIO_SYNC_OP_VOID boost::system::error_code # define BOOST_ASIO_SYNC_OP_VOID_RETURN(e) return e #endif // defined(BOOST_ASIO_NO_DEPRECATED) // Newer gcc, clang need special treatment to suppress unused typedef warnings. #if defined(__clang__) # if defined(__apple_build_version__) # if (__clang_major__ >= 7) # define BOOST_ASIO_UNUSED_TYPEDEF __attribute__((__unused__)) # endif // (__clang_major__ >= 7) # elif ((__clang_major__ == 3) && (__clang_minor__ >= 6)) \ || (__clang_major__ > 3) # define BOOST_ASIO_UNUSED_TYPEDEF __attribute__((__unused__)) # endif // ((__clang_major__ == 3) && (__clang_minor__ >= 6)) // || (__clang_major__ > 3) #elif defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4) # define BOOST_ASIO_UNUSED_TYPEDEF __attribute__((__unused__)) # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4) #endif // defined(__GNUC__) #if !defined(BOOST_ASIO_UNUSED_TYPEDEF) # define BOOST_ASIO_UNUSED_TYPEDEF #endif // !defined(BOOST_ASIO_UNUSED_TYPEDEF) // Some versions of gcc generate spurious warnings about unused variables. #if defined(__GNUC__) # if (__GNUC__ >= 4) # define BOOST_ASIO_UNUSED_VARIABLE __attribute__((__unused__)) # endif // (__GNUC__ >= 4) #endif // defined(__GNUC__) #if !defined(BOOST_ASIO_UNUSED_VARIABLE) # define BOOST_ASIO_UNUSED_VARIABLE #endif // !defined(BOOST_ASIO_UNUSED_VARIABLE) // Helper macro to tell the optimiser what may be assumed to be true. #if defined(BOOST_ASIO_MSVC) # define BOOST_ASIO_ASSUME(expr) __assume(expr) #elif defined(__clang__) # if __has_builtin(__builtin_assume) # define BOOST_ASIO_ASSUME(expr) __builtin_assume(expr) # endif // __has_builtin(__builtin_assume) #elif defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4) # define BOOST_ASIO_ASSUME(expr) if (expr) {} else { __builtin_unreachable(); } # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4) #endif // defined(__GNUC__) #if !defined(BOOST_ASIO_ASSUME) # define BOOST_ASIO_ASSUME(expr) (void)0 #endif // !defined(BOOST_ASIO_ASSUME) // Support the co_await keyword on compilers known to allow it. #if !defined(BOOST_ASIO_HAS_CO_AWAIT) # if !defined(BOOST_ASIO_DISABLE_CO_AWAIT) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705) && !defined(__clang__) # define BOOST_ASIO_HAS_CO_AWAIT 1 # elif (_MSC_FULL_VER >= 190023506) # if defined(_RESUMABLE_FUNCTIONS_SUPPORTED) # define BOOST_ASIO_HAS_CO_AWAIT 1 # endif // defined(_RESUMABLE_FUNCTIONS_SUPPORTED) # endif // (_MSC_FULL_VER >= 190023506) # elif defined(__clang__) # if (__clang_major__ >= 14) # if (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902) # if __has_include(<coroutine>) # define BOOST_ASIO_HAS_CO_AWAIT 1 # endif // __has_include(<coroutine>) # elif (__cplusplus >= 201703) && (__cpp_coroutines >= 201703) # if __has_include(<experimental/coroutine>) # define BOOST_ASIO_HAS_CO_AWAIT 1 # endif // __has_include(<experimental/coroutine>) # endif // (__cplusplus >= 201703) && (__cpp_coroutines >= 201703) # else // (__clang_major__ >= 14) # if (__cplusplus >= 201703) && (__cpp_coroutines >= 201703) # if __has_include(<experimental/coroutine>) # define BOOST_ASIO_HAS_CO_AWAIT 1 # endif // __has_include(<experimental/coroutine>) # endif // (__cplusplus >= 201703) && (__cpp_coroutines >= 201703) # endif // (__clang_major__ >= 14) # elif defined(__GNUC__) # if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902) # if __has_include(<coroutine>) # define BOOST_ASIO_HAS_CO_AWAIT 1 # endif // __has_include(<coroutine>) # endif // (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902) # endif // defined(__GNUC__) # endif // !defined(BOOST_ASIO_DISABLE_CO_AWAIT) #endif // !defined(BOOST_ASIO_HAS_CO_AWAIT) // Standard library support for coroutines. #if !defined(BOOST_ASIO_HAS_STD_COROUTINE) # if !defined(BOOST_ASIO_DISABLE_STD_COROUTINE) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705) # define BOOST_ASIO_HAS_STD_COROUTINE 1 # endif // (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705) # elif defined(__clang__) # if (__clang_major__ >= 14) # if (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902) # if __has_include(<coroutine>) # define BOOST_ASIO_HAS_STD_COROUTINE 1 # endif // __has_include(<coroutine>) # endif // (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902) # endif // (__clang_major__ >= 14) # elif defined(__GNUC__) # if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902) # if __has_include(<coroutine>) # define BOOST_ASIO_HAS_STD_COROUTINE 1 # endif // __has_include(<coroutine>) # endif // (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902) # endif // defined(__GNUC__) # endif // !defined(BOOST_ASIO_DISABLE_STD_COROUTINE) #endif // !defined(BOOST_ASIO_HAS_STD_COROUTINE) // Compiler support for the the [[nodiscard]] attribute. #if !defined(BOOST_ASIO_NODISCARD) # if defined(__has_cpp_attribute) # if __has_cpp_attribute(nodiscard) # if (__cplusplus >= 201703) # define BOOST_ASIO_NODISCARD [[nodiscard]] # endif // (__cplusplus >= 201703) # endif // __has_cpp_attribute(nodiscard) # endif // defined(__has_cpp_attribute) #endif // !defined(BOOST_ASIO_NODISCARD) #if !defined(BOOST_ASIO_NODISCARD) # define BOOST_ASIO_NODISCARD #endif // !defined(BOOST_ASIO_NODISCARD) // Kernel support for MSG_NOSIGNAL. #if !defined(BOOST_ASIO_HAS_MSG_NOSIGNAL) # if defined(__linux__) # define BOOST_ASIO_HAS_MSG_NOSIGNAL 1 # elif defined(_POSIX_VERSION) # if (_POSIX_VERSION >= 200809L) # define BOOST_ASIO_HAS_MSG_NOSIGNAL 1 # endif // _POSIX_VERSION >= 200809L # endif // defined(_POSIX_VERSION) #endif // !defined(BOOST_ASIO_HAS_MSG_NOSIGNAL) // Standard library support for std::to_address. #if !defined(BOOST_ASIO_HAS_STD_TO_ADDRESS) # if !defined(BOOST_ASIO_DISABLE_STD_TO_ADDRESS) # if defined(__clang__) # if (__cplusplus >= 202002) # define BOOST_ASIO_HAS_STD_TO_ADDRESS 1 # endif // (__cplusplus >= 202002) # elif defined(__GNUC__) # if (__GNUC__ >= 8) # if (__cplusplus >= 202002) # define BOOST_ASIO_HAS_STD_TO_ADDRESS 1 # endif // (__cplusplus >= 202002) # endif // (__GNUC__ >= 8) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1922) && (_MSVC_LANG >= 202002) # define BOOST_ASIO_HAS_STD_TO_ADDRESS 1 # endif // (_MSC_VER >= 1922) && (_MSVC_LANG >= 202002) # endif // defined(BOOST_ASIO_MSVC) # endif // !defined(BOOST_ASIO_DISABLE_STD_TO_ADDRESS) #endif // !defined(BOOST_ASIO_HAS_STD_TO_ADDRESS) // Standard library support for snprintf. #if !defined(BOOST_ASIO_HAS_SNPRINTF) # if !defined(BOOST_ASIO_DISABLE_SNPRINTF) # if defined(__apple_build_version__) # if (__clang_major__ >= 14) # define BOOST_ASIO_HAS_SNPRINTF 1 # endif // (__clang_major__ >= 14) # endif // defined(__apple_build_version__) # endif // !defined(BOOST_ASIO_DISABLE_SNPRINTF) #endif // !defined(BOOST_ASIO_HAS_SNPRINTF) #endif // BOOST_ASIO_DETAIL_CONFIG_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/initiate_post.hpp
// // detail/initiate_post.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_INITIATE_POST_HPP #define BOOST_ASIO_DETAIL_INITIATE_POST_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/detail/work_dispatcher.hpp> #include <boost/asio/execution/allocator.hpp> #include <boost/asio/execution/blocking.hpp> #include <boost/asio/execution/relationship.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/require.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class initiate_post { public: template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex, execution::blocking.never), execution::relationship.fork, execution::allocator(alloc) ).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex.post(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } }; template <typename Executor> class initiate_post_with_executor { public: typedef Executor executor_type; explicit initiate_post_with_executor(const Executor& ex) : ex_(ex) { } executor_type get_executor() const noexcept { return ex_; } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex_, execution::blocking.never), execution::relationship.fork, execution::allocator(alloc) ).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex_, execution::blocking.never), execution::relationship.fork, execution::allocator(alloc) ).execute( detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex)); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex_.post(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); ex_.post(detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex), alloc); } private: Executor ex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_INITIATE_POST_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_wait_op.hpp
// // detail/io_uring_wait_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_IO_URING_WAIT_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_WAIT_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/io_uring_operation.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class io_uring_wait_op : public io_uring_operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_wait_op); io_uring_wait_op(const boost::system::error_code& success_ec, int descriptor, int poll_flags, Handler& handler, const IoExecutor& io_ex) : io_uring_operation(success_ec, &io_uring_wait_op::do_prepare, &io_uring_wait_op::do_perform, &io_uring_wait_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex), descriptor_(descriptor), poll_flags_(poll_flags) { } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_wait_op* o(static_cast<io_uring_wait_op*>(base)); ::io_uring_prep_poll_add(sqe, o->descriptor_, o->poll_flags_); } static bool do_perform(io_uring_operation*, bool after_completion) { return after_completion; } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_wait_op* o(static_cast<io_uring_wait_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); BOOST_ASIO_ERROR_LOCATION(o->ec_); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder1<Handler, boost::system::error_code> handler(o->handler_, o->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; int descriptor_; int poll_flags_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IO_URING_WAIT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_event.hpp
// // detail/win_event.hpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_WIN_EVENT_HPP #define BOOST_ASIO_DETAIL_WIN_EVENT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS) #include <cstddef> #include <boost/asio/detail/assert.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class win_event : private noncopyable { public: // Constructor. BOOST_ASIO_DECL win_event(); // Destructor. BOOST_ASIO_DECL ~win_event(); // Signal the event. (Retained for backward compatibility.) template <typename Lock> void signal(Lock& lock) { this->signal_all(lock); } // Signal all waiters. template <typename Lock> void signal_all(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); (void)lock; state_ |= 1; ::SetEvent(events_[0]); } // Unlock the mutex and signal one waiter. template <typename Lock> void unlock_and_signal_one(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); lock.unlock(); if (have_waiters) ::SetEvent(events_[1]); } // Unlock the mutex and signal one waiter who may destroy us. template <typename Lock> void unlock_and_signal_one_for_destruction(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); if (have_waiters) ::SetEvent(events_[1]); lock.unlock(); } // If there's a waiter, unlock the mutex and signal it. template <typename Lock> bool maybe_unlock_and_signal_one(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; if (state_ > 1) { lock.unlock(); ::SetEvent(events_[1]); return true; } return false; } // Reset the event. template <typename Lock> void clear(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); (void)lock; ::ResetEvent(events_[0]); state_ &= ~std::size_t(1); } // Wait for the event to become signalled. template <typename Lock> void wait(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); while ((state_ & 1) == 0) { state_ += 2; lock.unlock(); #if defined(BOOST_ASIO_WINDOWS_APP) ::WaitForMultipleObjectsEx(2, events_, false, INFINITE, false); #else // defined(BOOST_ASIO_WINDOWS_APP) ::WaitForMultipleObjects(2, events_, false, INFINITE); #endif // defined(BOOST_ASIO_WINDOWS_APP) lock.lock(); state_ -= 2; } } // Timed wait for the event to become signalled. template <typename Lock> bool wait_for_usec(Lock& lock, long usec) { BOOST_ASIO_ASSERT(lock.locked()); if ((state_ & 1) == 0) { state_ += 2; lock.unlock(); DWORD msec = usec > 0 ? (usec < 1000 ? 1 : usec / 1000) : 0; #if defined(BOOST_ASIO_WINDOWS_APP) ::WaitForMultipleObjectsEx(2, events_, false, msec, false); #else // defined(BOOST_ASIO_WINDOWS_APP) ::WaitForMultipleObjects(2, events_, false, msec); #endif // defined(BOOST_ASIO_WINDOWS_APP) lock.lock(); state_ -= 2; } return (state_ & 1) != 0; } private: HANDLE events_[2]; std::size_t state_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_event.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) #endif // BOOST_ASIO_DETAIL_WIN_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_descriptor_service.hpp
// // detail/io_uring_descriptor_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP #define BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/buffer.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/descriptor_ops.hpp> #include <boost/asio/detail/io_uring_descriptor_read_at_op.hpp> #include <boost/asio/detail/io_uring_descriptor_read_op.hpp> #include <boost/asio/detail/io_uring_descriptor_write_at_op.hpp> #include <boost/asio/detail/io_uring_descriptor_write_op.hpp> #include <boost/asio/detail/io_uring_null_buffers_op.hpp> #include <boost/asio/detail/io_uring_service.hpp> #include <boost/asio/detail/io_uring_wait_op.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/posix/descriptor_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class io_uring_descriptor_service : public execution_context_service_base<io_uring_descriptor_service> { public: // The native type of a descriptor. typedef int native_handle_type; // The implementation type of the descriptor. class implementation_type : private boost::asio::detail::noncopyable { public: // Default constructor. implementation_type() : descriptor_(-1), state_(0) { } private: // Only this service will have access to the internal values. friend class io_uring_descriptor_service; // The native descriptor representation. int descriptor_; // The current state of the descriptor. descriptor_ops::state_type state_; // Per I/O object data used by the io_uring_service. io_uring_service::per_io_object_data io_object_data_; }; // Constructor. BOOST_ASIO_DECL io_uring_descriptor_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new descriptor implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Move-construct a new descriptor implementation. BOOST_ASIO_DECL void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept; // Move-assign from another descriptor implementation. BOOST_ASIO_DECL void move_assign(implementation_type& impl, io_uring_descriptor_service& other_service, implementation_type& other_impl); // Destroy a descriptor implementation. BOOST_ASIO_DECL void destroy(implementation_type& impl); // Assign a native descriptor to a descriptor implementation. BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl, const native_handle_type& native_descriptor, boost::system::error_code& ec); // Determine whether the descriptor is open. bool is_open(const implementation_type& impl) const { return impl.descriptor_ != -1; } // Destroy a descriptor implementation. BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec); // Get the native descriptor representation. native_handle_type native_handle(const implementation_type& impl) const { return impl.descriptor_; } // Release ownership of the native descriptor representation. BOOST_ASIO_DECL native_handle_type release(implementation_type& impl); // Release ownership of the native descriptor representation. native_handle_type release(implementation_type& impl, boost::system::error_code& ec) { ec = success_ec_; return release(impl); } // Cancel all operations associated with the descriptor. BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec); // Perform an IO control command on the descriptor. template <typename IO_Control_Command> boost::system::error_code io_control(implementation_type& impl, IO_Control_Command& command, boost::system::error_code& ec) { descriptor_ops::ioctl(impl.descriptor_, impl.state_, command.name(), static_cast<ioctl_arg_type*>(command.data()), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Gets the non-blocking mode of the descriptor. bool non_blocking(const implementation_type& impl) const { return (impl.state_ & descriptor_ops::user_set_non_blocking) != 0; } // Sets the non-blocking mode of the descriptor. boost::system::error_code non_blocking(implementation_type& impl, bool mode, boost::system::error_code& ec) { descriptor_ops::set_user_non_blocking( impl.descriptor_, impl.state_, mode, ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Gets the non-blocking mode of the native descriptor implementation. bool native_non_blocking(const implementation_type& impl) const { return (impl.state_ & descriptor_ops::internal_non_blocking) != 0; } // Sets the non-blocking mode of the native descriptor implementation. boost::system::error_code native_non_blocking(implementation_type& impl, bool mode, boost::system::error_code& ec) { descriptor_ops::set_internal_non_blocking( impl.descriptor_, impl.state_, mode, ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Wait for the descriptor to become ready to read, ready to write, or to have // pending error conditions. boost::system::error_code wait(implementation_type& impl, posix::descriptor_base::wait_type w, boost::system::error_code& ec) { switch (w) { case posix::descriptor_base::wait_read: descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec); break; case posix::descriptor_base::wait_write: descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec); break; case posix::descriptor_base::wait_error: descriptor_ops::poll_error(impl.descriptor_, impl.state_, ec); break; default: ec = boost::asio::error::invalid_argument; break; } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Asynchronously wait for the descriptor to become ready to read, ready to // write, or to have pending error conditions. template <typename Handler, typename IoExecutor> void async_wait(implementation_type& impl, posix::descriptor_base::wait_type w, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); int op_type; int poll_flags; switch (w) { case posix::descriptor_base::wait_read: op_type = io_uring_service::read_op; poll_flags = POLLIN; break; case posix::descriptor_base::wait_write: op_type = io_uring_service::write_op; poll_flags = POLLOUT; break; case posix::descriptor_base::wait_error: op_type = io_uring_service::except_op; poll_flags = POLLPRI | POLLERR | POLLHUP; break; default: op_type = -1; poll_flags = -1; return; } // Allocate and construct an operation to wrap the handler. typedef io_uring_wait_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, poll_flags, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected() && op_type != -1) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>( &io_uring_service_, &impl.io_object_data_, op_type); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_wait")); start_op(impl, op_type, p.p, is_continuation, op_type == -1); p.v = p.p = 0; } // Write some data to the descriptor. template <typename ConstBufferSequence> size_t write_some(implementation_type& impl, const ConstBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = descriptor_ops::sync_write1(impl.descriptor_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); n = descriptor_ops::sync_write(impl.descriptor_, impl.state_, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be written without blocking. size_t write_some(implementation_type& impl, const null_buffers&, boost::system::error_code& ec) { // Wait for descriptor to become ready. descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous write. The data being sent must be valid for the // lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_descriptor_write_op< ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, impl.state_, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::write_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_write_some")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::all_empty(buffers)); p.v = p.p = 0; } // Start an asynchronous wait until data can be written without blocking. template <typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const null_buffers&, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, POLLOUT, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::write_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_write_some(null_buffers)")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, false); p.v = p.p = 0; } // Write some data to the descriptor at the specified offset. template <typename ConstBufferSequence> size_t write_some_at(implementation_type& impl, uint64_t offset, const ConstBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = descriptor_ops::sync_write_at1(impl.descriptor_, impl.state_, offset, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); n = descriptor_ops::sync_write_at(impl.descriptor_, impl.state_, offset, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be written without blocking. size_t write_some_at(implementation_type& impl, uint64_t, const null_buffers& buffers, boost::system::error_code& ec) { return write_some(impl, buffers, ec); } // Start an asynchronous write at the specified offset. The data being sent // must be valid for the lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_write_some_at(implementation_type& impl, uint64_t offset, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_descriptor_write_at_op< ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, impl.state_, offset, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::write_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_write_some")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::all_empty(buffers)); p.v = p.p = 0; } // Start an asynchronous wait until data can be written without blocking. template <typename Handler, typename IoExecutor> void async_write_some_at(implementation_type& impl, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex) { return async_write_some(impl, buffers, handler, io_ex); } // Read some data from the stream. Returns the number of bytes read. template <typename MutableBufferSequence> size_t read_some(implementation_type& impl, const MutableBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = descriptor_ops::sync_read1(impl.descriptor_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); n = descriptor_ops::sync_read(impl.descriptor_, impl.state_, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be read without blocking. size_t read_some(implementation_type& impl, const null_buffers&, boost::system::error_code& ec) { // Wait for descriptor to become ready. descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous read. The buffer for the data being read must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_descriptor_read_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, impl.state_, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::read_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_read_some")); start_op(impl, io_uring_service::read_op, p.p, is_continuation, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(buffers)); p.v = p.p = 0; } // Wait until data can be read without blocking. template <typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const null_buffers&, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, POLLIN, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::read_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_read_some(null_buffers)")); start_op(impl, io_uring_service::read_op, p.p, is_continuation, false); p.v = p.p = 0; } // Read some data at the specified offset. Returns the number of bytes read. template <typename MutableBufferSequence> size_t read_some_at(implementation_type& impl, uint64_t offset, const MutableBufferSequence& buffers, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; if (bufs_type::is_single_buffer) { return descriptor_ops::sync_read_at1(impl.descriptor_, impl.state_, offset, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), ec); } else { bufs_type bufs(buffers); return descriptor_ops::sync_read_at(impl.descriptor_, impl.state_, offset, bufs.buffers(), bufs.count(), bufs.all_empty(), ec); } } // Wait until data can be read without blocking. size_t read_some_at(implementation_type& impl, uint64_t, const null_buffers& buffers, boost::system::error_code& ec) { return read_some(impl, buffers, ec); } // Start an asynchronous read. The buffer for the data being read must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some_at(implementation_type& impl, uint64_t offset, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef io_uring_descriptor_read_at_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.descriptor_, impl.state_, offset, buffers, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::read_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "descriptor", &impl, impl.descriptor_, "async_read_some")); start_op(impl, io_uring_service::read_op, p.p, is_continuation, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(buffers)); p.v = p.p = 0; } // Wait until data can be read without blocking. template <typename Handler, typename IoExecutor> void async_read_some_at(implementation_type& impl, uint64_t, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex) { return async_read_some(impl, buffers, handler, io_ex); } private: // Start the asynchronous operation. BOOST_ASIO_DECL void start_op(implementation_type& impl, int op_type, io_uring_operation* op, bool is_continuation, bool noop); // Helper class used to implement per-operation cancellation class io_uring_op_cancellation { public: io_uring_op_cancellation(io_uring_service* s, io_uring_service::per_io_object_data* p, int o) : io_uring_service_(s), io_object_data_(p), op_type_(o) { } void operator()(cancellation_type_t type) { if (!!(type & (cancellation_type::terminal | cancellation_type::partial | cancellation_type::total))) { io_uring_service_->cancel_ops_by_key(*io_object_data_, op_type_, this); } } private: io_uring_service* io_uring_service_; io_uring_service::per_io_object_data* io_object_data_; int op_type_; }; // The io_uring_service that performs event demultiplexing for the service. io_uring_service& io_uring_service_; // Cached success value to avoid accessing category singleton. const boost::system::error_code success_ec_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/io_uring_descriptor_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_recv_op.hpp
// // detail/reactive_socket_recv_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECV_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECV_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence> class reactive_socket_recv_op_base : public reactor_op { public: reactive_socket_recv_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags flags, func_type complete_func) : reactor_op(success_ec, &reactive_socket_recv_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), flags_(flags) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_recv_op_base* o( static_cast<reactive_socket_recv_op_base*>(base)); typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; status result; if (bufs_type::is_single_buffer) { result = socket_ops::non_blocking_recv1(o->socket_, bufs_type::first(o->buffers_).data(), bufs_type::first(o->buffers_).size(), o->flags_, (o->state_ & socket_ops::stream_oriented) != 0, o->ec_, o->bytes_transferred_) ? done : not_done; } else { bufs_type bufs(o->buffers_); result = socket_ops::non_blocking_recv(o->socket_, bufs.buffers(), bufs.count(), o->flags_, (o->state_ & socket_ops::stream_oriented) != 0, o->ec_, o->bytes_transferred_) ? done : not_done; } if (result == done) if ((o->state_ & socket_ops::stream_oriented) != 0) if (o->bytes_transferred_ == 0) result = done_and_exhausted; BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recv", o->ec_, o->bytes_transferred_)); return result; } private: socket_type socket_; socket_ops::state_type state_; MutableBufferSequence buffers_; socket_base::message_flags flags_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class reactive_socket_recv_op : public reactive_socket_recv_op_base<MutableBufferSequence> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_recv_op); reactive_socket_recv_op(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : reactive_socket_recv_op_base<MutableBufferSequence>(success_ec, socket, state, buffers, flags, &reactive_socket_recv_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recv_op* o(static_cast<reactive_socket_recv_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); BOOST_ASIO_ERROR_LOCATION(o->ec_); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recv_op* o(static_cast<reactive_socket_recv_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. immediate_handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); BOOST_ASIO_ERROR_LOCATION(o->ec_); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_, io_ex); BOOST_ASIO_HANDLER_INVOCATION_END; } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECV_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_service.hpp
// // detail/reactive_socket_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 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 BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_IOCP) \ && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #include <boost/asio/buffer.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/reactive_null_buffers_op.hpp> #include <boost/asio/detail/reactive_socket_accept_op.hpp> #include <boost/asio/detail/reactive_socket_connect_op.hpp> #include <boost/asio/detail/reactive_socket_recvfrom_op.hpp> #include <boost/asio/detail/reactive_socket_sendto_op.hpp> #include <boost/asio/detail/reactive_socket_service_base.hpp> #include <boost/asio/detail/reactor.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_holder.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class reactive_socket_service : public execution_context_service_base<reactive_socket_service<Protocol>>, public reactive_socket_service_base { public: // The protocol type. typedef Protocol protocol_type; // The endpoint type. typedef typename Protocol::endpoint endpoint_type; // The native type of a socket. typedef socket_type native_handle_type; // The implementation type of the socket. struct implementation_type : reactive_socket_service_base::base_implementation_type { // Default constructor. implementation_type() : protocol_(endpoint_type().protocol()) { } // The protocol associated with the socket. protocol_type protocol_; }; // Constructor. reactive_socket_service(execution_context& context) : execution_context_service_base< reactive_socket_service<Protocol>>(context), reactive_socket_service_base(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { this->base_shutdown(); } // Move-construct a new socket implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept { this->base_move_construct(impl, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-assign from another socket implementation. void move_assign(implementation_type& impl, reactive_socket_service_base& other_service, implementation_type& other_impl) { this->base_move_assign(impl, other_service, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-construct a new socket implementation from another protocol type. template <typename Protocol1> void converting_move_construct(implementation_type& impl, reactive_socket_service<Protocol1>&, typename reactive_socket_service< Protocol1>::implementation_type& other_impl) { this->base_move_construct(impl, other_impl); impl.protocol_ = protocol_type(other_impl.protocol_); other_impl.protocol_ = typename Protocol1::endpoint().protocol(); } // Open a new socket implementation. boost::system::error_code open(implementation_type& impl, const protocol_type& protocol, boost::system::error_code& ec) { if (!do_open(impl, protocol.family(), protocol.type(), protocol.protocol(), ec)) impl.protocol_ = protocol; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Assign a native socket to a socket implementation. boost::system::error_code assign(implementation_type& impl, const protocol_type& protocol, const native_handle_type& native_socket, boost::system::error_code& ec) { if (!do_assign(impl, protocol.type(), native_socket, ec)) impl.protocol_ = protocol; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the native socket representation. native_handle_type native_handle(implementation_type& impl) { return impl.socket_; } // Bind the socket to the specified local endpoint. boost::system::error_code bind(implementation_type& impl, const endpoint_type& endpoint, boost::system::error_code& ec) { socket_ops::bind(impl.socket_, endpoint.data(), endpoint.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code set_option(implementation_type& impl, const Option& option, boost::system::error_code& ec) { socket_ops::setsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), option.size(impl.protocol_), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code get_option(const implementation_type& impl, Option& option, boost::system::error_code& ec) const { std::size_t size = option.size(impl.protocol_); socket_ops::getsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), &size, ec); if (!ec) option.resize(impl.protocol_, size); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the local endpoint. endpoint_type local_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getsockname(impl.socket_, endpoint.data(), &addr_len, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Get the remote endpoint. endpoint_type remote_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getpeername(impl.socket_, endpoint.data(), &addr_len, false, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Disable sends or receives on the socket. boost::system::error_code shutdown(base_implementation_type& impl, socket_base::shutdown_type what, boost::system::error_code& ec) { socket_ops::shutdown(impl.socket_, what, ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Send a datagram to the specified endpoint. Returns the number of bytes // sent. template <typename ConstBufferSequence> size_t send_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, socket_base::message_flags flags, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = socket_ops::sync_sendto1(impl.socket_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), flags, destination.data(), destination.size(), ec); } else { bufs_type bufs(buffers); n = socket_ops::sync_sendto(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, destination.data(), destination.size(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be sent without blocking. size_t send_to(implementation_type& impl, const null_buffers&, const endpoint_type&, socket_base::message_flags, boost::system::error_code& ec) { // Wait for socket to become ready. socket_ops::poll_write(impl.socket_, impl.state_, -1, ec); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous send. The data being sent must be valid for the // lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_send_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_sendto_op<ConstBufferSequence, endpoint_type, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.socket_, buffers, destination, flags, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_send_to")); start_op(impl, reactor::write_op, p.p, is_continuation, true, false, &io_ex, 0); p.v = p.p = 0; } // Start an asynchronous wait until data can be sent without blocking. template <typename Handler, typename IoExecutor> void async_send_to(implementation_type& impl, const null_buffers&, const endpoint_type&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_send_to(null_buffers)")); start_op(impl, reactor::write_op, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } // Receive a datagram with the endpoint of the sender. Returns the number of // bytes received. template <typename MutableBufferSequence> size_t receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endpoint, socket_base::message_flags flags, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; std::size_t addr_len = sender_endpoint.capacity(); std::size_t n; if (bufs_type::is_single_buffer) { n = socket_ops::sync_recvfrom1(impl.socket_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), flags, sender_endpoint.data(), &addr_len, ec); } else { bufs_type bufs(buffers); n = socket_ops::sync_recvfrom(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, sender_endpoint.data(), &addr_len, ec); } if (!ec) sender_endpoint.resize(addr_len); BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be received without blocking. size_t receive_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, socket_base::message_flags, boost::system::error_code& ec) { // Wait for socket to become ready. socket_ops::poll_read(impl.socket_, impl.state_, -1, ec); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous receive. The buffer for the data being received and // the sender_endpoint object must both be valid for the lifetime of the // asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endpoint, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_recvfrom_op<MutableBufferSequence, endpoint_type, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; int protocol = impl.protocol_.type(); p.p = new (p.v) op(success_ec_, impl.socket_, protocol, buffers, sender_endpoint, flags, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_receive_from")); start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, true, false, &io_ex, 0); p.v = p.p = 0; } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_receive_from(null_buffers)")); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } // Accept a new connection. template <typename Socket> boost::system::error_code accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, boost::system::error_code& ec) { // We cannot accept a socket that is already open. if (peer.is_open()) { ec = boost::asio::error::already_open; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } std::size_t addr_len = peer_endpoint ? peer_endpoint->capacity() : 0; socket_holder new_socket(socket_ops::sync_accept(impl.socket_, impl.state_, peer_endpoint ? peer_endpoint->data() : 0, peer_endpoint ? &addr_len : 0, ec)); // On success, assign new connection to peer socket object. if (new_socket.get() != invalid_socket) { if (peer_endpoint) peer_endpoint->resize(addr_len); peer.assign(impl.protocol_, new_socket.get(), ec); if (!ec) new_socket.release(); } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Start an asynchronous accept. The peer and peer_endpoint objects must be // valid until the accept's handler is invoked. template <typename Socket, typename Handler, typename IoExecutor> void async_accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_accept_op<Socket, Protocol, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.socket_, impl.state_, peer, impl.protocol_, peer_endpoint, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected() && !peer.is_open()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_accept")); start_accept_op(impl, p.p, is_continuation, peer.is_open(), &io_ex, 0); p.v = p.p = 0; } // Start an asynchronous accept. The peer_endpoint object must be valid until // the accept's handler is invoked. template <typename PeerIoExecutor, typename Handler, typename IoExecutor> void async_move_accept(implementation_type& impl, const PeerIoExecutor& peer_io_ex, endpoint_type* peer_endpoint, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_move_accept_op<Protocol, PeerIoExecutor, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, peer_io_ex, impl.socket_, impl.state_, impl.protocol_, peer_endpoint, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_accept")); start_accept_op(impl, p.p, is_continuation, false, &io_ex, 0); p.v = p.p = 0; } // Connect the socket to the specified endpoint. boost::system::error_code connect(implementation_type& impl, const endpoint_type& peer_endpoint, boost::system::error_code& ec) { socket_ops::sync_connect(impl.socket_, peer_endpoint.data(), peer_endpoint.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Start an asynchronous connect. template <typename Handler, typename IoExecutor> void async_connect(implementation_type& impl, const endpoint_type& peer_endpoint, Handler& handler, const IoExecutor& io_ex) { bool is_continuation = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_connect_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.socket_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::connect_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_connect")); start_connect_op(impl, p.p, is_continuation, peer_endpoint.data(), peer_endpoint.size(), &io_ex, 0); p.v = p.p = 0; } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_HAS_IOCP) // && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_handle_write_op.hpp
// // detail/win_iocp_handle_write_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // 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 BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class win_iocp_handle_write_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_handle_write_op); win_iocp_handle_write_op(const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_handle_write_op::do_complete), buffers_(buffers), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& result_ec, std::size_t bytes_transferred) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_handle_write_op* o(static_cast<win_iocp_handle_write_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Take ownership of the operation's outstanding work. handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) if (owner) { // Check whether buffers are still valid. buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) BOOST_ASIO_ERROR_LOCATION(ec); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, boost::system::error_code, std::size_t> handler(o->handler_, ec, bytes_transferred); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: ConstBufferSequence buffers_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP
hpp