diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | 1f553f46fb4f3c5eec631352cdd900a0709016af (patch) | |
tree | a231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/socket_addr.h | |
parent | c4de7efdedc25b49cbea74bd589eecb61b55b60a (diff) | |
download | ydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/socket_addr.h')
-rw-r--r-- | library/cpp/messagebus/socket_addr.h | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/library/cpp/messagebus/socket_addr.h b/library/cpp/messagebus/socket_addr.h index 959eafe689..7e3df5afbe 100644 --- a/library/cpp/messagebus/socket_addr.h +++ b/library/cpp/messagebus/socket_addr.h @@ -1,18 +1,18 @@ -#pragma once - +#pragma once + #include "hash.h" - + #include <util/generic/hash.h> #include <util/generic/utility.h> -#include <util/network/address.h> +#include <util/network/address.h> #include <util/network/init.h> - + #include <string.h> - -namespace NBus { - class TNetAddr; -} - + +namespace NBus { + class TNetAddr; +} + namespace NBus { namespace NPrivate { enum EAddrFamily { @@ -20,94 +20,94 @@ namespace NBus { ADDR_IPV4 = AF_INET, ADDR_IPV6 = AF_INET6, }; - + class TBusIpAddr { private: EAddrFamily Af; - + union { in_addr In4; in6_addr In6; }; - + public: TBusIpAddr() { Clear(); } - + EAddrFamily GetAddrFamily() const { return Af; } - + void Clear() { Zero(*this); } - + in_addr GetInAddr() const { Y_ASSERT(Af == ADDR_IPV4); return In4; } - + void SetInAddr(const in_addr& in4) { Clear(); Af = ADDR_IPV4; In4 = in4; } - + in6_addr GetIn6Addr() const { Y_ASSERT(Af == ADDR_IPV6); return In6; } - + void SetIn6Addr(const in6_addr& in6) { Clear(); Af = ADDR_IPV6; In6 = in6; } - + bool operator==(const TBusIpAddr& that) const { return memcmp(this, &that, sizeof(that)) == 0; } }; - + class TBusSocketAddr { public: TBusIpAddr IpAddr; ui16 Port; - + //Only makes sense for IPv6 link-local addresses ui32 IPv6ScopeID; - + TBusSocketAddr() : Port(0) , IPv6ScopeID(0) { } - + TBusSocketAddr(const NAddr::IRemoteAddr*); TBusSocketAddr(const TNetAddr&); TBusSocketAddr(TStringBuf host, unsigned port); TNetAddr ToNetAddr() const; - + bool operator==(const TBusSocketAddr& that) const { return IpAddr == that.IpAddr && Port == that.Port; } }; - + } } - -template <> -struct THash<NBus::NPrivate::TBusIpAddr> { - inline size_t operator()(const NBus::NPrivate::TBusIpAddr& a) const { + +template <> +struct THash<NBus::NPrivate::TBusIpAddr> { + inline size_t operator()(const NBus::NPrivate::TBusIpAddr& a) const { return ComputeHash(TStringBuf((const char*)&a, sizeof(a))); - } -}; - -template <> -struct THash<NBus::NPrivate::TBusSocketAddr> { - inline size_t operator()(const NBus::NPrivate::TBusSocketAddr& a) const { - return HashValues(a.IpAddr, a.Port); - } -}; + } +}; + +template <> +struct THash<NBus::NPrivate::TBusSocketAddr> { + inline size_t operator()(const NBus::NPrivate::TBusSocketAddr& a) const { + return HashValues(a.IpAddr, a.Port); + } +}; |