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