2 // generic/detail/impl/endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 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_IMPL_ENDPOINT_IPP
12 #define BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
22 #include <boost/asio/detail/socket_ops.hpp>
23 #include <boost/asio/detail/throw_error.hpp>
24 #include <boost/asio/detail/throw_exception.hpp>
25 #include <boost/asio/error.hpp>
26 #include <boost/asio/generic/detail/endpoint.hpp>
28 #include <boost/asio/detail/push_options.hpp>
40 endpoint::endpoint(const void* sock_addr,
41 std::size_t sock_addr_size, int sock_protocol)
43 init(sock_addr, sock_addr_size, sock_protocol);
46 void endpoint::resize(std::size_t new_size)
48 if (new_size > sizeof(boost::asio::detail::sockaddr_storage_type))
50 boost::system::error_code ec(boost::asio::error::invalid_argument);
51 boost::asio::detail::throw_error(ec);
60 bool operator==(const endpoint& e1, const endpoint& e2)
62 using namespace std; // For memcmp.
63 return e1.size() == e2.size() && memcmp(e1.data(), e2.data(), e1.size()) == 0;
66 bool operator<(const endpoint& e1, const endpoint& e2)
68 if (e1.protocol() < e2.protocol())
71 if (e1.protocol() > e2.protocol())
74 using namespace std; // For memcmp.
75 std::size_t compare_size = e1.size() < e2.size() ? e1.size() : e2.size();
76 int compare_result = memcmp(e1.data(), e2.data(), compare_size);
78 if (compare_result < 0)
81 if (compare_result > 0)
84 return e1.size() < e2.size();
87 void endpoint::init(const void* sock_addr,
88 std::size_t sock_addr_size, int sock_protocol)
90 if (sock_addr_size > sizeof(boost::asio::detail::sockaddr_storage_type))
92 boost::system::error_code ec(boost::asio::error::invalid_argument);
93 boost::asio::detail::throw_error(ec);
96 using namespace std; // For memset and memcpy.
97 memset(&data_.generic, 0, sizeof(boost::asio::detail::sockaddr_storage_type));
98 if (sock_addr_size > 0)
99 memcpy(&data_.generic, sock_addr, sock_addr_size);
101 size_ = sock_addr_size;
102 protocol_ = sock_protocol;
105 } // namespace detail
106 } // namespace generic
110 #include <boost/asio/detail/pop_options.hpp>
112 #endif // BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP