File indexing completed on 2025-01-18 09:54:51
0001
0002
0003
0004
0005 #ifndef CPPCORO_NET_IPV4_ENDPOINT_HPP_INCLUDED
0006 #define CPPCORO_NET_IPV4_ENDPOINT_HPP_INCLUDED
0007
0008 #include <cppcoro/net/ipv4_address.hpp>
0009
0010 #include <optional>
0011 #include <string>
0012 #include <string_view>
0013
0014 namespace cppcoro
0015 {
0016 namespace net
0017 {
0018 class ipv4_endpoint
0019 {
0020 public:
0021
0022
0023 ipv4_endpoint() noexcept
0024 : m_address()
0025 , m_port(0)
0026 {}
0027
0028 explicit ipv4_endpoint(ipv4_address address, std::uint16_t port = 0) noexcept
0029 : m_address(address)
0030 , m_port(port)
0031 {}
0032
0033 const ipv4_address& address() const noexcept { return m_address; }
0034
0035 std::uint16_t port() const noexcept { return m_port; }
0036
0037 std::string to_string() const;
0038
0039 static std::optional<ipv4_endpoint> from_string(std::string_view string) noexcept;
0040
0041 private:
0042
0043 ipv4_address m_address;
0044 std::uint16_t m_port;
0045
0046 };
0047
0048 inline bool operator==(const ipv4_endpoint& a, const ipv4_endpoint& b)
0049 {
0050 return a.address() == b.address() &&
0051 a.port() == b.port();
0052 }
0053
0054 inline bool operator!=(const ipv4_endpoint& a, const ipv4_endpoint& b)
0055 {
0056 return !(a == b);
0057 }
0058
0059 inline bool operator<(const ipv4_endpoint& a, const ipv4_endpoint& b)
0060 {
0061 return a.address() < b.address() ||
0062 (a.address() == b.address() && a.port() < b.port());
0063 }
0064
0065 inline bool operator>(const ipv4_endpoint& a, const ipv4_endpoint& b)
0066 {
0067 return b < a;
0068 }
0069
0070 inline bool operator<=(const ipv4_endpoint& a, const ipv4_endpoint& b)
0071 {
0072 return !(b < a);
0073 }
0074
0075 inline bool operator>=(const ipv4_endpoint& a, const ipv4_endpoint& b)
0076 {
0077 return !(a < b);
0078 }
0079 }
0080 }
0081
0082 #endif