async_handler.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * async_handler.hpp
  3. *
  4. * Created on: 12.06.2016
  5. * Author: Klemens
  6. */
  7. #ifndef BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_
  8. #define BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_
  9. #include <type_traits>
  10. #if defined(BOOST_POSIX_API)
  11. #include <boost/process/posix.hpp>
  12. #include <boost/process/detail/posix/async_handler.hpp>
  13. #include <boost/process/detail/posix/asio_fwd.hpp>
  14. #else
  15. #include <boost/process/detail/windows/async_handler.hpp>
  16. #include <boost/process/detail/windows/asio_fwd.hpp>
  17. #endif
  18. namespace boost {
  19. namespace process {
  20. namespace detail {
  21. #if defined(BOOST_POSIX_API)
  22. using ::boost::process::detail::posix::is_async_handler;
  23. using ::boost::process::detail::posix::does_require_io_context;
  24. #else
  25. using ::boost::process::detail::windows::is_async_handler;
  26. using ::boost::process::detail::windows::does_require_io_context;
  27. #endif
  28. template<typename ...Args>
  29. struct has_io_context;
  30. template<typename T, typename ...Args>
  31. struct has_io_context<T, Args...>
  32. {
  33. typedef typename has_io_context<Args...>::type next;
  34. typedef typename std::is_same<
  35. typename std::remove_reference<T>::type,
  36. boost::asio::io_context>::type is_ios;
  37. typedef typename std::conditional<is_ios::value,
  38. std::true_type,
  39. next>::type type;
  40. };
  41. template<typename T>
  42. struct has_io_context<T>
  43. {
  44. typedef typename std::is_same<
  45. typename std::remove_reference<T>::type,
  46. boost::asio::io_context>::type type;
  47. };
  48. template<typename ...Args>
  49. using has_io_context_t = typename has_io_context<Args...>::type;
  50. template<typename ...Args>
  51. struct has_async_handler;
  52. template<typename T, typename ...Args>
  53. struct has_async_handler<T, Args...>
  54. {
  55. typedef typename has_async_handler<Args...>::type next;
  56. typedef typename is_async_handler<T>::type is_ios;
  57. typedef typename std::conditional<is_ios::value,
  58. std::true_type,
  59. next>::type type;
  60. };
  61. template<typename T>
  62. struct has_async_handler<T>
  63. {
  64. typedef typename is_async_handler<T>::type type;
  65. };
  66. template<typename ...Args>
  67. struct needs_io_context;
  68. template<typename T, typename ...Args>
  69. struct needs_io_context<T, Args...>
  70. {
  71. typedef typename needs_io_context<Args...>::type next;
  72. typedef typename does_require_io_context<T>::type is_ios;
  73. typedef typename std::conditional<is_ios::value,
  74. std::true_type,
  75. next>::type type;
  76. };
  77. template<typename T>
  78. struct needs_io_context<T>
  79. {
  80. typedef typename does_require_io_context<T>::type type;
  81. };
  82. template<typename ...Args>
  83. boost::asio::io_context &get_io_context_var(boost::asio::io_context & f, Args&...)
  84. {
  85. return f;
  86. }
  87. template<typename First, typename ...Args>
  88. boost::asio::io_context &get_io_context_var(First&, Args&...args)
  89. {
  90. return get_io_context_var(args...);
  91. }
  92. }
  93. }
  94. }
  95. #endif /* BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_ */