diff options
author | ermolovd <ermolovd@yandex-team.ru> | 2022-02-10 16:47:53 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:53 +0300 |
commit | 2a4a975b112fa0fa138abc7457fe67e0e1e7fd02 (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /util/network | |
parent | b91bcef7c99a119b0846479ef71bfab4beec72ca (diff) | |
download | ydb-2a4a975b112fa0fa138abc7457fe67e0e1e7fd02.tar.gz |
Restoring authorship annotation for <ermolovd@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/socket.cpp | 28 | ||||
-rw-r--r-- | util/network/socket_ut.cpp | 72 |
2 files changed, 50 insertions, 50 deletions
diff --git a/util/network/socket.cpp b/util/network/socket.cpp index cec676b032..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -538,19 +538,19 @@ ESocketReadStatus HasSocketDataToRead(SOCKET s) { } #if defined(_win_) -static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { +static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { return writev(sock, iov, iovcnt); -} -#else -static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { - struct msghdr message; - - Zero(message); - message.msg_iov = const_cast<struct iovec*>(iov); - message.msg_iovlen = iovcnt; - - return sendmsg(sock, &message, MSG_NOSIGNAL); -} +} +#else +static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { + struct msghdr message; + + Zero(message); + message.msg_iov = const_cast<struct iovec*>(iov); + message.msg_iovlen = iovcnt; + + return sendmsg(sock, &message, MSG_NOSIGNAL); +} #endif void TSocketHolder::Close() noexcept { @@ -709,7 +709,7 @@ static inline SOCKET DoConnect(const struct addrinfo* res, const TInstant& deadL static inline ssize_t DoSendV(SOCKET fd, const struct iovec* iov, size_t count) { ssize_t ret = -1; do { - ret = DoSendMsg(fd, iov, (int)count); + ret = DoSendMsg(fd, iov, (int)count); } while (ret == -1 && errno == EINTR); if (ret < 0) { @@ -760,7 +760,7 @@ public: ssize_t Send(SOCKET fd, const void* data, size_t len) override { ssize_t ret = -1; do { - ret = send(fd, (const char*)data, (int)len, MSG_NOSIGNAL); + ret = send(fd, (const char*)data, (int)len, MSG_NOSIGNAL); } while (ret == -1 && errno == EINTR); if (ret < 0) { diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp index 5980c7d370..6b20e11f70 100644 --- a/util/network/socket_ut.cpp +++ b/util/network/socket_ut.cpp @@ -1,7 +1,7 @@ #include "socket.h" -#include "pair.h" - +#include "pair.h" + #include <library/cpp/testing/unittest/registar.h> #include <util/string/builder.h> @@ -23,7 +23,7 @@ class TSockTest: public TTestBase { #endif UNIT_TEST(TestNetworkResolutionError); UNIT_TEST(TestNetworkResolutionErrorMessage); - UNIT_TEST(TestBrokenPipe); + UNIT_TEST(TestBrokenPipe); UNIT_TEST(TestClose); UNIT_TEST(TestReusePortAvailCheck); UNIT_TEST_SUITE_END(); @@ -34,7 +34,7 @@ public: void TestConnectionRefused(); void TestNetworkResolutionError(); void TestNetworkResolutionErrorMessage(); - void TestBrokenPipe(); + void TestBrokenPipe(); void TestClose(); void TestReusePortAvailCheck(); }; @@ -129,43 +129,43 @@ void TSockTest::TestNetworkResolutionErrorMessage() { } class TTempEnableSigPipe { -public: - TTempEnableSigPipe() { +public: + TTempEnableSigPipe() { OriginalSigHandler_ = signal(SIGPIPE, SIG_DFL); Y_VERIFY(OriginalSigHandler_ != SIG_ERR); - } - - ~TTempEnableSigPipe() { + } + + ~TTempEnableSigPipe() { auto ret = signal(SIGPIPE, OriginalSigHandler_); - Y_VERIFY(ret != SIG_ERR); - } - -private: + Y_VERIFY(ret != SIG_ERR); + } + +private: void (*OriginalSigHandler_)(int); -}; - +}; + void TSockTest::TestBrokenPipe() { - TTempEnableSigPipe guard; - - SOCKET socks[2]; - - int ret = SocketPair(socks); - UNIT_ASSERT_VALUES_EQUAL(ret, 0); - - TSocket sender(socks[0]); - TSocket receiver(socks[1]); - receiver.ShutDown(SHUT_RDWR); - int sent = sender.Send("FOO", 3); - UNIT_ASSERT(sent < 0); - - IOutputStream::TPart parts[] = { - {"foo", 3}, - {"bar", 3}, - }; - sent = sender.SendV(parts, 2); - UNIT_ASSERT(sent < 0); -} - + TTempEnableSigPipe guard; + + SOCKET socks[2]; + + int ret = SocketPair(socks); + UNIT_ASSERT_VALUES_EQUAL(ret, 0); + + TSocket sender(socks[0]); + TSocket receiver(socks[1]); + receiver.ShutDown(SHUT_RDWR); + int sent = sender.Send("FOO", 3); + UNIT_ASSERT(sent < 0); + + IOutputStream::TPart parts[] = { + {"foo", 3}, + {"bar", 3}, + }; + sent = sender.SendV(parts, 2); + UNIT_ASSERT(sent < 0); +} + void TSockTest::TestClose() { SOCKET socks[2]; |