connect_pipe.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // impl/connect_pipe.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_IMPL_CONNECT_PIPE_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #if defined(ASIO_HAS_PIPE)
  17. #include "asio/connect_pipe.hpp"
  18. #include "asio/detail/throw_error.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. template <typename Executor1, typename Executor2>
  22. void connect_pipe(basic_readable_pipe<Executor1>& read_end,
  23. basic_writable_pipe<Executor2>& write_end)
  24. {
  25. asio::error_code ec;
  26. asio::connect_pipe(read_end, write_end, ec);
  27. asio::detail::throw_error(ec, "connect_pipe");
  28. }
  29. template <typename Executor1, typename Executor2>
  30. ASIO_SYNC_OP_VOID connect_pipe(basic_readable_pipe<Executor1>& read_end,
  31. basic_writable_pipe<Executor2>& write_end, asio::error_code& ec)
  32. {
  33. detail::native_pipe_handle p[2];
  34. detail::create_pipe(p, ec);
  35. if (ec)
  36. ASIO_SYNC_OP_VOID_RETURN(ec);
  37. read_end.assign(p[0], ec);
  38. if (ec)
  39. {
  40. detail::close_pipe(p[0]);
  41. detail::close_pipe(p[1]);
  42. ASIO_SYNC_OP_VOID_RETURN(ec);
  43. }
  44. write_end.assign(p[1], ec);
  45. if (ec)
  46. {
  47. asio::error_code temp_ec;
  48. read_end.close(temp_ec);
  49. detail::close_pipe(p[1]);
  50. ASIO_SYNC_OP_VOID_RETURN(ec);
  51. }
  52. ASIO_SYNC_OP_VOID_RETURN(ec);
  53. }
  54. } // namespace asio
  55. #include "asio/detail/pop_options.hpp"
  56. #endif // defined(ASIO_HAS_PIPE)
  57. #endif // ASIO_IMPL_CONNECT_PIPE_HPP