connect_pair.hpp
Go to the documentation of this file.
00001 //
00002 // connect_pair.hpp
00003 // ~~~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef ASIO_LOCAL_CONNECT_PAIR_HPP
00012 #define ASIO_LOCAL_CONNECT_PAIR_HPP
00013 
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017 
00018 #include "asio/detail/push_options.hpp"
00019 
00020 #include "asio/basic_socket.hpp"
00021 #include "asio/error.hpp"
00022 #include "asio/local/basic_endpoint.hpp"
00023 #include "asio/detail/socket_ops.hpp"
00024 #include "asio/detail/throw_error.hpp"
00025 
00026 #if defined(ASIO_HAS_LOCAL_SOCKETS) \
00027   || defined(GENERATING_DOCUMENTATION)
00028 
00029 namespace asio {
00030 namespace local {
00031 
00033 template <typename Protocol, typename SocketService1, typename SocketService2>
00034 void connect_pair(
00035     basic_socket<Protocol, SocketService1>& socket1,
00036     basic_socket<Protocol, SocketService2>& socket2);
00037 
00039 template <typename Protocol, typename SocketService1, typename SocketService2>
00040 asio::error_code connect_pair(
00041     basic_socket<Protocol, SocketService1>& socket1,
00042     basic_socket<Protocol, SocketService2>& socket2,
00043     asio::error_code& ec);
00044 
00045 template <typename Protocol, typename SocketService1, typename SocketService2>
00046 inline void connect_pair(
00047     basic_socket<Protocol, SocketService1>& socket1,
00048     basic_socket<Protocol, SocketService2>& socket2)
00049 {
00050   asio::error_code ec;
00051   connect_pair(socket1, socket2, ec);
00052   asio::detail::throw_error(ec);
00053 }
00054 
00055 template <typename Protocol, typename SocketService1, typename SocketService2>
00056 inline asio::error_code connect_pair(
00057     basic_socket<Protocol, SocketService1>& socket1,
00058     basic_socket<Protocol, SocketService2>& socket2,
00059     asio::error_code& ec)
00060 {
00061   // Check that this function is only being used with a UNIX domain socket.
00062   asio::local::basic_endpoint<Protocol>* tmp
00063     = static_cast<typename Protocol::endpoint*>(0);
00064   (void)tmp;
00065 
00066   Protocol protocol;
00067   asio::detail::socket_type sv[2];
00068   if (asio::detail::socket_ops::socketpair(protocol.family(),
00069         protocol.type(), protocol.protocol(), sv, ec)
00070       == asio::detail::socket_error_retval)
00071     return ec;
00072 
00073   if (socket1.assign(protocol, sv[0], ec))
00074   {
00075     asio::error_code temp_ec;
00076     asio::detail::socket_ops::close(sv[0], temp_ec);
00077     asio::detail::socket_ops::close(sv[1], temp_ec);
00078     return ec;
00079   }
00080 
00081   if (socket2.assign(protocol, sv[1], ec))
00082   {
00083     asio::error_code temp_ec;
00084     socket1.close(temp_ec);
00085     asio::detail::socket_ops::close(sv[1], temp_ec);
00086     return ec;
00087   }
00088 
00089   return ec;
00090 }
00091 
00092 } // namespace local
00093 } // namespace asio
00094 
00095 #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
00096        //   || defined(GENERATING_DOCUMENTATION)
00097 
00098 #include "asio/detail/pop_options.hpp"
00099 
00100 #endif // ASIO_LOCAL_CONNECT_PAIR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39