connect_pipe.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // impl/connect_pipe.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
  11. #define BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_PIPE)
  17. #include <boost/asio/connect_pipe.hpp>
  18. #include <boost/asio/detail/throw_error.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. template <typename Executor1, typename Executor2>
  23. void connect_pipe(basic_readable_pipe<Executor1>& read_end,
  24. basic_writable_pipe<Executor2>& write_end)
  25. {
  26. boost::system::error_code ec;
  27. boost::asio::connect_pipe(read_end, write_end, ec);
  28. boost::asio::detail::throw_error(ec, "connect_pipe");
  29. }
  30. template <typename Executor1, typename Executor2>
  31. BOOST_ASIO_SYNC_OP_VOID connect_pipe(basic_readable_pipe<Executor1>& read_end,
  32. basic_writable_pipe<Executor2>& write_end, boost::system::error_code& ec)
  33. {
  34. detail::native_pipe_handle p[2];
  35. detail::create_pipe(p, ec);
  36. if (ec)
  37. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  38. read_end.assign(p[0], ec);
  39. if (ec)
  40. {
  41. detail::close_pipe(p[0]);
  42. detail::close_pipe(p[1]);
  43. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  44. }
  45. write_end.assign(p[1], ec);
  46. if (ec)
  47. {
  48. boost::system::error_code temp_ec;
  49. read_end.close(temp_ec);
  50. detail::close_pipe(p[1]);
  51. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  52. }
  53. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  54. }
  55. } // namespace asio
  56. } // namespace boost
  57. #include <boost/asio/detail/pop_options.hpp>
  58. #endif // defined(BOOST_ASIO_HAS_PIPE)
  59. #endif // BOOST_ASIO_IMPL_CONNECT_PIPE_HPP