Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:55

0001 //
0002 // impl/connect_pipe.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
0012 #define BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if defined(BOOST_ASIO_HAS_PIPE)
0021 
0022 #include <boost/asio/connect_pipe.hpp>
0023 #include <boost/asio/detail/throw_error.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 
0030 template <typename Executor1, typename Executor2>
0031 void connect_pipe(basic_readable_pipe<Executor1>& read_end,
0032     basic_writable_pipe<Executor2>& write_end)
0033 {
0034   boost::system::error_code ec;
0035   boost::asio::connect_pipe(read_end, write_end, ec);
0036   boost::asio::detail::throw_error(ec, "connect_pipe");
0037 }
0038 
0039 template <typename Executor1, typename Executor2>
0040 BOOST_ASIO_SYNC_OP_VOID connect_pipe(basic_readable_pipe<Executor1>& read_end,
0041     basic_writable_pipe<Executor2>& write_end, boost::system::error_code& ec)
0042 {
0043   detail::native_pipe_handle p[2];
0044   detail::create_pipe(p, ec);
0045   if (ec)
0046     BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
0047 
0048   read_end.assign(p[0], ec);
0049   if (ec)
0050   {
0051     detail::close_pipe(p[0]);
0052     detail::close_pipe(p[1]);
0053     BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
0054   }
0055 
0056   write_end.assign(p[1], ec);
0057   if (ec)
0058   {
0059     boost::system::error_code temp_ec;
0060     read_end.close(temp_ec);
0061     detail::close_pipe(p[1]);
0062     BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
0063   }
0064 
0065   BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
0066 }
0067 
0068 } // namespace asio
0069 } // namespace boost
0070 
0071 #include <boost/asio/detail/pop_options.hpp>
0072 
0073 #endif // defined(BOOST_ASIO_HAS_PIPE)
0074 
0075 #endif // BOOST_ASIO_IMPL_CONNECT_PIPE_HPP