]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/local/connect_pair.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / asio / local / connect_pair.hpp
CommitLineData
7c673cae
FG
1//
2// local/connect_pair.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~
4//
1e59de90 5// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
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 BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP
12#define BOOST_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 <boost/asio/detail/config.hpp>
19
20#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
21 || defined(GENERATING_DOCUMENTATION)
22
23#include <boost/asio/basic_socket.hpp>
24#include <boost/asio/detail/socket_ops.hpp>
25#include <boost/asio/detail/throw_error.hpp>
26#include <boost/asio/error.hpp>
27#include <boost/asio/local/basic_endpoint.hpp>
28
29#include <boost/asio/detail/push_options.hpp>
30
31namespace boost {
32namespace asio {
33namespace local {
34
35/// Create a pair of connected sockets.
92f5a8d4
TL
36template <typename Protocol, typename Executor1, typename Executor2>
37void connect_pair(basic_socket<Protocol, Executor1>& socket1,
38 basic_socket<Protocol, Executor2>& socket2);
7c673cae
FG
39
40/// Create a pair of connected sockets.
92f5a8d4
TL
41template <typename Protocol, typename Executor1, typename Executor2>
42BOOST_ASIO_SYNC_OP_VOID connect_pair(basic_socket<Protocol, Executor1>& socket1,
43 basic_socket<Protocol, Executor2>& socket2, boost::system::error_code& ec);
7c673cae 44
92f5a8d4
TL
45template <typename Protocol, typename Executor1, typename Executor2>
46inline void connect_pair(basic_socket<Protocol, Executor1>& socket1,
47 basic_socket<Protocol, Executor2>& socket2)
7c673cae
FG
48{
49 boost::system::error_code ec;
50 connect_pair(socket1, socket2, ec);
51 boost::asio::detail::throw_error(ec, "connect_pair");
52}
53
92f5a8d4 54template <typename Protocol, typename Executor1, typename Executor2>
b32b8144 55inline BOOST_ASIO_SYNC_OP_VOID connect_pair(
92f5a8d4
TL
56 basic_socket<Protocol, Executor1>& socket1,
57 basic_socket<Protocol, Executor2>& socket2, boost::system::error_code& ec)
7c673cae
FG
58{
59 // Check that this function is only being used with a UNIX domain socket.
60 boost::asio::local::basic_endpoint<Protocol>* tmp
61 = static_cast<typename Protocol::endpoint*>(0);
62 (void)tmp;
63
64 Protocol protocol;
65 boost::asio::detail::socket_type sv[2];
66 if (boost::asio::detail::socket_ops::socketpair(protocol.family(),
67 protocol.type(), protocol.protocol(), sv, ec)
68 == boost::asio::detail::socket_error_retval)
b32b8144 69 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
7c673cae 70
b32b8144
FG
71 socket1.assign(protocol, sv[0], ec);
72 if (ec)
7c673cae
FG
73 {
74 boost::system::error_code temp_ec;
75 boost::asio::detail::socket_ops::state_type state[2] = { 0, 0 };
76 boost::asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec);
77 boost::asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec);
b32b8144 78 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
7c673cae
FG
79 }
80
b32b8144
FG
81 socket2.assign(protocol, sv[1], ec);
82 if (ec)
7c673cae
FG
83 {
84 boost::system::error_code temp_ec;
85 socket1.close(temp_ec);
86 boost::asio::detail::socket_ops::state_type state = 0;
87 boost::asio::detail::socket_ops::close(sv[1], state, true, temp_ec);
b32b8144 88 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
7c673cae
FG
89 }
90
b32b8144 91 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
7c673cae
FG
92}
93
94} // namespace local
95} // namespace asio
96} // namespace boost
97
98#include <boost/asio/detail/pop_options.hpp>
99
100#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
101 // || defined(GENERATING_DOCUMENTATION)
102
103#endif // BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP