// // local/connect_pair.hpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2018 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 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ || defined(GENERATING_DOCUMENTATION) #include #include #include #include #include #include namespace lslboost { namespace asio { namespace local { /// Create a pair of connected sockets. template void connect_pair( basic_socket& socket1, basic_socket& socket2); /// Create a pair of connected sockets. template BOOST_ASIO_SYNC_OP_VOID connect_pair( basic_socket& socket1, basic_socket& socket2, lslboost::system::error_code& ec); template inline void connect_pair( basic_socket& socket1, basic_socket& socket2) { lslboost::system::error_code ec; connect_pair(socket1, socket2, ec); lslboost::asio::detail::throw_error(ec, "connect_pair"); } template inline BOOST_ASIO_SYNC_OP_VOID connect_pair( basic_socket& socket1, basic_socket& socket2, lslboost::system::error_code& ec) { // Check that this function is only being used with a UNIX domain socket. lslboost::asio::local::basic_endpoint* tmp = static_cast(0); (void)tmp; Protocol protocol; lslboost::asio::detail::socket_type sv[2]; if (lslboost::asio::detail::socket_ops::socketpair(protocol.family(), protocol.type(), protocol.protocol(), sv, ec) == lslboost::asio::detail::socket_error_retval) BOOST_ASIO_SYNC_OP_VOID_RETURN(ec); socket1.assign(protocol, sv[0], ec); if (ec) { lslboost::system::error_code temp_ec; lslboost::asio::detail::socket_ops::state_type state[2] = { 0, 0 }; lslboost::asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec); lslboost::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) { lslboost::system::error_code temp_ec; socket1.close(temp_ec); lslboost::asio::detail::socket_ops::state_type state = 0; lslboost::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 lslboost #include #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) // || defined(GENERATING_DOCUMENTATION) #endif // BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP