Boost Asio总结(14)class basic_endpoint

Posted thefist11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Boost Asio总结(14)class basic_endpoint相关的知识,希望对你有一定的参考价值。

1. 设置address,port

boost\\asio\\ip\\basic_endpoint.hpp

template <typename InternetProtocol>
class basic_endpoint

public:
  /// The protocol type associated with the endpoint.
  typedef InternetProtocol protocol_type;

  basic_endpoint(const InternetProtocol& internet_protocol,
      unsigned short port_num) BOOST_ASIO_NOEXCEPT
    : impl_(internet_protocol.family(), port_num)
  
  

  /// Construct an endpoint using a port number and an IP address. This
  /// constructor may be used for accepting connections on a specific interface
  /// or for making a connection to a remote endpoint.
  basic_endpoint(const boost::asio::ip::address& addr,
      unsigned short port_num) BOOST_ASIO_NOEXCEPT
    : impl_(addr, port_num)
  
  

 /// The protocol associated with the endpoint.
  protocol_type protocol() const BOOST_ASIO_NOEXCEPT
  
    if (impl_.is_v4())
      return InternetProtocol::v4();
    return InternetProtocol::v6();
  

  /// Get the underlying endpoint in the native type.
  data_type* data() BOOST_ASIO_NOEXCEPT
  
    return impl_.data();
  

  /// Get the underlying endpoint in the native type.
  const data_type* data() const BOOST_ASIO_NOEXCEPT
  
    return impl_.data();
  

  /// Get the underlying size of the endpoint in the native type.
  std::size_t size() const BOOST_ASIO_NOEXCEPT
  
    return impl_.size();
  

  unsigned short port() const BOOST_ASIO_NOEXCEPT
  
    return impl_.port();
  

  /// Set the port associated with the endpoint. The port number is always in
  /// the host's byte order.
  void port(unsigned short port_num) BOOST_ASIO_NOEXCEPT
  
    impl_.port(port_num);
  

  /// Get the IP address associated with the endpoint.
  boost::asio::ip::address address() const BOOST_ASIO_NOEXCEPT
  
    return impl_.address();
  

  /// Set the IP address associated with the endpoint.
  void address(const boost::asio::ip::address& addr) BOOST_ASIO_NOEXCEPT
  
    impl_.address(addr);
  
private:
  // The underlying IP endpoint.
  boost::asio::ip::detail::endpoint impl_;
;





以上是关于Boost Asio总结(14)class basic_endpoint的主要内容,如果未能解决你的问题,请参考以下文章

Boost Asio总结class work

Boost Asio总结class tcp

Boost Asio总结class strand

Boost Asio总结(15)class basic_stream_socket

Boost Asio总结数据缓冲区class mutable_buffer和const_buffer

Boost Asio总结(16)例子