diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/network | |
parent | 8cbc307de0221f84c80c42dcbe07d40727537e2c (diff) | |
download | ydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/address.cpp | 6 | ||||
-rw-r--r-- | util/network/address.h | 2 | ||||
-rw-r--r-- | util/network/address_ut.cpp | 10 | ||||
-rw-r--r-- | util/network/endpoint_ut.cpp | 6 | ||||
-rw-r--r-- | util/network/hostip.cpp | 4 | ||||
-rw-r--r-- | util/network/init.cpp | 28 | ||||
-rw-r--r-- | util/network/init.h | 2 | ||||
-rw-r--r-- | util/network/interface.cpp | 6 | ||||
-rw-r--r-- | util/network/iovec.h | 2 | ||||
-rw-r--r-- | util/network/ip_ut.cpp | 4 | ||||
-rw-r--r-- | util/network/nonblock.cpp | 6 | ||||
-rw-r--r-- | util/network/pair.cpp | 4 | ||||
-rw-r--r-- | util/network/poller.h | 2 | ||||
-rw-r--r-- | util/network/poller_ut.cpp | 38 | ||||
-rw-r--r-- | util/network/pollerimpl.h | 26 | ||||
-rw-r--r-- | util/network/sock.h | 42 | ||||
-rw-r--r-- | util/network/sock_ut.cpp | 12 | ||||
-rw-r--r-- | util/network/socket.cpp | 42 | ||||
-rw-r--r-- | util/network/socket.h | 12 | ||||
-rw-r--r-- | util/network/socket_ut.cpp | 4 |
20 files changed, 129 insertions, 129 deletions
diff --git a/util/network/address.cpp b/util/network/address.cpp index 906608d30f..a81a9e6994 100644 --- a/util/network/address.cpp +++ b/util/network/address.cpp @@ -10,7 +10,7 @@ using namespace NAddr; template <bool printPort> -static inline void PrintAddr(IOutputStream& out, const IRemoteAddr& addr) { +static inline void PrintAddr(IOutputStream& out, const IRemoteAddr& addr) { const sockaddr* a = addr.Addr(); char buf[INET6_ADDRSTRLEN + 10]; @@ -90,7 +90,7 @@ static inline void PrintAddr(IOutputStream& out, const IRemoteAddr& addr) { } template <> -void Out<IRemoteAddr>(IOutputStream& out, const IRemoteAddr& addr) { +void Out<IRemoteAddr>(IOutputStream& out, const IRemoteAddr& addr) { PrintAddr<true>(out, addr); } @@ -114,7 +114,7 @@ void Out<NAddr::TOpaqueAddr>(IOutputStream& out, const NAddr::TOpaqueAddr& addr) PrintAddr<true>(out, addr); } -void NAddr::PrintHost(IOutputStream& out, const IRemoteAddr& addr) { +void NAddr::PrintHost(IOutputStream& out, const IRemoteAddr& addr) { PrintAddr<false>(out, addr); } diff --git a/util/network/address.h b/util/network/address.h index d9f310ae9d..448fcac0c9 100644 --- a/util/network/address.h +++ b/util/network/address.h @@ -20,7 +20,7 @@ namespace NAddr { IRemoteAddrPtr GetSockAddr(SOCKET s); IRemoteAddrPtr GetPeerAddr(SOCKET s); - void PrintHost(IOutputStream& out, const IRemoteAddr& addr); + void PrintHost(IOutputStream& out, const IRemoteAddr& addr); TString PrintHost(const IRemoteAddr& addr); TString PrintHostAndPort(const IRemoteAddr& addr); diff --git a/util/network/address_ut.cpp b/util/network/address_ut.cpp index 98f75d95f4..28f45172ff 100644 --- a/util/network/address_ut.cpp +++ b/util/network/address_ut.cpp @@ -4,8 +4,8 @@ using namespace NAddr; -Y_UNIT_TEST_SUITE(IRemoteAddr_ToString) { - Y_UNIT_TEST(Raw) { +Y_UNIT_TEST_SUITE(IRemoteAddr_ToString) { + Y_UNIT_TEST(Raw) { THolder<TOpaqueAddr> opaque(new TOpaqueAddr); IRemoteAddr* addr = opaque.Get(); @@ -16,11 +16,11 @@ Y_UNIT_TEST_SUITE(IRemoteAddr_ToString) { TString t = ToString(*addr); - UNIT_ASSERT_C(t.StartsWith("(raw 0 0"), t); - UNIT_ASSERT_C(t.EndsWith(')'), t); + UNIT_ASSERT_C(t.StartsWith("(raw 0 0"), t); + UNIT_ASSERT_C(t.EndsWith(')'), t); } - Y_UNIT_TEST(Ipv6) { + Y_UNIT_TEST(Ipv6) { TNetworkAddress address("::1", 22); TNetworkAddress::TIterator it = address.Begin(); UNIT_ASSERT(it != address.End()); diff --git a/util/network/endpoint_ut.cpp b/util/network/endpoint_ut.cpp index f812065805..d5e40dd6e1 100644 --- a/util/network/endpoint_ut.cpp +++ b/util/network/endpoint_ut.cpp @@ -5,8 +5,8 @@ #include <util/generic/hash_set.h> #include <util/generic/strbuf.h> -Y_UNIT_TEST_SUITE(TEndpointTest) { - Y_UNIT_TEST(TestSimple) { +Y_UNIT_TEST_SUITE(TEndpointTest) { + Y_UNIT_TEST(TestSimple) { TVector<TNetworkAddress> addrs; TEndpoint ep0; @@ -86,7 +86,7 @@ Y_UNIT_TEST_SUITE(TEndpointTest) { UNIT_ASSERT_VALUES_EQUAL(5u, he.size()); } - Y_UNIT_TEST(TestEqual) { + Y_UNIT_TEST(TestEqual) { const TString ip1 = "2a02:6b8:0:1410::5f6c:f3c2"; const TString ip2 = "2a02:6b8:0:1410::5f6c:f3c3"; diff --git a/util/network/hostip.cpp b/util/network/hostip.cpp index 62085e7c5b..cb8d43bf90 100644 --- a/util/network/hostip.cpp +++ b/util/network/hostip.cpp @@ -28,8 +28,8 @@ int NResolver::GetHostIP(const char* hostname, ui32* ip, size_t* slots) { memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; - struct addrinfo* gai_res = nullptr; - int gai_ret = getaddrinfo(hostname, nullptr, &hints, &gai_res); + struct addrinfo* gai_res = nullptr; + int gai_ret = getaddrinfo(hostname, nullptr, &hints, &gai_res); if (gai_ret == 0 && gai_res->ai_addr) { struct addrinfo* cur = gai_res; for (i = 0; i < *slots && cur; i++, cur = cur->ai_next, ipsFound++) { diff --git a/util/network/init.cpp b/util/network/init.cpp index 26561c173a..366e65682c 100644 --- a/util/network/init.cpp +++ b/util/network/init.cpp @@ -8,26 +8,26 @@ #include <cstdio> #include <cstdlib> -namespace { - class TNetworkInit { - public: - inline TNetworkInit() { +namespace { + class TNetworkInit { + public: + inline TNetworkInit() { #ifndef ROBOT_SIGPIPE - signal(SIGPIPE, SIG_IGN); + signal(SIGPIPE, SIG_IGN); #endif #if defined(_win_) #pragma comment(lib, "ws2_32.lib") - WSADATA wsaData; - int result = WSAStartup(MAKEWORD(2, 2), &wsaData); - Y_ASSERT(!result); - if (result) { - exit(-1); - } -#endif + WSADATA wsaData; + int result = WSAStartup(MAKEWORD(2, 2), &wsaData); + Y_ASSERT(!result); + if (result) { + exit(-1); + } +#endif } - }; -} + }; +} void InitNetworkSubSystem() { (void)Singleton<TNetworkInit>(); diff --git a/util/network/init.h b/util/network/init.h index 33a3e7f435..08a79c0fca 100644 --- a/util/network/init.h +++ b/util/network/init.h @@ -49,7 +49,7 @@ struct sockaddr_un { #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif -#endif // _win_ or _darwin_ +#endif // _win_ or _darwin_ void InitNetworkSubSystem(); diff --git a/util/network/interface.cpp b/util/network/interface.cpp index 1ad5f21191..256776c6d3 100644 --- a/util/network/interface.cpp +++ b/util/network/interface.cpp @@ -11,7 +11,7 @@ namespace NAddr { static bool IsInetAddress(sockaddr* addr) { - return (addr != nullptr) && ((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6)); + return (addr != nullptr) && ((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6)); } TNetworkInterfaceList GetNetworkInterfaces() { @@ -23,7 +23,7 @@ namespace NAddr { PIP_ADAPTER_ADDRESSES adapterBuf = (PIP_ADAPTER_ADDRESSES)&buf[0]; ULONG bufSize = buf.ysize(); - if (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, adapterBuf, &bufSize) == ERROR_SUCCESS) { + if (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, adapterBuf, &bufSize) == ERROR_SUCCESS) { for (PIP_ADAPTER_ADDRESSES ptr = adapterBuf; ptr != 0; ptr = ptr->Next) { // The check below makes code working on Vista+ if ((ptr->Flags & (IP_ADAPTER_IPV4_ENABLED | IP_ADAPTER_IPV6_ENABLED)) == 0) { @@ -59,7 +59,7 @@ namespace NAddr { #else ifaddrs* ifap; if (getifaddrs(&ifap) != -1) { - for (ifaddrs* ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) { + for (ifaddrs* ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) { if (IsInetAddress(ifa->ifa_addr)) { TNetworkInterface interface; interface.Name = ifa->ifa_name; diff --git a/util/network/iovec.h b/util/network/iovec.h index cabc453492..ac15a41f54 100644 --- a/util/network/iovec.h +++ b/util/network/iovec.h @@ -5,7 +5,7 @@ #include <util/system/yassert.h> class TContIOVector { - using TPart = IOutputStream::TPart; + using TPart = IOutputStream::TPart; public: inline TContIOVector(TPart* parts, size_t count) diff --git a/util/network/ip_ut.cpp b/util/network/ip_ut.cpp index 71fbba21f3..6716c6a699 100644 --- a/util/network/ip_ut.cpp +++ b/util/network/ip_ut.cpp @@ -29,7 +29,7 @@ void TSysIpTest::TestIpFromString() { const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; - for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { const ui32 ip = IpFromString(ipStr[i]); UNIT_ASSERT(memcmp(&ip, ipArr[i], sizeof(ui32)) == 0); @@ -57,7 +57,7 @@ void TSysIpTest::TestIpToString() { const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; - for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { UNIT_ASSERT(IpToString(*reinterpret_cast<TIpHost*>(&(ipArr[i]))) == ipStr[i]); } } diff --git a/util/network/nonblock.cpp b/util/network/nonblock.cpp index dcc7360e62..e515c27cc5 100644 --- a/util/network/nonblock.cpp +++ b/util/network/nonblock.cpp @@ -17,7 +17,7 @@ namespace { struct TFeatureCheck { inline TFeatureCheck() - : Accept4(nullptr) + : Accept4(nullptr) , HaveSockNonBlock(false) { #if defined(_unix_) && defined(SOCK_NONBLOCK) @@ -32,10 +32,10 @@ namespace { #endif if (Accept4) { - Accept4(-1, nullptr, nullptr, SOCK_NONBLOCK); + Accept4(-1, nullptr, nullptr, SOCK_NONBLOCK); if (errno == ENOSYS) { - Accept4 = nullptr; + Accept4 = nullptr; } } } diff --git a/util/network/pair.cpp b/util/network/pair.cpp index 384fd03620..9751ef5c96 100644 --- a/util/network/pair.cpp +++ b/util/network/pair.cpp @@ -50,13 +50,13 @@ int SocketPair(SOCKET socks[2], bool overlapped, bool cloexec) { if (listen(listener, 1) == SOCKET_ERROR) break; - if ((socks[0] = WSASocket(AF_INET, SOCK_STREAM, 0, nullptr, 0, flags)) == INVALID_SOCKET) + if ((socks[0] = WSASocket(AF_INET, SOCK_STREAM, 0, nullptr, 0, flags)) == INVALID_SOCKET) break; if (connect(socks[0], (const struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) break; - if ((socks[1] = accept(listener, nullptr, nullptr)) == INVALID_SOCKET) + if ((socks[1] = accept(listener, nullptr, nullptr)) == INVALID_SOCKET) break; closesocket(listener); diff --git a/util/network/poller.h b/util/network/poller.h index 8ae414d4f3..8dccd73140 100644 --- a/util/network/poller.h +++ b/util/network/poller.h @@ -41,7 +41,7 @@ public: return ret; } - return nullptr; + return nullptr; } inline void* WaitT(const TDuration& timeOut) { diff --git a/util/network/poller_ut.cpp b/util/network/poller_ut.cpp index 0e19bff4c1..6df0dda8ec 100644 --- a/util/network/poller_ut.cpp +++ b/util/network/poller_ut.cpp @@ -1,12 +1,12 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/system/error.h> -#include "pair.h" +#include "pair.h" #include "poller.h" #include "pollerimpl.h" -Y_UNIT_TEST_SUITE(TSocketPollerTest) { - Y_UNIT_TEST(TestSimple) { +Y_UNIT_TEST_SUITE(TSocketPollerTest) { + Y_UNIT_TEST(TestSimple) { SOCKET sockets[2]; UNIT_ASSERT(SocketPair(sockets) == 0); @@ -16,8 +16,8 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { TSocketPoller poller; poller.WaitRead(sockets[1], (void*)17); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); for (ui32 i = 0; i < 3; ++i) { char buf[] = {18}; @@ -28,12 +28,12 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { UNIT_ASSERT_VALUES_EQUAL(1, recv(sockets[1], buf, 1, 0)); UNIT_ASSERT_VALUES_EQUAL(18, buf[0]); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); } } - Y_UNIT_TEST(TestSimpleOneShot) { + Y_UNIT_TEST(TestSimpleOneShot) { SOCKET sockets[2]; UNIT_ASSERT(SocketPair(sockets) == 0); @@ -42,8 +42,8 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { TSocketPoller poller; - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); for (ui32 i = 0; i < 3; ++i) { poller.WaitReadOneShot(sockets[1], (void*)17); @@ -59,23 +59,23 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { UNIT_ASSERT_VALUES_EQUAL(1, recv(sockets[1], buf, 1, 0)); UNIT_ASSERT_VALUES_EQUAL(char(i + 20), buf[0]); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); buf[0] = i + 21; UNIT_ASSERT_VALUES_EQUAL(1, send(sockets[0], buf, 1, 0)); // this fails if socket is not oneshot - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); - UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); + UNIT_ASSERT_VALUES_EQUAL(nullptr, poller.WaitT(TDuration::Zero())); UNIT_ASSERT_VALUES_EQUAL(1, recv(sockets[1], buf, 1, 0)); UNIT_ASSERT_VALUES_EQUAL(char(i + 21), buf[0]); } } - Y_UNIT_TEST(TestItIsSafeToUnregisterUnregisteredDescriptor) { + Y_UNIT_TEST(TestItIsSafeToUnregisterUnregisteredDescriptor) { SOCKET sockets[2]; UNIT_ASSERT(SocketPair(sockets) == 0); @@ -87,7 +87,7 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { poller.Unwait(s1); } - Y_UNIT_TEST(TestItIsSafeToReregisterDescriptor) { + Y_UNIT_TEST(TestItIsSafeToReregisterDescriptor) { SOCKET sockets[2]; UNIT_ASSERT(SocketPair(sockets) == 0); @@ -96,9 +96,9 @@ Y_UNIT_TEST_SUITE(TSocketPollerTest) { TSocketPoller poller; - poller.WaitRead(s1, nullptr); - poller.WaitRead(s1, nullptr); - poller.WaitWrite(s1, nullptr); + poller.WaitRead(s1, nullptr); + poller.WaitRead(s1, nullptr); + poller.WaitWrite(s1, nullptr); } Y_UNIT_TEST(TestSimpleEdgeTriggered) { diff --git a/util/network/pollerimpl.h b/util/network/pollerimpl.h index 103df45afe..e8c7e40fba 100644 --- a/util/network/pollerimpl.h +++ b/util/network/pollerimpl.h @@ -126,7 +126,7 @@ public: EV_SET(e + 0, fd, EVFILT_READ, flags | ((what & CONT_POLL_READ) ? EV_ENABLE : EV_DISABLE), 0, 0, data); EV_SET(e + 1, fd, EVFILT_WRITE, flags | ((what & CONT_POLL_WRITE) ? EV_ENABLE : EV_DISABLE), 0, 0, data); - if (Kevent(Fd_, e, 2, nullptr, 0, nullptr) == -1) { + if (Kevent(Fd_, e, 2, nullptr, 0, nullptr) == -1) { ythrow TSystemError() << "kevent add failed"; } } @@ -139,7 +139,7 @@ public: EV_SET(e + 0, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); EV_SET(e + 1, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0); - Y_VERIFY(!(Kevent(Fd_, e, 2, nullptr, 0, nullptr) == -1 && errno != ENOENT), "kevent remove failed: %s", LastSystemErrorText()); + Y_VERIFY(!(Kevent(Fd_, e, 2, nullptr, 0, nullptr) == -1 && errno != ENOENT), "kevent remove failed: %s", LastSystemErrorText()); } inline size_t Wait(TEvent* events, size_t len, int timeout) noexcept { @@ -148,9 +148,9 @@ public: ts.tv_sec = timeout / 1000000; ts.tv_nsec = (timeout % 1000000) * 1000; - const int ret = Kevent(Fd_, nullptr, 0, events, len, &ts); + const int ret = Kevent(Fd_, nullptr, 0, events, len, &ts); - Y_VERIFY(ret >= 0, "kevent failed: %s", LastSystemErrorText()); + Y_VERIFY(ret >= 0, "kevent failed: %s", LastSystemErrorText()); return (size_t)ret; } @@ -269,7 +269,7 @@ public: inline size_t Wait(TEvent* events, size_t len, int timeout) noexcept { const int ret = ContEpollWait(Fd_, events, len, MicroToMilli(timeout)); - Y_VERIFY(ret >= 0, "epoll wait error: %s", LastSystemErrorText()); + Y_VERIFY(ret >= 0, "epoll wait error: %s", LastSystemErrorText()); return (size_t)ret; } @@ -331,7 +331,7 @@ struct TSelectPollerNoTemplate { int Filter_; inline THandle() - : Data_(nullptr) + : Data_(nullptr) , Filter_(0) { } @@ -367,9 +367,9 @@ struct TSelectPollerNoTemplate { inline SOCKET Build(fd_set* r, fd_set* w, fd_set* e) const noexcept { SOCKET ret = 0; - for (const auto& it : *this) { - const SOCKET fd = it.first; - const THandle& handle = it.second; + for (const auto& it : *this) { + const SOCKET fd = it.first; + const THandle& handle = it.second; FD_SET(fd, e); @@ -411,8 +411,8 @@ class TSelectPoller: public TSelectPollerNoTemplate { public: inline TSelectPoller() - : Begin_(nullptr) - , End_(nullptr) + : Begin_(nullptr) + , End_(nullptr) { SocketPair(Signal_); SetNonBlock(WaitSock()); @@ -519,7 +519,7 @@ public: TryWait(); } - Y_VERIFY(ret >= 0 && (size_t)ret <= len, "select error: %s", LastSystemErrorText()); + Y_VERIFY(ret >= 0 && (size_t)ret <= len, "select error: %s", LastSystemErrorText()); TEvent* eventsStart = events; @@ -598,7 +598,7 @@ private: char ch[32]; while (recv(WaitSock(), ch, sizeof(ch), 0) > 0) { - Y_ASSERT(ch[0] == 13); + Y_ASSERT(ch[0] == 13); } } diff --git a/util/network/sock.h b/util/network/sock.h index ea558f22e1..b10be2f715 100644 --- a/util/network/sock.h +++ b/util/network/sock.h @@ -3,7 +3,7 @@ #include <util/folder/path.h> #include <util/system/defaults.h> #include <util/string/cast.h> -#include <util/stream/output.h> +#include <util/stream/output.h> #include <util/system/sysstat.h> #if defined(_win_) || defined(_cygwin_) @@ -17,11 +17,11 @@ #include "ip.h" #include "socket.h" -constexpr ui16 DEF_LOCAL_SOCK_MODE = 00644; +constexpr ui16 DEF_LOCAL_SOCK_MODE = 00644; // Base abstract class for socket address -struct ISockAddr { - virtual ~ISockAddr() = default; +struct ISockAddr { + virtual ~ISockAddr() = default; // Max size of the address that we can store (arg of recvfrom) virtual socklen_t Size() const = 0; // Real length of the address (arg of sendto) @@ -47,7 +47,7 @@ protected: #if defined(_win_) || defined(_cygwin_) #define YAF_LOCAL AF_INET -struct TSockAddrLocal: public ISockAddr { +struct TSockAddrLocal: public ISockAddr { TSockAddrLocal() { Clear(); } @@ -111,7 +111,7 @@ struct TSockAddrLocal: public ISockAddr { } int Bind(SOCKET s, ui16 mode) const { - Y_UNUSED(mode); + Y_UNUSED(mode); int ret = 0; // 1. open file TFileHandle f(Path, CreateAlways | WrOnly); @@ -137,13 +137,13 @@ struct TSockAddrLocal: public ISockAddr { return 0; } - static constexpr size_t PathSize = 128; + static constexpr size_t PathSize = 128; mutable struct sockaddr_in in; char Path[PathSize]; }; #else #define YAF_LOCAL AF_LOCAL -struct TSockAddrLocal: public sockaddr_un, public ISockAddr { +struct TSockAddrLocal: public sockaddr_un, public ISockAddr { TSockAddrLocal() { Clear(); } @@ -201,7 +201,7 @@ struct TSockAddrLocal: public sockaddr_un, public ISockAddr { }; #endif // _win_ -struct TSockAddrInet: public sockaddr_in, public ISockAddr { +struct TSockAddrInet: public sockaddr_in, public ISockAddr { TSockAddrInet() { Clear(); } @@ -246,7 +246,7 @@ struct TSockAddrInet: public sockaddr_in, public ISockAddr { } int Bind(SOCKET s, ui16 mode) const override { - Y_UNUSED(mode); + Y_UNUSED(mode); int ret = bind(s, SockAddr(), Len()); if (ret < 0) return -errno; @@ -271,7 +271,7 @@ struct TSockAddrInet: public sockaddr_in, public ISockAddr { } }; -struct TSockAddrInet6: public sockaddr_in6, public ISockAddr { +struct TSockAddrInet6: public sockaddr_in6, public ISockAddr { TSockAddrInet6() { Clear(); } @@ -312,7 +312,7 @@ struct TSockAddrInet6: public sockaddr_in6, public ISockAddr { } int Bind(SOCKET s, ui16 mode) const override { - Y_UNUSED(mode); + Y_UNUSED(mode); int ret = bind(s, SockAddr(), Len()); if (ret < 0) { return -errno; @@ -354,7 +354,7 @@ protected: } public: - int Bind(const ISockAddr* addr, ui16 mode = DEF_LOCAL_SOCK_MODE) { + int Bind(const ISockAddr* addr, ui16 mode = DEF_LOCAL_SOCK_MODE) { return addr->Bind((SOCKET) * this, mode); } @@ -378,7 +378,7 @@ protected: } public: - ssize_t SendTo(const void* msg, size_t len, const ISockAddr* toAddr) { + ssize_t SendTo(const void* msg, size_t len, const ISockAddr* toAddr) { ssize_t ret = toAddr->ResolveAddr(); if (ret < 0) { return -LastSystemError(); @@ -392,7 +392,7 @@ public: return ret; } - ssize_t RecvFrom(void* buf, size_t len, ISockAddr* fromAddr) { + ssize_t RecvFrom(void* buf, size_t len, ISockAddr* fromAddr) { socklen_t fromSize = fromAddr->Size(); const ssize_t ret = recvfrom((SOCKET) * this, (char*)buf, (int)len, 0, fromAddr->SockAddr(), &fromSize); if (ret < 0) { @@ -432,7 +432,7 @@ public: return ret; } - int Connect(const ISockAddr* addr) { + int Connect(const ISockAddr* addr) { int ret = addr->ResolveAddr(); if (ret < 0) return -errno; @@ -548,7 +548,7 @@ public: } }; -class TStreamSocketInput: public IInputStream { +class TStreamSocketInput: public IInputStream { public: TStreamSocketInput(TStreamSocket* socket) : Socket(socket) @@ -562,7 +562,7 @@ protected: TStreamSocket* Socket; size_t DoRead(void* buf, size_t len) override { - Y_VERIFY(Socket, "TStreamSocketInput: socket isn't set"); + Y_VERIFY(Socket, "TStreamSocketInput: socket isn't set"); const ssize_t ret = Socket->Recv(buf, len); if (ret >= 0) { @@ -573,7 +573,7 @@ protected: } }; -class TStreamSocketOutput: public IOutputStream { +class TStreamSocketOutput: public IOutputStream { public: TStreamSocketOutput(TStreamSocket* socket) : Socket(socket) @@ -590,7 +590,7 @@ protected: TStreamSocket* Socket; void DoWrite(const void* buf, size_t len) override { - Y_VERIFY(Socket, "TStreamSocketOutput: socket isn't set"); + Y_VERIFY(Socket, "TStreamSocketOutput: socket isn't set"); const char* ptr = (const char*)buf; while (len) { @@ -600,7 +600,7 @@ protected: ythrow TSystemError(-(int)ret) << "can not write to socket output stream"; } - Y_ASSERT((size_t)ret <= len); + Y_ASSERT((size_t)ret <= len); len -= (size_t)ret; ptr += (size_t)ret; } diff --git a/util/network/sock_ut.cpp b/util/network/sock_ut.cpp index 3ba7eafc75..fd8c783747 100644 --- a/util/network/sock_ut.cpp +++ b/util/network/sock_ut.cpp @@ -5,8 +5,8 @@ #include <util/system/fs.h> -Y_UNIT_TEST_SUITE(TSocketTest) { - Y_UNIT_TEST(InetDgramTest) { +Y_UNIT_TEST_SUITE(TSocketTest) { + Y_UNIT_TEST(InetDgramTest) { char buf[256]; TSockAddrInetDgram servAddr(IpFromString("127.0.0.1"), 0); TSockAddrInetDgram cliAddr(IpFromString("127.0.0.1"), 0); @@ -64,7 +64,7 @@ Y_UNIT_TEST_SUITE(TSocketTest) { UNIT_ASSERT(strcmp(repStr, buf) == 0); } - Y_UNIT_TEST(LocalDgramTest) { + Y_UNIT_TEST(LocalDgramTest) { const char* localServerSockName = "./serv_sock"; const char* localClientSockName = "./cli_sock"; RunLocalDgramTest(localServerSockName, localClientSockName); @@ -111,11 +111,11 @@ Y_UNIT_TEST_SUITE(TSocketTest) { UNIT_ASSERT(strcmp(repStr, buf) == 0); } - Y_UNIT_TEST(InetStreamTest) { + Y_UNIT_TEST(InetStreamTest) { RunInetStreamTest<TSockAddrInetStream, TInetStreamSocket>("127.0.0.1"); } - Y_UNIT_TEST(Inet6StreamTest) { + Y_UNIT_TEST(Inet6StreamTest) { RunInetStreamTest<TSockAddrInet6Stream, TInet6StreamSocket>("::1"); } @@ -159,7 +159,7 @@ Y_UNIT_TEST_SUITE(TSocketTest) { UNIT_ASSERT(strcmp(repStr, buf) == 0); } - Y_UNIT_TEST(LocalStreamTest) { + Y_UNIT_TEST(LocalStreamTest) { const char* localServerSockName = "./serv_sock2"; RunLocalStreamTest(localServerSockName); NFs::Remove(localServerSockName); diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 0d44f7bac7..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -36,7 +36,7 @@ #include <util/generic/ylimits.h> #include <util/string/cast.h> -#include <util/stream/mem.h> +#include <util/stream/mem.h> #include <util/system/datetime.h> #include <util/system/error.h> #include <util/memory/tempbuf.h> @@ -54,7 +54,7 @@ int inet_aton(const char* cp, struct in_addr* inp) { sockaddr_in addr; addr.sin_family = AF_INET; int psz = sizeof(addr); - if (0 == WSAStringToAddress((char*)cp, AF_INET, nullptr, (LPSOCKADDR)&addr, &psz)) { + if (0 == WSAStringToAddress((char*)cp, AF_INET, nullptr, (LPSOCKADDR)&addr, &psz)) { memcpy(inp, &addr.sin_addr, sizeof(in_addr)); return 1; } @@ -180,7 +180,7 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept { if (fd->events & POLLOUT) { FD_SET(fd->fd, &writefds); } - int error = select(0, &readfds, &writefds, nullptr, &timeout); + int error = select(0, &readfds, &writefds, nullptr, &timeout); if (error > 0) { if (FD_ISSET(fd->fd, &readfds)) { fd->revents |= POLLIN; @@ -315,8 +315,8 @@ void SetReusePort(SOCKET s, bool value) { #if defined(SO_REUSEPORT) CheckedSetSockOpt(s, SOL_SOCKET, SO_REUSEPORT, (int)value, "reuse port"); #else - Y_UNUSED(s); - Y_UNUSED(value); + Y_UNUSED(s); + Y_UNUSED(value); ythrow TSystemError(ENOSYS) << "SO_REUSEPORT is not defined"; #endif } @@ -340,8 +340,8 @@ void SetCloseOnExec(SOCKET s, bool value) { ythrow TSystemError() << "fcntl() failed"; } #else - Y_UNUSED(s); - Y_UNUSED(value); + Y_UNUSED(s); + Y_UNUSED(value); #endif } @@ -485,8 +485,8 @@ void SetTcpFastOpen(SOCKET s, int qlen) { #if defined(TCP_FASTOPEN) TTcpFastOpenFeature::Instance()->SetFastOpen(s, qlen); #else - Y_UNUSED(s); - Y_UNUSED(qlen); + Y_UNUSED(s); + Y_UNUSED(qlen); #endif } @@ -561,9 +561,9 @@ void TSocketHolder::Close() noexcept { // because often it means double close // that is disasterous #ifdef _win_ - Y_VERIFY(WSAGetLastError() != WSAENOTSOCK, "must not quietly close bad socket descriptor"); + Y_VERIFY(WSAGetLastError() != WSAENOTSOCK, "must not quietly close bad socket descriptor"); #elif defined(_unix_) - Y_VERIFY(errno != EBADF, "must not quietly close bad descriptor: fd=%d", int(Fd_)); + Y_VERIFY(errno != EBADF, "must not quietly close bad descriptor: fd=%d", int(Fd_)); #else #error unsupported platform #endif @@ -611,7 +611,7 @@ private: }; template <> -void Out<const struct addrinfo*>(IOutputStream& os, const struct addrinfo* ai) { +void Out<const struct addrinfo*>(IOutputStream& os, const struct addrinfo* ai) { if (ai->ai_flags & AI_CANONNAME) { os << "`" << ai->ai_canonname << "' "; } @@ -628,12 +628,12 @@ void Out<const struct addrinfo*>(IOutputStream& os, const struct addrinfo* ai) { } template <> -void Out<struct addrinfo*>(IOutputStream& os, struct addrinfo* ai) { +void Out<struct addrinfo*>(IOutputStream& os, struct addrinfo* ai) { Out<const struct addrinfo*>(os, static_cast<const struct addrinfo*>(ai)); } template <> -void Out<TNetworkAddress>(IOutputStream& os, const TNetworkAddress& addr) { +void Out<TNetworkAddress>(IOutputStream& os, const TNetworkAddress& addr) { os << &*addr.Begin(); } @@ -919,16 +919,16 @@ TSocketOutput::~TSocketOutput() { } void TSocketOutput::DoWrite(const void* buf, size_t len) { - size_t send = 0; + size_t send = 0; while (len) { const ssize_t ret = S_.Send(buf, len); if (ret < 0) { - ythrow TSystemError(-(int)ret) << "can not write to socket output stream; " << send << " bytes already send"; + ythrow TSystemError(-(int)ret) << "can not write to socket output stream; " << send << " bytes already send"; } buf = (const char*)buf + ret; len -= ret; - send += ret; + send += ret; } } @@ -1080,7 +1080,7 @@ TNetworkAddress::TNetworkAddress(const TString& host, ui16 port) } TNetworkAddress::TNetworkAddress(ui16 port) - : Impl_(new TImpl(nullptr, port, 0)) + : Impl_(new TImpl(nullptr, port, 0)) { } @@ -1091,7 +1091,7 @@ struct addrinfo* TNetworkAddress::Info() const noexcept { } TNetworkResolutionError::TNetworkResolutionError(int error) { - const char* errMsg = nullptr; + const char* errMsg = nullptr; #ifdef _win_ errMsg = LastSystemErrorText(error); // gai_strerror is not thread-safe on Windows #else @@ -1163,7 +1163,7 @@ static inline void SetNonBlockSocket(SOCKET fd, int value) { DWORD written = 0; if (!inbuf) { - WSAEventSelect(fd, nullptr, 0); + WSAEventSelect(fd, nullptr, 0); } if (WSAIoctl(fd, FIONBIO, &inbuf, sizeof(inbuf), &outbuf, sizeof(outbuf), &written, 0, 0) == SOCKET_ERROR) { @@ -1185,7 +1185,7 @@ static inline bool IsNonBlockSocket(SOCKET fd) { void SetNonBlock(SOCKET fd, bool value) { #if defined(_unix_) #if defined(FIONBIO) - Y_UNUSED(SetFlag); // shut up clang about unused function + Y_UNUSED(SetFlag); // shut up clang about unused function int nb = value; if (ioctl(fd, FIONBIO, &nb) < 0) { diff --git a/util/network/socket.h b/util/network/socket.h index 9f0e35e1d2..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -5,8 +5,8 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> #include <util/system/error.h> -#include <util/stream/output.h> -#include <util/stream/input.h> +#include <util/stream/output.h> +#include <util/stream/input.h> #include <util/generic/ptr.h> #include <util/generic/yexception.h> #include <util/generic/noncopyable.h> @@ -223,7 +223,7 @@ public: } inline TIterator End() const noexcept { - return TIterator(nullptr); + return TIterator(nullptr); } private: @@ -297,7 +297,7 @@ private: class TSocket { public: - using TPart = IOutputStream::TPart; + using TPart = IOutputStream::TPart; class TOps { public: @@ -389,7 +389,7 @@ private: TSimpleIntrusivePtr<TImpl> Impl_; }; -class TSocketInput: public IInputStream { +class TSocketInput: public IInputStream { public: TSocketInput(const TSocket& s) noexcept; ~TSocketInput() override; @@ -408,7 +408,7 @@ private: TSocket S_; }; -class TSocketOutput: public IOutputStream { +class TSocketOutput: public IOutputStream { public: TSocketOutput(const TSocket& s) noexcept; ~TSocketOutput() override; diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp index 7156161699..6b20e11f70 100644 --- a/util/network/socket_ut.cpp +++ b/util/network/socket_ut.cpp @@ -219,7 +219,7 @@ class TPollTest: public TTestBase { public: inline TPollTest() { - srand(static_cast<unsigned int>(time(nullptr))); + srand(static_cast<unsigned int>(time(nullptr))); } void TestPollInOut(); @@ -273,7 +273,7 @@ SOCKET TPollTest::StartClientSocket(ui32 ip, ui16 port) { } SOCKET TPollTest::AcceptConnection(SOCKET serverSocket) { - SOCKET connectedSocket = accept(serverSocket, nullptr, nullptr); + SOCKET connectedSocket = accept(serverSocket, nullptr, nullptr); if (connectedSocket == INVALID_SOCKET) { ythrow yexception() << "Can not accept connection on server socket (" << LastSystemErrorText() << ")"; } |