Chris@16: // Chris@16: // local/connect_pair.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP Chris@16: #define BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \ Chris@16: || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace local { Chris@16: Chris@16: /// Create a pair of connected sockets. Chris@16: template Chris@16: void connect_pair( Chris@16: basic_socket& socket1, Chris@16: basic_socket& socket2); Chris@16: Chris@16: /// Create a pair of connected sockets. Chris@16: template Chris@16: boost::system::error_code connect_pair( Chris@16: basic_socket& socket1, Chris@16: basic_socket& socket2, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: template Chris@16: inline void connect_pair( Chris@16: basic_socket& socket1, Chris@16: basic_socket& socket2) Chris@16: { Chris@16: boost::system::error_code ec; Chris@16: connect_pair(socket1, socket2, ec); Chris@16: boost::asio::detail::throw_error(ec, "connect_pair"); Chris@16: } Chris@16: Chris@16: template Chris@16: inline boost::system::error_code connect_pair( Chris@16: basic_socket& socket1, Chris@16: basic_socket& socket2, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: // Check that this function is only being used with a UNIX domain socket. Chris@16: boost::asio::local::basic_endpoint* tmp Chris@16: = static_cast(0); Chris@16: (void)tmp; Chris@16: Chris@16: Protocol protocol; Chris@16: boost::asio::detail::socket_type sv[2]; Chris@16: if (boost::asio::detail::socket_ops::socketpair(protocol.family(), Chris@16: protocol.type(), protocol.protocol(), sv, ec) Chris@16: == boost::asio::detail::socket_error_retval) Chris@16: return ec; Chris@16: Chris@16: if (socket1.assign(protocol, sv[0], ec)) Chris@16: { Chris@16: boost::system::error_code temp_ec; Chris@16: boost::asio::detail::socket_ops::state_type state[2] = { 0, 0 }; Chris@16: boost::asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec); Chris@16: boost::asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec); Chris@16: return ec; Chris@16: } Chris@16: Chris@16: if (socket2.assign(protocol, sv[1], ec)) Chris@16: { Chris@16: boost::system::error_code temp_ec; Chris@16: socket1.close(temp_ec); Chris@16: boost::asio::detail::socket_ops::state_type state = 0; Chris@16: boost::asio::detail::socket_ops::close(sv[1], state, true, temp_ec); Chris@16: return ec; Chris@16: } Chris@16: Chris@16: return ec; Chris@16: } Chris@16: Chris@16: } // namespace local Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) Chris@16: // || defined(GENERATING_DOCUMENTATION) Chris@16: Chris@16: #endif // BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP