diff options
author | cerevra <cerevra@yandex-team.ru> | 2022-02-10 16:45:59 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:59 +0300 |
commit | 4f292c7e2fd0a41da93fda51b2d440c979a330b7 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/network | |
parent | bf41dd01f6c920583e9faae7cd55ed25e547e052 (diff) | |
download | ydb-4f292c7e2fd0a41da93fda51b2d440c979a330b7.tar.gz |
Restoring authorship annotation for <cerevra@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/socket.cpp | 90 | ||||
-rw-r--r-- | util/network/socket.h | 6 | ||||
-rw-r--r-- | util/network/socket_ut.cpp | 70 |
3 files changed, 83 insertions, 83 deletions
diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 6a7d3a9d28..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -490,44 +490,44 @@ void SetTcpFastOpen(SOCKET s, int qlen) { #endif } -static bool IsBlocked(int lasterr) noexcept { - return lasterr == EAGAIN || lasterr == EWOULDBLOCK; -} - -struct TUnblockingGuard { - SOCKET S_; - - TUnblockingGuard(SOCKET s) - : S_(s) - { - SetNonBlock(S_, true); - } - - ~TUnblockingGuard() { - SetNonBlock(S_, false); - } -}; - -static int MsgPeek(SOCKET s) { - int flags = MSG_PEEK; - +static bool IsBlocked(int lasterr) noexcept { + return lasterr == EAGAIN || lasterr == EWOULDBLOCK; +} + +struct TUnblockingGuard { + SOCKET S_; + + TUnblockingGuard(SOCKET s) + : S_(s) + { + SetNonBlock(S_, true); + } + + ~TUnblockingGuard() { + SetNonBlock(S_, false); + } +}; + +static int MsgPeek(SOCKET s) { + int flags = MSG_PEEK; + #if defined(_win_) - TUnblockingGuard unblocker(s); - Y_UNUSED(unblocker); -#else - flags |= MSG_DONTWAIT; -#endif - - char c; - return recv(s, &c, 1, flags); -} - -bool IsNotSocketClosedByOtherSide(SOCKET s) { + TUnblockingGuard unblocker(s); + Y_UNUSED(unblocker); +#else + flags |= MSG_DONTWAIT; +#endif + + char c; + return recv(s, &c, 1, flags); +} + +bool IsNotSocketClosedByOtherSide(SOCKET s) { return HasSocketDataToRead(s) != ESocketReadStatus::SocketClosed; } ESocketReadStatus HasSocketDataToRead(SOCKET s) { - const int r = MsgPeek(s); + const int r = MsgPeek(s); if (r == -1 && IsBlocked(LastSystemError())) { return ESocketReadStatus::NoData; } @@ -535,9 +535,9 @@ ESocketReadStatus HasSocketDataToRead(SOCKET s) { return ESocketReadStatus::HasData; } return ESocketReadStatus::SocketClosed; -} - -#if defined(_win_) +} + +#if defined(_win_) static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { return writev(sock, iov, iovcnt); } @@ -1097,15 +1097,15 @@ TNetworkResolutionError::TNetworkResolutionError(int error) { #else errMsg = gai_strerror(error); #endif - (*this) << errMsg << "(" << error; - -#if defined(_unix_) - if (error == EAI_SYSTEM) { - (*this) << "; errno=" << LastSystemError(); - } -#endif - - (*this) << "): "; + (*this) << errMsg << "(" << error; + +#if defined(_unix_) + if (error == EAI_SYSTEM) { + (*this) << "; errno=" << LastSystemError(); + } +#endif + + (*this) << "): "; } #if defined(_unix_) diff --git a/util/network/socket.h b/util/network/socket.h index f5c3279e5e..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -120,14 +120,14 @@ void SetSocketPriority(SOCKET s, int priority); void SetTcpFastOpen(SOCKET s, int qlen); /** * Deprecated, consider using HasSocketDataToRead instead. - **/ -bool IsNotSocketClosedByOtherSide(SOCKET s); + **/ +bool IsNotSocketClosedByOtherSide(SOCKET s); enum class ESocketReadStatus { HasData, NoData, SocketClosed }; -/** +/** * Useful for keep-alive connections. **/ ESocketReadStatus HasSocketDataToRead(SOCKET s); diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp index 00f27fce4b..6b20e11f70 100644 --- a/util/network/socket_ut.cpp +++ b/util/network/socket_ut.cpp @@ -22,7 +22,7 @@ class TSockTest: public TTestBase { UNIT_TEST_EXCEPTION(TestConnectionRefused, yexception); #endif UNIT_TEST(TestNetworkResolutionError); - UNIT_TEST(TestNetworkResolutionErrorMessage); + UNIT_TEST(TestNetworkResolutionErrorMessage); UNIT_TEST(TestBrokenPipe); UNIT_TEST(TestClose); UNIT_TEST(TestReusePortAvailCheck); @@ -33,7 +33,7 @@ public: void TestTimeout(); void TestConnectionRefused(); void TestNetworkResolutionError(); - void TestNetworkResolutionErrorMessage(); + void TestNetworkResolutionErrorMessage(); void TestBrokenPipe(); void TestClose(); void TestReusePortAvailCheck(); @@ -92,42 +92,42 @@ void TSockTest::TestNetworkResolutionError() { } } -void TSockTest::TestNetworkResolutionErrorMessage() { -#ifdef _unix_ - auto str = [](int code) -> TString { - return TNetworkResolutionError(code).what(); - }; - - auto expected = [](int code) -> TString { - return gai_strerror(code); - }; - - struct TErrnoGuard { - TErrnoGuard() +void TSockTest::TestNetworkResolutionErrorMessage() { +#ifdef _unix_ + auto str = [](int code) -> TString { + return TNetworkResolutionError(code).what(); + }; + + auto expected = [](int code) -> TString { + return gai_strerror(code); + }; + + struct TErrnoGuard { + TErrnoGuard() : PrevValue_(errno) - { - } - - ~TErrnoGuard() { + { + } + + ~TErrnoGuard() { errno = PrevValue_; - } - - private: + } + + private: int PrevValue_; - } g; - - UNIT_ASSERT_VALUES_EQUAL(expected(0) + "(0): ", str(0)); - UNIT_ASSERT_VALUES_EQUAL(expected(-9) + "(-9): ", str(-9)); - - errno = 0; - UNIT_ASSERT_VALUES_EQUAL(expected(EAI_SYSTEM) + "(" + IntToString<10>(EAI_SYSTEM) + "; errno=0): ", - str(EAI_SYSTEM)); - errno = 110; - UNIT_ASSERT_VALUES_EQUAL(expected(EAI_SYSTEM) + "(" + IntToString<10>(EAI_SYSTEM) + "; errno=110): ", - str(EAI_SYSTEM)); -#endif -} - + } g; + + UNIT_ASSERT_VALUES_EQUAL(expected(0) + "(0): ", str(0)); + UNIT_ASSERT_VALUES_EQUAL(expected(-9) + "(-9): ", str(-9)); + + errno = 0; + UNIT_ASSERT_VALUES_EQUAL(expected(EAI_SYSTEM) + "(" + IntToString<10>(EAI_SYSTEM) + "; errno=0): ", + str(EAI_SYSTEM)); + errno = 110; + UNIT_ASSERT_VALUES_EQUAL(expected(EAI_SYSTEM) + "(" + IntToString<10>(EAI_SYSTEM) + "; errno=110): ", + str(EAI_SYSTEM)); +#endif +} + class TTempEnableSigPipe { public: TTempEnableSigPipe() { |