Commit f0f4ee65 authored by Jakob Otto's avatar Jakob Otto

Add requested changes

parent 4bbc4e19
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace caf { namespace caf {
/// An IP endpoint that contains an ipv6_address and a port. /// An IP endpoint that contains an ::ipv6_address and a port.
using ip_endpoint = ipv6_endpoint; using ip_endpoint = ipv6_endpoint;
} // namespace caf } // namespace caf
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
#pragma once #pragma once
#include "caf/detail/comparable.hpp"
#include "caf/ipv4_address.hpp" #include "caf/ipv4_address.hpp"
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
namespace caf { namespace caf {
/// A hashable endpoint abstraction for ipv4 /// An IP endpoint that contains an ::ipv4_address and a port.
struct ipv4_endpoint : detail::comparable<ipv4_endpoint> { struct ipv4_endpoint : detail::comparable<ipv4_endpoint> {
public: public:
// -- constructors ----------------------------------------------------------- // -- constructors -----------------------------------------------------------
...@@ -53,8 +54,9 @@ public: ...@@ -53,8 +54,9 @@ public:
/// Returns a hash for this object /// Returns a hash for this object
size_t hash_code() const noexcept; size_t hash_code() const noexcept;
/// compares This endpoint to another. /// Compares this endpoint to `x`.
/// Returns 0 if equal, otherwise >0 if this > x and <0 if this < x /// @returns 0 if `*this == x`, a positive value if `*this > x` and a negative
/// value otherwise.
long compare(ipv4_endpoint x) const noexcept; long compare(ipv4_endpoint x) const noexcept;
template <class Inspector> template <class Inspector>
......
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
#pragma once #pragma once
#include "caf/detail/comparable.hpp"
#include "caf/ipv6_address.hpp" #include "caf/ipv6_address.hpp"
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
namespace caf { namespace caf {
/// A hashable endpoint abstraction for ipv6. /// An IP endpoint that contains an ::ipv6_address and a port.
struct ipv6_endpoint : detail::comparable<ipv6_endpoint> { struct ipv6_endpoint : detail::comparable<ipv6_endpoint> {
public: public:
// -- constructors ----------------------------------------------------------- // -- constructors -----------------------------------------------------------
...@@ -53,8 +54,9 @@ public: ...@@ -53,8 +54,9 @@ public:
/// Returns a hash for this object. /// Returns a hash for this object.
size_t hash_code() const noexcept; size_t hash_code() const noexcept;
/// compares This endpoint to another. /// Compares this endpoint to `x`.
/// Returns 0 if equal, otherwise >0 if this > x and <0 if this < x. /// @returns 0 if `*this == x`, a positive value if `*this > x` and a negative
/// value otherwise.
long compare(ipv6_endpoint x) const noexcept; long compare(ipv6_endpoint x) const noexcept;
template <class Inspector> template <class Inspector>
...@@ -64,8 +66,10 @@ public: ...@@ -64,8 +66,10 @@ public:
} }
private: private:
ipv6_address address_; /// The address of this endpoint. /// The address of this endpoint.
uint16_t port_; /// The port of this endpoint. ipv6_address address_;
/// The port of this endpoint.
uint16_t port_;
}; };
std::string to_string(const ipv6_endpoint& ep); std::string to_string(const ipv6_endpoint& ep);
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
#include "caf/detail/fnv_hash.hpp" #include "caf/detail/fnv_hash.hpp"
using caf::detail::fnv_hash;
using caf::detail::fnv_hash_append;
namespace caf { namespace caf {
ipv4_endpoint::ipv4_endpoint(ipv4_address address, uint16_t port) ipv4_endpoint::ipv4_endpoint(ipv4_address address, uint16_t port)
...@@ -47,16 +44,13 @@ void ipv4_endpoint::port(uint16_t x) noexcept { ...@@ -47,16 +44,13 @@ void ipv4_endpoint::port(uint16_t x) noexcept {
} }
size_t ipv4_endpoint::hash_code() const noexcept { size_t ipv4_endpoint::hash_code() const noexcept {
auto result = fnv_hash(address_.data()); auto result = detail::fnv_hash(address_.data());
return fnv_hash_append(result, port_); return detail::fnv_hash_append(result, port_);
} }
long ipv4_endpoint::compare(ipv4_endpoint x) const noexcept { long ipv4_endpoint::compare(ipv4_endpoint x) const noexcept {
auto res = address_.compare(x.address()); auto res = address_.compare(x.address());
if (res != 0) return res == 0 ? port_ - x.port() : res;
return port_ - x.port();
else
return res;
} }
std::string to_string(const ipv4_endpoint& ep) { std::string to_string(const ipv4_endpoint& ep) {
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
#include "caf/detail/fnv_hash.hpp" #include "caf/detail/fnv_hash.hpp"
using caf::detail::fnv_hash;
using caf::detail::fnv_hash_append;
namespace caf { namespace caf {
ipv6_endpoint::ipv6_endpoint(ipv6_address address, uint16_t port) ipv6_endpoint::ipv6_endpoint(ipv6_address address, uint16_t port)
...@@ -47,20 +44,17 @@ void ipv6_endpoint::port(uint16_t x) noexcept { ...@@ -47,20 +44,17 @@ void ipv6_endpoint::port(uint16_t x) noexcept {
} }
size_t ipv6_endpoint::hash_code() const noexcept { size_t ipv6_endpoint::hash_code() const noexcept {
auto result = fnv_hash(address_.data()); auto result = detail::fnv_hash(address_.data());
return fnv_hash_append(result, port_); return detail::fnv_hash_append(result, port_);
} }
long ipv6_endpoint::compare(ipv6_endpoint x) const noexcept { long ipv6_endpoint::compare(ipv6_endpoint x) const noexcept {
auto res = address_.compare(x.address()); auto res = address_.compare(x.address());
if (res != 0) return res == 0 ? port_ - x.port() : res;
return port_ - x.port();
else
return res;
} }
std::string to_string(const ipv6_endpoint& ep) { std::string to_string(const ipv6_endpoint& ep) {
return to_string(ep.address()) + ":" + std::to_string(ep.port()); return "[" + to_string(ep.address()) + "]:" + std::to_string(ep.port());
} }
} // namespace caf } // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment