diff options
author | shotinleg <shotinleg@yandex-team.ru> | 2022-02-10 16:52:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:01 +0300 |
commit | f79012ccbc48d4068bc9f0fc0712689b8b0dfb5f (patch) | |
tree | ab7fbbf3253d4c0e2793218f09378908beb025fb /util | |
parent | 3acb0d236fd0f37bbc1c8ba7f3660464d9592089 (diff) | |
download | ydb-f79012ccbc48d4068bc9f0fc0712689b8b0dfb5f.tar.gz |
Restoring authorship annotation for <shotinleg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/network/address.cpp | 4 | ||||
-rw-r--r-- | util/network/endpoint.cpp | 24 | ||||
-rw-r--r-- | util/network/endpoint.h | 6 | ||||
-rw-r--r-- | util/network/endpoint_ut.cpp | 28 | ||||
-rw-r--r-- | util/network/socket.cpp | 110 | ||||
-rw-r--r-- | util/network/socket.h | 20 |
6 files changed, 96 insertions, 96 deletions
diff --git a/util/network/address.cpp b/util/network/address.cpp index 22874aff4a..a81a9e6994 100644 --- a/util/network/address.cpp +++ b/util/network/address.cpp @@ -44,8 +44,8 @@ static inline void PrintAddr(IOutputStream& out, const IRemoteAddr& addr) { break; } -#if defined(AF_UNIX) - case AF_UNIX: { +#if defined(AF_UNIX) + case AF_UNIX: { const sockaddr_un* sa = (const sockaddr_un*)a; out << TStringBuf(sa->sun_path); diff --git a/util/network/endpoint.cpp b/util/network/endpoint.cpp index b24d0baa21..9acdd06940 100644 --- a/util/network/endpoint.cpp +++ b/util/network/endpoint.cpp @@ -6,7 +6,7 @@ TEndpoint::TEndpoint(const TEndpoint::TAddrRef& addr) { const sockaddr* sa = Addr_->Addr(); - if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6 && sa->sa_family != AF_UNIX) { + if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6 && sa->sa_family != AF_UNIX) { ythrow yexception() << TStringBuf("endpoint can contain only ipv4, ipv6 or unix address"); } } @@ -17,7 +17,7 @@ TEndpoint::TEndpoint() } void TEndpoint::SetPort(ui16 port) { - if (Port() == port || Addr_->Addr()->sa_family == AF_UNIX) { + if (Port() == port || Addr_->Addr()->sa_family == AF_UNIX) { return; } @@ -33,10 +33,10 @@ void TEndpoint::SetPort(ui16 port) { } ui16 TEndpoint::Port() const noexcept { - if (Addr_->Addr()->sa_family == AF_UNIX) { - return 0; - } - + if (Addr_->Addr()->sa_family == AF_UNIX) { + return 0; + } + const sockaddr* sa = Addr_->Addr(); if (sa->sa_family == AF_INET) { @@ -53,15 +53,15 @@ size_t TEndpoint::Hash() const { const sockaddr_in* sa4 = (const sockaddr_in*)sa; return IntHash((((ui64)sa4->sin_addr.s_addr) << 16) ^ sa4->sin_port); - } else if (sa->sa_family == AF_INET6) { + } else if (sa->sa_family == AF_INET6) { const sockaddr_in6* sa6 = (const sockaddr_in6*)sa; const ui64* ptr = (const ui64*)&sa6->sin6_addr; return IntHash(ptr[0] ^ ptr[1] ^ sa6->sin6_port); - } else { - const sockaddr_un* un = (const sockaddr_un*)sa; - THash<TString> strHash; - - return strHash(un->sun_path); + } else { + const sockaddr_un* un = (const sockaddr_un*)sa; + THash<TString> strHash; + + return strHash(un->sun_path); } } diff --git a/util/network/endpoint.h b/util/network/endpoint.h index 77da7e335a..a3e59b4925 100644 --- a/util/network/endpoint.h +++ b/util/network/endpoint.h @@ -28,9 +28,9 @@ public: inline bool IsIpV6() const { return Addr_->Addr()->sa_family == AF_INET6; } - inline bool IsUnix() const { - return Addr_->Addr()->sa_family == AF_UNIX; - } + inline bool IsUnix() const { + return Addr_->Addr()->sa_family == AF_UNIX; + } inline TString IpToString() const { return NAddr::PrintHost(*Addr_); diff --git a/util/network/endpoint_ut.cpp b/util/network/endpoint_ut.cpp index 28590646de..d5e40dd6e1 100644 --- a/util/network/endpoint_ut.cpp +++ b/util/network/endpoint_ut.cpp @@ -106,18 +106,18 @@ Y_UNIT_TEST_SUITE(TEndpointTest) { UNIT_ASSERT(!(ep1 == ep3)); UNIT_ASSERT(!(ep1 == ep4)); } - - Y_UNIT_TEST(TestIsUnixSocket) { - TNetworkAddress na1(TUnixSocketPath("/tmp/unixsocket")); - TEndpoint ep1(new NAddr::TAddrInfo(&*na1.Begin())); - - TNetworkAddress na2("2a02:6b8:0:1410::5f6c:f3c2", 24242); - TEndpoint ep2(new NAddr::TAddrInfo(&*na2.Begin())); - - UNIT_ASSERT(ep1.IsUnix()); - UNIT_ASSERT(ep1.SockAddr()->sa_family == AF_UNIX); - - UNIT_ASSERT(!ep2.IsUnix()); - UNIT_ASSERT(ep2.SockAddr()->sa_family != AF_UNIX); - } + + Y_UNIT_TEST(TestIsUnixSocket) { + TNetworkAddress na1(TUnixSocketPath("/tmp/unixsocket")); + TEndpoint ep1(new NAddr::TAddrInfo(&*na1.Begin())); + + TNetworkAddress na2("2a02:6b8:0:1410::5f6c:f3c2", 24242); + TEndpoint ep2(new NAddr::TAddrInfo(&*na2.Begin())); + + UNIT_ASSERT(ep1.IsUnix()); + UNIT_ASSERT(ep1.SockAddr()->sa_family == AF_UNIX); + + UNIT_ASSERT(!ep2.IsUnix()); + UNIT_ASSERT(ep2.SockAddr()->sa_family != AF_UNIX); + } } diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 280ba039a5..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -970,39 +970,39 @@ namespace { } class TNetworkAddress::TImpl: public TAtomicRefCount<TImpl> { -private: - class TAddrInfoDeleter { - public: - TAddrInfoDeleter(bool useFreeAddrInfo = true) - : UseFreeAddrInfo_(useFreeAddrInfo) +private: + class TAddrInfoDeleter { + public: + TAddrInfoDeleter(bool useFreeAddrInfo = true) + : UseFreeAddrInfo_(useFreeAddrInfo) { } - - void operator()(struct addrinfo* ai) noexcept { - if (!UseFreeAddrInfo_ && ai != NULL) { - if (ai->ai_addr != NULL) { + + void operator()(struct addrinfo* ai) noexcept { + if (!UseFreeAddrInfo_ && ai != NULL) { + if (ai->ai_addr != NULL) { free(ai->ai_addr); - } - + } + struct addrinfo* p; - while (ai != NULL) { - p = ai; - ai = ai->ai_next; + while (ai != NULL) { + p = ai; + ai = ai->ai_next; free(p->ai_canonname); free(p); - } - } else if (ai != NULL) { - freeaddrinfo(ai); - } - } - - private: - bool UseFreeAddrInfo_ = true; - }; - + } + } else if (ai != NULL) { + freeaddrinfo(ai); + } + } + + private: + bool UseFreeAddrInfo_ = true; + }; + public: inline TImpl(const char* host, ui16 port, int flags) - : Info_(nullptr, TAddrInfoDeleter{}) + : Info_(nullptr, TAddrInfoDeleter{}) { const TString port_st(ToString(port)); struct addrinfo hints; @@ -1021,54 +1021,54 @@ public: } } - struct addrinfo* pai = NULL; - const int error = getaddrinfo(host, port_st.data(), &hints, &pai); + struct addrinfo* pai = NULL; + const int error = getaddrinfo(host, port_st.data(), &hints, &pai); if (error) { - TAddrInfoDeleter()(pai); + TAddrInfoDeleter()(pai); ythrow TNetworkResolutionError(error) << ": can not resolve " << host << ":" << port; } - - Info_.reset(pai); + + Info_.reset(pai); } - inline TImpl(const char* path, int flags) - : Info_(nullptr, TAddrInfoDeleter{/* useFreeAddrInfo = */ false}) - { + inline TImpl(const char* path, int flags) + : Info_(nullptr, TAddrInfoDeleter{/* useFreeAddrInfo = */ false}) + { THolder<struct sockaddr_un, TFree> sockAddr( reinterpret_cast<struct sockaddr_un*>(malloc(sizeof(struct sockaddr_un)))); - - Y_ENSURE(strlen(path) < sizeof(sockAddr->sun_path), "Unix socket path more than " << sizeof(sockAddr->sun_path)); - sockAddr->sun_family = AF_UNIX; - strcpy(sockAddr->sun_path, path); - + + Y_ENSURE(strlen(path) < sizeof(sockAddr->sun_path), "Unix socket path more than " << sizeof(sockAddr->sun_path)); + sockAddr->sun_family = AF_UNIX; + strcpy(sockAddr->sun_path, path); + TAddrInfoPtr hints(reinterpret_cast<struct addrinfo*>(malloc(sizeof(struct addrinfo))), TAddrInfoDeleter{/* useFreeAddrInfo = */ false}); - memset(hints.get(), 0, sizeof(*hints)); - - hints->ai_flags = flags; - hints->ai_family = AF_UNIX; - hints->ai_socktype = SOCK_STREAM; - hints->ai_addrlen = sizeof(*sockAddr); - hints->ai_addr = (struct sockaddr*)sockAddr.Release(); - - Info_.reset(hints.release()); + memset(hints.get(), 0, sizeof(*hints)); + + hints->ai_flags = flags; + hints->ai_family = AF_UNIX; + hints->ai_socktype = SOCK_STREAM; + hints->ai_addrlen = sizeof(*sockAddr); + hints->ai_addr = (struct sockaddr*)sockAddr.Release(); + + Info_.reset(hints.release()); } inline struct addrinfo* Info() const noexcept { - return Info_.get(); + return Info_.get(); } private: - using TAddrInfoPtr = std::unique_ptr<struct addrinfo, TAddrInfoDeleter>; + using TAddrInfoPtr = std::unique_ptr<struct addrinfo, TAddrInfoDeleter>; - TAddrInfoPtr Info_; + TAddrInfoPtr Info_; }; -TNetworkAddress::TNetworkAddress(const TUnixSocketPath& unixSocketPath, int flags) - : Impl_(new TImpl(unixSocketPath.Path.data(), flags)) -{ -} - +TNetworkAddress::TNetworkAddress(const TUnixSocketPath& unixSocketPath, int flags) + : Impl_(new TImpl(unixSocketPath.Path.data(), flags)) +{ +} + TNetworkAddress::TNetworkAddress(const TString& host, ui16 port, int flags) : Impl_(new TImpl(host.data(), port, flags)) { diff --git a/util/network/socket.h b/util/network/socket.h index b33a0a365c..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -152,17 +152,17 @@ public: TNetworkResolutionError(int error); }; -struct TUnixSocketPath { - TString Path; - - // Constructor for create unix domain socket path from string with path in filesystem - // TUnixSocketPath("/tmp/unixsocket") -> "/tmp/unixsocket" - explicit TUnixSocketPath(const TString& path) - : Path(path) +struct TUnixSocketPath { + TString Path; + + // Constructor for create unix domain socket path from string with path in filesystem + // TUnixSocketPath("/tmp/unixsocket") -> "/tmp/unixsocket" + explicit TUnixSocketPath(const TString& path) + : Path(path) { } -}; - +}; + class TNetworkAddress { friend class TSocket; @@ -215,7 +215,7 @@ public: TNetworkAddress(ui16 port); TNetworkAddress(const TString& host, ui16 port); TNetworkAddress(const TString& host, ui16 port, int flags); - TNetworkAddress(const TUnixSocketPath& unixSocketPath, int flags = 0); + TNetworkAddress(const TUnixSocketPath& unixSocketPath, int flags = 0); ~TNetworkAddress(); inline TIterator Begin() const noexcept { |