Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:53

0001 //
0002 // generic/detail/impl/endpoint.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
0012 #define BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <cstring>
0021 #include <typeinfo>
0022 #include <boost/asio/detail/socket_ops.hpp>
0023 #include <boost/asio/detail/throw_error.hpp>
0024 #include <boost/asio/detail/throw_exception.hpp>
0025 #include <boost/asio/error.hpp>
0026 #include <boost/asio/generic/detail/endpoint.hpp>
0027 
0028 #include <boost/asio/detail/push_options.hpp>
0029 
0030 namespace boost {
0031 namespace asio {
0032 namespace generic {
0033 namespace detail {
0034 
0035 endpoint::endpoint()
0036 {
0037   init(0, 0, 0);
0038 }
0039 
0040 endpoint::endpoint(const void* sock_addr,
0041     std::size_t sock_addr_size, int sock_protocol)
0042 {
0043   init(sock_addr, sock_addr_size, sock_protocol);
0044 }
0045 
0046 void endpoint::resize(std::size_t new_size)
0047 {
0048   if (new_size > sizeof(boost::asio::detail::sockaddr_storage_type))
0049   {
0050     boost::system::error_code ec(boost::asio::error::invalid_argument);
0051     boost::asio::detail::throw_error(ec);
0052   }
0053   else
0054   {
0055     size_ = new_size;
0056     protocol_ = 0;
0057   }
0058 }
0059 
0060 bool operator==(const endpoint& e1, const endpoint& e2)
0061 {
0062   using namespace std; // For memcmp.
0063   return e1.size() == e2.size() && memcmp(e1.data(), e2.data(), e1.size()) == 0;
0064 }
0065 
0066 bool operator<(const endpoint& e1, const endpoint& e2)
0067 {
0068   if (e1.protocol() < e2.protocol())
0069     return true;
0070 
0071   if (e1.protocol() > e2.protocol())
0072     return false;
0073 
0074   using namespace std; // For memcmp.
0075   std::size_t compare_size = e1.size() < e2.size() ? e1.size() : e2.size();
0076   int compare_result = memcmp(e1.data(), e2.data(), compare_size);
0077 
0078   if (compare_result < 0)
0079     return true;
0080 
0081   if (compare_result > 0)
0082     return false;
0083 
0084   return e1.size() < e2.size();
0085 }
0086 
0087 void endpoint::init(const void* sock_addr,
0088     std::size_t sock_addr_size, int sock_protocol)
0089 {
0090   if (sock_addr_size > sizeof(boost::asio::detail::sockaddr_storage_type))
0091   {
0092     boost::system::error_code ec(boost::asio::error::invalid_argument);
0093     boost::asio::detail::throw_error(ec);
0094   }
0095 
0096   using namespace std; // For memset and memcpy.
0097   memset(&data_.generic, 0, sizeof(boost::asio::detail::sockaddr_storage_type));
0098   if (sock_addr_size > 0)
0099     memcpy(&data_.generic, sock_addr, sock_addr_size);
0100 
0101   size_ = sock_addr_size;
0102   protocol_ = sock_protocol;
0103 }
0104 
0105 } // namespace detail
0106 } // namespace generic
0107 } // namespace asio
0108 } // namespace boost
0109 
0110 #include <boost/asio/detail/pop_options.hpp>
0111 
0112 #endif // BOOST_ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP