aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorand42 <and42@yandex-team.ru>2022-02-10 16:47:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:12 +0300
commit984590e9d9d7c0f912885d93ae78be402ae7b4f4 (patch)
tree339adc63bce23800021202ae4a8328a843dc447a /util
parent4fc9a1a64db469cc94894abfec740aa5c9e9789b (diff)
downloadydb-984590e9d9d7c0f912885d93ae78be402ae7b4f4.tar.gz
Restoring authorship annotation for <and42@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/network/endpoint.cpp104
-rw-r--r--util/network/endpoint.h100
-rw-r--r--util/network/endpoint_ut.cpp116
-rw-r--r--util/system/atexit.cpp8
-rw-r--r--util/system/event.cpp20
-rw-r--r--util/system/event_ut.cpp26
6 files changed, 187 insertions, 187 deletions
diff --git a/util/network/endpoint.cpp b/util/network/endpoint.cpp
index 80dc18d63e..9acdd06940 100644
--- a/util/network/endpoint.cpp
+++ b/util/network/endpoint.cpp
@@ -1,67 +1,67 @@
-#include "endpoint.h"
+#include "endpoint.h"
#include "sock.h"
-
-TEndpoint::TEndpoint(const TEndpoint::TAddrRef& addr)
- : Addr_(addr)
-{
- const sockaddr* sa = Addr_->Addr();
-
+
+TEndpoint::TEndpoint(const TEndpoint::TAddrRef& addr)
+ : Addr_(addr)
+{
+ const sockaddr* sa = Addr_->Addr();
+
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");
- }
-}
-
-TEndpoint::TEndpoint()
- : Addr_(new NAddr::TIPv4Addr(TIpAddress(TIpHost(0), TIpPort(0))))
-{
-}
-
-void TEndpoint::SetPort(ui16 port) {
+ }
+}
+
+TEndpoint::TEndpoint()
+ : Addr_(new NAddr::TIPv4Addr(TIpAddress(TIpHost(0), TIpPort(0))))
+{
+}
+
+void TEndpoint::SetPort(ui16 port) {
if (Port() == port || Addr_->Addr()->sa_family == AF_UNIX) {
- return;
- }
-
- NAddr::TOpaqueAddr* oa = new NAddr::TOpaqueAddr(Addr_.Get());
- Addr_.Reset(oa);
- sockaddr* sa = oa->MutableAddr();
-
- if (sa->sa_family == AF_INET) {
- ((sockaddr_in*)sa)->sin_port = HostToInet(port);
- } else {
- ((sockaddr_in6*)sa)->sin6_port = HostToInet(port);
- }
-}
-
+ return;
+ }
+
+ NAddr::TOpaqueAddr* oa = new NAddr::TOpaqueAddr(Addr_.Get());
+ Addr_.Reset(oa);
+ sockaddr* sa = oa->MutableAddr();
+
+ if (sa->sa_family == AF_INET) {
+ ((sockaddr_in*)sa)->sin_port = HostToInet(port);
+ } else {
+ ((sockaddr_in6*)sa)->sin6_port = HostToInet(port);
+ }
+}
+
ui16 TEndpoint::Port() const noexcept {
if (Addr_->Addr()->sa_family == AF_UNIX) {
return 0;
}
- const sockaddr* sa = Addr_->Addr();
-
- if (sa->sa_family == AF_INET) {
- return InetToHost(((const sockaddr_in*)sa)->sin_port);
- } else {
- return InetToHost(((const sockaddr_in6*)sa)->sin6_port);
- }
-}
-
-size_t TEndpoint::Hash() const {
- const sockaddr* sa = Addr_->Addr();
-
- if (sa->sa_family == AF_INET) {
- const sockaddr_in* sa4 = (const sockaddr_in*)sa;
-
- return IntHash((((ui64)sa4->sin_addr.s_addr) << 16) ^ sa4->sin_port);
+ const sockaddr* sa = Addr_->Addr();
+
+ if (sa->sa_family == AF_INET) {
+ return InetToHost(((const sockaddr_in*)sa)->sin_port);
+ } else {
+ return InetToHost(((const sockaddr_in6*)sa)->sin6_port);
+ }
+}
+
+size_t TEndpoint::Hash() const {
+ const sockaddr* sa = Addr_->Addr();
+
+ if (sa->sa_family == AF_INET) {
+ 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) {
- 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);
+ 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);
- }
-}
+ }
+}
diff --git a/util/network/endpoint.h b/util/network/endpoint.h
index fd98d331af..a3e59b4925 100644
--- a/util/network/endpoint.h
+++ b/util/network/endpoint.h
@@ -1,61 +1,61 @@
-#pragma once
-
-#include "address.h"
-
-#include <util/str_stl.h>
-
-//some equivalent boost::asio::ip::endpoint (easy for using pair ip:port)
-class TEndpoint {
-public:
+#pragma once
+
+#include "address.h"
+
+#include <util/str_stl.h>
+
+//some equivalent boost::asio::ip::endpoint (easy for using pair ip:port)
+class TEndpoint {
+public:
using TAddrRef = NAddr::IRemoteAddrRef;
-
- TEndpoint(const TAddrRef& addr);
- TEndpoint();
-
+
+ TEndpoint(const TAddrRef& addr);
+ TEndpoint();
+
inline const TAddrRef& Addr() const noexcept {
- return Addr_;
- }
- inline const sockaddr* SockAddr() const {
- return Addr_->Addr();
- }
- inline socklen_t SockAddrLen() const {
- return Addr_->Len();
- }
-
- inline bool IsIpV4() const {
- return Addr_->Addr()->sa_family == AF_INET;
- }
- inline bool IsIpV6() const {
- return Addr_->Addr()->sa_family == AF_INET6;
- }
+ return Addr_;
+ }
+ inline const sockaddr* SockAddr() const {
+ return Addr_->Addr();
+ }
+ inline socklen_t SockAddrLen() const {
+ return Addr_->Len();
+ }
+
+ inline bool IsIpV4() const {
+ return Addr_->Addr()->sa_family == AF_INET;
+ }
+ inline bool IsIpV6() const {
+ return Addr_->Addr()->sa_family == AF_INET6;
+ }
inline bool IsUnix() const {
return Addr_->Addr()->sa_family == AF_UNIX;
}
-
+
inline TString IpToString() const {
- return NAddr::PrintHost(*Addr_);
- }
-
- void SetPort(ui16 port);
+ return NAddr::PrintHost(*Addr_);
+ }
+
+ void SetPort(ui16 port);
ui16 Port() const noexcept;
-
- size_t Hash() const;
-
-private:
- TAddrRef Addr_;
-};
-
+
+ size_t Hash() const;
+
+private:
+ TAddrRef Addr_;
+};
+
template <>
-struct THash<TEndpoint> {
+struct THash<TEndpoint> {
inline size_t operator()(const TEndpoint& ep) const {
- return ep.Hash();
- }
-};
-
+ return ep.Hash();
+ }
+};
+
inline bool operator==(const TEndpoint& l, const TEndpoint& r) {
- try {
+ try {
return NAddr::IsSame(*l.Addr(), *r.Addr()) && l.Port() == r.Port();
- } catch (...) {
- return false;
- }
-}
+ } catch (...) {
+ return false;
+ }
+}
diff --git a/util/network/endpoint_ut.cpp b/util/network/endpoint_ut.cpp
index 30becbfe77..d5e40dd6e1 100644
--- a/util/network/endpoint_ut.cpp
+++ b/util/network/endpoint_ut.cpp
@@ -1,25 +1,25 @@
-#include "endpoint.h"
-
+#include "endpoint.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/hash_set.h>
-#include <util/generic/strbuf.h>
-
+
+#include <util/generic/hash_set.h>
+#include <util/generic/strbuf.h>
+
Y_UNIT_TEST_SUITE(TEndpointTest) {
Y_UNIT_TEST(TestSimple) {
TVector<TNetworkAddress> addrs;
- TEndpoint ep0;
-
- UNIT_ASSERT(ep0.IsIpV4());
- UNIT_ASSERT_VALUES_EQUAL(0, ep0.Port());
- UNIT_ASSERT_VALUES_EQUAL("0.0.0.0", ep0.IpToString());
-
+ TEndpoint ep0;
+
+ UNIT_ASSERT(ep0.IsIpV4());
+ UNIT_ASSERT_VALUES_EQUAL(0, ep0.Port());
+ UNIT_ASSERT_VALUES_EQUAL("0.0.0.0", ep0.IpToString());
+
TEndpoint ep1;
-
+
try {
TNetworkAddress na1("25.26.27.28", 24242);
-
+
addrs.push_back(na1);
ep1 = TEndpoint(new NAddr::TAddrInfo(&*na1.Begin()));
@@ -35,56 +35,56 @@ Y_UNIT_TEST_SUITE(TEndpointTest) {
ep1 = TEndpoint(new NAddr::TAddrInfo(&*n.Begin()));
}
- ep0.SetPort(12345);
-
- TEndpoint ep2(ep0);
-
- ep0.SetPort(0);
-
- UNIT_ASSERT_VALUES_EQUAL(12345, ep2.Port());
-
- TEndpoint ep2_;
-
- ep2_.SetPort(12345);
-
- UNIT_ASSERT(ep2 == ep2_);
-
- TNetworkAddress na3("2a02:6b8:0:1410::5f6c:f3c2", 54321);
- TEndpoint ep3(new NAddr::TAddrInfo(&*na3.Begin()));
-
- UNIT_ASSERT(ep3.IsIpV6());
+ ep0.SetPort(12345);
+
+ TEndpoint ep2(ep0);
+
+ ep0.SetPort(0);
+
+ UNIT_ASSERT_VALUES_EQUAL(12345, ep2.Port());
+
+ TEndpoint ep2_;
+
+ ep2_.SetPort(12345);
+
+ UNIT_ASSERT(ep2 == ep2_);
+
+ TNetworkAddress na3("2a02:6b8:0:1410::5f6c:f3c2", 54321);
+ TEndpoint ep3(new NAddr::TAddrInfo(&*na3.Begin()));
+
+ UNIT_ASSERT(ep3.IsIpV6());
UNIT_ASSERT(ep3.IpToString().StartsWith(TStringBuf("2a02:6b8:0:1410:")));
UNIT_ASSERT(ep3.IpToString().EndsWith(TStringBuf(":5f6c:f3c2")));
- UNIT_ASSERT_VALUES_EQUAL(54321, ep3.Port());
-
- TNetworkAddress na4("2a02:6b8:0:1410:0::5f6c:f3c2", 1);
- TEndpoint ep4(new NAddr::TAddrInfo(&*na4.Begin()));
-
- TEndpoint ep3_ = ep4;
-
- ep3_.SetPort(54321);
-
+ UNIT_ASSERT_VALUES_EQUAL(54321, ep3.Port());
+
+ TNetworkAddress na4("2a02:6b8:0:1410:0::5f6c:f3c2", 1);
+ TEndpoint ep4(new NAddr::TAddrInfo(&*na4.Begin()));
+
+ TEndpoint ep3_ = ep4;
+
+ ep3_.SetPort(54321);
+
THashSet<TEndpoint> he;
-
- he.insert(ep0);
- he.insert(ep1);
- he.insert(ep2);
-
+
+ he.insert(ep0);
+ he.insert(ep1);
+ he.insert(ep2);
+
UNIT_ASSERT_VALUES_EQUAL(3u, he.size());
-
- he.insert(ep2_);
-
+
+ he.insert(ep2_);
+
UNIT_ASSERT_VALUES_EQUAL(3u, he.size());
-
- he.insert(ep3);
- he.insert(ep3_);
-
+
+ he.insert(ep3);
+ he.insert(ep3_);
+
UNIT_ASSERT_VALUES_EQUAL(4u, he.size());
-
- he.insert(ep4);
-
+
+ he.insert(ep4);
+
UNIT_ASSERT_VALUES_EQUAL(5u, he.size());
- }
+ }
Y_UNIT_TEST(TestEqual) {
const TString ip1 = "2a02:6b8:0:1410::5f6c:f3c2";
@@ -120,4 +120,4 @@ Y_UNIT_TEST_SUITE(TEndpointTest) {
UNIT_ASSERT(!ep2.IsUnix());
UNIT_ASSERT(ep2.SockAddr()->sa_family != AF_UNIX);
}
-}
+}
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp
index 25dc673b5f..74fb10b6b1 100644
--- a/util/system/atexit.cpp
+++ b/util/system/atexit.cpp
@@ -45,15 +45,15 @@ namespace {
Y_ASSERT(c);
Items_.pop();
-
+
{
auto unguard = Unguard(guard);
-
+
try {
- c->Func(c->Ctx);
+ c->Func(c->Ctx);
} catch (...) {
// ¯\_(ツ)_/¯
- }
+ }
}
}
}
diff --git a/util/system/event.cpp b/util/system/event.cpp
index 9771e44a89..79b3cdb291 100644
--- a/util/system/event.cpp
+++ b/util/system/event.cpp
@@ -3,7 +3,7 @@
#include <cstdio>
-#include "atomic.h"
+#include "atomic.h"
#include "event.h"
#include "mutex.h"
#include "condvar.h"
@@ -47,17 +47,17 @@ public:
}
#else
inline TEvImpl(ResetMode rmode)
- : Manual(rmode == rManual ? true : false)
+ : Manual(rmode == rManual ? true : false)
{
}
inline void Signal() noexcept {
- if (Manual && AtomicGet(Signaled)) {
+ if (Manual && AtomicGet(Signaled)) {
return; // shortcut
}
with_lock (Mutex) {
- AtomicSet(Signaled, 1);
+ AtomicSet(Signaled, 1);
}
if (Manual) {
@@ -68,27 +68,27 @@ public:
}
inline void Reset() noexcept {
- AtomicSet(Signaled, 0);
+ AtomicSet(Signaled, 0);
}
inline bool WaitD(TInstant deadLine) noexcept {
- if (Manual && AtomicGet(Signaled)) {
+ if (Manual && AtomicGet(Signaled)) {
return true; // shortcut
}
bool resSignaled = true;
with_lock (Mutex) {
- while (!AtomicGet(Signaled)) {
+ while (!AtomicGet(Signaled)) {
if (!Cond.WaitD(Mutex, deadLine)) {
- resSignaled = AtomicGet(Signaled); // timed out, but Signaled could have been set
+ resSignaled = AtomicGet(Signaled); // timed out, but Signaled could have been set
break;
}
}
if (!Manual) {
- AtomicSet(Signaled, 0);
+ AtomicSet(Signaled, 0);
}
}
@@ -102,7 +102,7 @@ private:
#else
TCondVar Cond;
TMutex Mutex;
- TAtomic Signaled = 0;
+ TAtomic Signaled = 0;
bool Manual;
#endif
};
diff --git a/util/system/event_ut.cpp b/util/system/event_ut.cpp
index d6f14c04cb..2506cb7a91 100644
--- a/util/system/event_ut.cpp
+++ b/util/system/event_ut.cpp
@@ -96,22 +96,22 @@ Y_UNIT_TEST_SUITE(EventTest) {
}
Y_UNIT_TEST(ConcurrentSignalAndWaitTest) {
- // test for problem detected by thread-sanitizer (signal/wait race) SEARCH-2113
- const size_t limit = 200;
- TManualEvent event[limit];
+ // test for problem detected by thread-sanitizer (signal/wait race) SEARCH-2113
+ const size_t limit = 200;
+ TManualEvent event[limit];
TThreadPool queue;
- queue.Start(limit);
+ queue.Start(limit);
TVector<THolder<IObjectInQueue>> tasks;
- for (size_t i = 0; i < limit; ++i) {
+ for (size_t i = 0; i < limit; ++i) {
tasks.emplace_back(MakeHolder<TSignalTask>(event[i]));
- UNIT_ASSERT(queue.Add(tasks.back().Get()));
- }
- for (size_t i = limit; i != 0; --i) {
- UNIT_ASSERT(event[i - 1].WaitT(TDuration::Seconds(90)));
- }
- queue.Stop();
- }
-
+ UNIT_ASSERT(queue.Add(tasks.back().Get()));
+ }
+ for (size_t i = limit; i != 0; --i) {
+ UNIT_ASSERT(event[i - 1].WaitT(TDuration::Seconds(90)));
+ }
+ queue.Stop();
+ }
+
/** Test for a problem: http://nga.at.yandex-team.ru/5772 */
Y_UNIT_TEST(DestructorBeforeSignalFinishTest) {
return;