]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/generic/detail/impl/endpoint.ipp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / generic / detail / impl / endpoint.ipp
CommitLineData
7c673cae
FG
1//
2// generic/detail/impl/endpoint.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 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_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
12#define BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
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#include <cstring>
21#include <typeinfo>
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>
27
28#include <boost/asio/detail/push_options.hpp>
29
30namespace boost {
31namespace asio {
32namespace generic {
33namespace detail {
34
35endpoint::endpoint()
36{
37 init(0, 0, 0);
38}
39
40endpoint::endpoint(const void* sock_addr,
41 std::size_t sock_addr_size, int sock_protocol)
42{
43 init(sock_addr, sock_addr_size, sock_protocol);
44}
45
46void endpoint::resize(std::size_t new_size)
47{
48 if (new_size > sizeof(boost::asio::detail::sockaddr_storage_type))
49 {
50 boost::system::error_code ec(boost::asio::error::invalid_argument);
51 boost::asio::detail::throw_error(ec);
52 }
53 else
54 {
55 size_ = new_size;
56 protocol_ = 0;
57 }
58}
59
60bool operator==(const endpoint& e1, const endpoint& e2)
61{
62 using namespace std; // For memcmp.
63 return e1.size() == e2.size() && memcmp(e1.data(), e2.data(), e1.size()) == 0;
64}
65
66bool operator<(const endpoint& e1, const endpoint& e2)
67{
68 if (e1.protocol() < e2.protocol())
69 return true;
70
71 if (e1.protocol() > e2.protocol())
72 return false;
73
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);
77
78 if (compare_result < 0)
79 return true;
80
81 if (compare_result > 0)
82 return false;
83
84 return e1.size() < e2.size();
85}
86
87void endpoint::init(const void* sock_addr,
88 std::size_t sock_addr_size, int sock_protocol)
89{
90 if (sock_addr_size > sizeof(boost::asio::detail::sockaddr_storage_type))
91 {
92 boost::system::error_code ec(boost::asio::error::invalid_argument);
93 boost::asio::detail::throw_error(ec);
94 }
95
96 using namespace std; // For memset and memcpy.
97 memset(&data_.generic, 0, sizeof(boost::asio::detail::sockaddr_storage_type));
b32b8144
FG
98 if (sock_addr_size > 0)
99 memcpy(&data_.generic, sock_addr, sock_addr_size);
7c673cae
FG
100
101 size_ = sock_addr_size;
102 protocol_ = sock_protocol;
103}
104
105} // namespace detail
106} // namespace generic
107} // namespace asio
108} // namespace boost
109
110#include <boost/asio/detail/pop_options.hpp>
111
112#endif // BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP