Realistic 3D camera system
3D camera system components
connect_pair.hpp
Go to the documentation of this file.
1 //
2 // local/connect_pair.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 
11 #ifndef ASIO_LOCAL_CONNECT_PAIR_HPP
12 #define ASIO_LOCAL_CONNECT_PAIR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_HAS_LOCAL_SOCKETS) \
21  || defined(GENERATING_DOCUMENTATION)
22 
23 #include "asio/basic_socket.hpp"
26 #include "asio/error.hpp"
28 
30 
31 namespace asio {
32 namespace local {
33 
35 template <typename Protocol, typename SocketService1, typename SocketService2>
36 void connect_pair(
37  basic_socket<Protocol, SocketService1>& socket1,
38  basic_socket<Protocol, SocketService2>& socket2);
39 
41 template <typename Protocol, typename SocketService1, typename SocketService2>
42 asio::error_code connect_pair(
43  basic_socket<Protocol, SocketService1>& socket1,
44  basic_socket<Protocol, SocketService2>& socket2,
45  asio::error_code& ec);
46 
47 template <typename Protocol, typename SocketService1, typename SocketService2>
48 inline void connect_pair(
49  basic_socket<Protocol, SocketService1>& socket1,
50  basic_socket<Protocol, SocketService2>& socket2)
51 {
53  connect_pair(socket1, socket2, ec);
54  asio::detail::throw_error(ec, "connect_pair");
55 }
56 
57 template <typename Protocol, typename SocketService1, typename SocketService2>
58 inline asio::error_code connect_pair(
59  basic_socket<Protocol, SocketService1>& socket1,
60  basic_socket<Protocol, SocketService2>& socket2,
61  asio::error_code& ec)
62 {
63  // Check that this function is only being used with a UNIX domain socket.
64  asio::local::basic_endpoint<Protocol>* tmp
65  = static_cast<typename Protocol::endpoint*>(0);
66  (void)tmp;
67 
68  Protocol protocol;
70  if (asio::detail::socket_ops::socketpair(protocol.family(),
71  protocol.type(), protocol.protocol(), sv, ec)
73  return ec;
74 
75  if (socket1.assign(protocol, sv[0], ec))
76  {
77  asio::error_code temp_ec;
78  asio::detail::socket_ops::state_type state[2] = { 0, 0 };
79  asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec);
80  asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec);
81  return ec;
82  }
83 
84  if (socket2.assign(protocol, sv[1], ec))
85  {
86  asio::error_code temp_ec;
87  socket1.close(temp_ec);
89  asio::detail::socket_ops::close(sv[1], state, true, temp_ec);
90  return ec;
91  }
92 
93  return ec;
94 }
95 
96 } // namespace local
97 } // namespace asio
98 
100 
101 #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
102  // || defined(GENERATING_DOCUMENTATION)
103 
104 #endif // ASIO_LOCAL_CONNECT_PAIR_HPP
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
int socketpair(int af, int type, int protocol, socket_type sv[2], asio::error_code &ec)
Definition: socket_ops.ipp:611
unsigned char state_type
Definition: socket_ops.hpp:59
Class to represent an error code value.
Definition: error_code.hpp:80
const int socket_error_retval
int close(socket_type s, state_type &state, bool destruction, asio::error_code &ec)
Definition: socket_ops.ipp:295