Chris@16
|
1 //
|
Chris@16
|
2 // local/detail/endpoint.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 // Derived from a public domain implementation written by Daniel Casimiro.
|
Chris@16
|
7 //
|
Chris@16
|
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
|
Chris@16
|
13 #define BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
|
Chris@16
|
22
|
Chris@16
|
23 #include <cstddef>
|
Chris@16
|
24 #include <string>
|
Chris@16
|
25 #include <boost/asio/detail/socket_types.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30 namespace asio {
|
Chris@16
|
31 namespace local {
|
Chris@16
|
32 namespace detail {
|
Chris@16
|
33
|
Chris@16
|
34 // Helper class for implementing a UNIX domain endpoint.
|
Chris@16
|
35 class endpoint
|
Chris@16
|
36 {
|
Chris@16
|
37 public:
|
Chris@16
|
38 // Default constructor.
|
Chris@16
|
39 BOOST_ASIO_DECL endpoint();
|
Chris@16
|
40
|
Chris@16
|
41 // Construct an endpoint using the specified path name.
|
Chris@16
|
42 BOOST_ASIO_DECL endpoint(const char* path_name);
|
Chris@16
|
43
|
Chris@16
|
44 // Construct an endpoint using the specified path name.
|
Chris@16
|
45 BOOST_ASIO_DECL endpoint(const std::string& path_name);
|
Chris@16
|
46
|
Chris@16
|
47 // Copy constructor.
|
Chris@16
|
48 endpoint(const endpoint& other)
|
Chris@16
|
49 : data_(other.data_),
|
Chris@16
|
50 path_length_(other.path_length_)
|
Chris@16
|
51 {
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@16
|
54 // Assign from another endpoint.
|
Chris@16
|
55 endpoint& operator=(const endpoint& other)
|
Chris@16
|
56 {
|
Chris@16
|
57 data_ = other.data_;
|
Chris@16
|
58 path_length_ = other.path_length_;
|
Chris@16
|
59 return *this;
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 // Get the underlying endpoint in the native type.
|
Chris@16
|
63 boost::asio::detail::socket_addr_type* data()
|
Chris@16
|
64 {
|
Chris@16
|
65 return &data_.base;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 // Get the underlying endpoint in the native type.
|
Chris@16
|
69 const boost::asio::detail::socket_addr_type* data() const
|
Chris@16
|
70 {
|
Chris@16
|
71 return &data_.base;
|
Chris@16
|
72 }
|
Chris@16
|
73
|
Chris@16
|
74 // Get the underlying size of the endpoint in the native type.
|
Chris@16
|
75 std::size_t size() const
|
Chris@16
|
76 {
|
Chris@16
|
77 return path_length_
|
Chris@16
|
78 + offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 // Set the underlying size of the endpoint in the native type.
|
Chris@16
|
82 BOOST_ASIO_DECL void resize(std::size_t size);
|
Chris@16
|
83
|
Chris@16
|
84 // Get the capacity of the endpoint in the native type.
|
Chris@16
|
85 std::size_t capacity() const
|
Chris@16
|
86 {
|
Chris@16
|
87 return sizeof(boost::asio::detail::sockaddr_un_type);
|
Chris@16
|
88 }
|
Chris@16
|
89
|
Chris@16
|
90 // Get the path associated with the endpoint.
|
Chris@16
|
91 BOOST_ASIO_DECL std::string path() const;
|
Chris@16
|
92
|
Chris@16
|
93 // Set the path associated with the endpoint.
|
Chris@16
|
94 BOOST_ASIO_DECL void path(const char* p);
|
Chris@16
|
95
|
Chris@16
|
96 // Set the path associated with the endpoint.
|
Chris@16
|
97 BOOST_ASIO_DECL void path(const std::string& p);
|
Chris@16
|
98
|
Chris@16
|
99 // Compare two endpoints for equality.
|
Chris@16
|
100 BOOST_ASIO_DECL friend bool operator==(
|
Chris@16
|
101 const endpoint& e1, const endpoint& e2);
|
Chris@16
|
102
|
Chris@16
|
103 // Compare endpoints for ordering.
|
Chris@16
|
104 BOOST_ASIO_DECL friend bool operator<(
|
Chris@16
|
105 const endpoint& e1, const endpoint& e2);
|
Chris@16
|
106
|
Chris@16
|
107 private:
|
Chris@16
|
108 // The underlying UNIX socket address.
|
Chris@16
|
109 union data_union
|
Chris@16
|
110 {
|
Chris@16
|
111 boost::asio::detail::socket_addr_type base;
|
Chris@16
|
112 boost::asio::detail::sockaddr_un_type local;
|
Chris@16
|
113 } data_;
|
Chris@16
|
114
|
Chris@16
|
115 // The length of the path associated with the endpoint.
|
Chris@16
|
116 std::size_t path_length_;
|
Chris@16
|
117
|
Chris@16
|
118 // Initialise with a specified path.
|
Chris@16
|
119 BOOST_ASIO_DECL void init(const char* path, std::size_t path_length);
|
Chris@16
|
120 };
|
Chris@16
|
121
|
Chris@16
|
122 } // namespace detail
|
Chris@16
|
123 } // namespace local
|
Chris@16
|
124 } // namespace asio
|
Chris@16
|
125 } // namespace boost
|
Chris@16
|
126
|
Chris@16
|
127 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
128
|
Chris@16
|
129 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
130 # include <boost/asio/local/detail/impl/endpoint.ipp>
|
Chris@16
|
131 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
132
|
Chris@16
|
133 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
|
Chris@16
|
134
|
Chris@16
|
135 #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
|