2 // generic/detail/endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP
12 #define BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
21 #include <boost/asio/detail/socket_types.hpp>
23 #include <boost/asio/detail/push_options.hpp>
30 // Helper class for implementing a generic socket endpoint.
34 // Default constructor.
35 BOOST_ASIO_DECL endpoint();
37 // Construct an endpoint from the specified raw bytes.
38 BOOST_ASIO_DECL endpoint(const void* sock_addr,
39 std::size_t sock_addr_size, int sock_protocol);
42 endpoint(const endpoint& other)
45 protocol_(other.protocol_)
49 // Assign from another endpoint.
50 endpoint& operator=(const endpoint& other)
54 protocol_ = other.protocol_;
58 // Get the address family associated with the endpoint.
61 return data_.base.sa_family;
64 // Get the socket protocol associated with the endpoint.
70 // Get the underlying endpoint in the native type.
71 boost::asio::detail::socket_addr_type* data()
76 // Get the underlying endpoint in the native type.
77 const boost::asio::detail::socket_addr_type* data() const
82 // Get the underlying size of the endpoint in the native type.
83 std::size_t size() const
88 // Set the underlying size of the endpoint in the native type.
89 BOOST_ASIO_DECL void resize(std::size_t size);
91 // Get the capacity of the endpoint in the native type.
92 std::size_t capacity() const
94 return sizeof(boost::asio::detail::sockaddr_storage_type);
97 // Compare two endpoints for equality.
98 BOOST_ASIO_DECL friend bool operator==(
99 const endpoint& e1, const endpoint& e2);
101 // Compare endpoints for ordering.
102 BOOST_ASIO_DECL friend bool operator<(
103 const endpoint& e1, const endpoint& e2);
106 // The underlying socket address.
109 boost::asio::detail::socket_addr_type base;
110 boost::asio::detail::sockaddr_storage_type generic;
113 // The length of the socket address stored in the endpoint.
116 // The socket protocol associated with the endpoint.
119 // Initialise with a specified memory.
120 BOOST_ASIO_DECL void init(const void* sock_addr,
121 std::size_t sock_addr_size, int sock_protocol);
124 } // namespace detail
125 } // namespace generic
129 #include <boost/asio/detail/pop_options.hpp>
131 #if defined(BOOST_ASIO_HEADER_ONLY)
132 # include <boost/asio/generic/detail/impl/endpoint.ipp>
133 #endif // defined(BOOST_ASIO_HEADER_ONLY)
135 #endif // BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP