diff options
author | leo <leo@yandex-team.ru> | 2022-02-10 16:46:40 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:40 +0300 |
commit | 99609724f661f7e21d1cb08e8d80e87c3632fdb3 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/network | |
parent | 980edcd3304699edf9d4e4d6a656e585028e2a72 (diff) | |
download | ydb-99609724f661f7e21d1cb08e8d80e87c3632fdb3.tar.gz |
Restoring authorship annotation for <leo@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/address.h | 2 | ||||
-rw-r--r-- | util/network/init.h | 6 | ||||
-rw-r--r-- | util/network/ip.h | 2 | ||||
-rw-r--r-- | util/network/pollerimpl.h | 10 | ||||
-rw-r--r-- | util/network/sock.h | 12 | ||||
-rw-r--r-- | util/network/socket.cpp | 56 | ||||
-rw-r--r-- | util/network/socket.h | 16 | ||||
-rw-r--r-- | util/network/socket_ut.cpp | 20 |
8 files changed, 62 insertions, 62 deletions
diff --git a/util/network/address.h b/util/network/address.h index f6ea9bf117..448fcac0c9 100644 --- a/util/network/address.h +++ b/util/network/address.h @@ -87,7 +87,7 @@ namespace NAddr { } socklen_t Len() const override { - return (socklen_t)AI_->ai_addrlen; + return (socklen_t)AI_->ai_addrlen; } private: diff --git a/util/network/init.h b/util/network/init.h index 16c27770f6..08a79c0fca 100644 --- a/util/network/init.h +++ b/util/network/init.h @@ -33,16 +33,16 @@ using SOCKET = int; using nfds_t = ULONG; #undef Yield - + struct sockaddr_un { short sun_family; char sun_path[108]; }; - + #define PF_LOCAL AF_UNIX #define NETDB_INTERNAL -1 #define NETDB_SUCCESS 0 - + #endif #if defined(_win_) || defined(_darwin_) diff --git a/util/network/ip.h b/util/network/ip.h index ad53edad85..dc7c2d24a0 100644 --- a/util/network/ip.h +++ b/util/network/ip.h @@ -29,7 +29,7 @@ static inline TIpHost IpFromString(const char* ipStr) { } static inline char* IpToString(TIpHost ip, char* buf, size_t len) { - if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) { + if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) { ythrow TSystemError() << "Failed to get ip address string"; } diff --git a/util/network/pollerimpl.h b/util/network/pollerimpl.h index a9e8dffe9d..e8c7e40fba 100644 --- a/util/network/pollerimpl.h +++ b/util/network/pollerimpl.h @@ -360,7 +360,7 @@ struct TSelectPollerNoTemplate { (*this)[fd].Set(data, filter); } - inline void Remove(SOCKET fd) { + inline void Remove(SOCKET fd) { erase(fd); } @@ -424,7 +424,7 @@ public: closesocket(Signal_[1]); } - inline void SetImpl(void* data, SOCKET fd, int what) { + inline void SetImpl(void* data, SOCKET fd, int what) { with_lock (CommandLock_) { Commands_.push_back(TCommand(fd, what, data)); } @@ -512,7 +512,7 @@ public: tout.tv_sec = timeout / 1000000; tout.tv_usec = timeout % 1000000; - int ret = ContSelect(int(maxFdNum + 1), in, out, errFds, &tout); + int ret = ContSelect(int(maxFdNum + 1), in, out, errFds, &tout); if (ret > 0 && FD_ISSET(WaitSock(), in)) { --ret; @@ -524,7 +524,7 @@ public: TEvent* eventsStart = events; for (typename TFds::iterator it = Fds_.begin(); it != Fds_.end(); ++it) { - const SOCKET fd = it->first; + const SOCKET fd = it->first; THandle& handle = it->second; if (FD_ISSET(fd, errFds)) { @@ -659,7 +659,7 @@ public: using TEvent = typename TBase::TEvent; - inline void Set(void* data, SOCKET fd, int what) { + inline void Set(void* data, SOCKET fd, int what) { if (what) { this->SetImpl(data, fd, what); } else { diff --git a/util/network/sock.h b/util/network/sock.h index 53ddd4b61b..b10be2f715 100644 --- a/util/network/sock.h +++ b/util/network/sock.h @@ -4,7 +4,7 @@ #include <util/system/defaults.h> #include <util/string/cast.h> #include <util/stream/output.h> -#include <util/system/sysstat.h> +#include <util/system/sysstat.h> #if defined(_win_) || defined(_cygwin_) #include <util/system/file.h> @@ -193,7 +193,7 @@ struct TSockAddrLocal: public sockaddr_un, public ISockAddr { if (ret < 0) return -errno; - ret = Chmod(sun_path, mode); + ret = Chmod(sun_path, mode); if (ret < 0) return -errno; return 0; @@ -365,7 +365,7 @@ public: static ssize_t Check(ssize_t ret, const char* op = "") { if (ret < 0) - ythrow TSystemError(-(int)ret) << "socket operation " << op; + ythrow TSystemError(-(int)ret) << "socket operation " << op; return ret; } }; @@ -461,7 +461,7 @@ public: s = accept((SOCKET) * this, nullptr, nullptr); } - if (s == INVALID_SOCKET) + if (s == INVALID_SOCKET) return -errno; TSocketHolder sock(s); @@ -569,7 +569,7 @@ protected: return (size_t)ret; } - ythrow TSystemError(-(int)ret) << "can not read from socket input stream"; + ythrow TSystemError(-(int)ret) << "can not read from socket input stream"; } }; @@ -597,7 +597,7 @@ protected: const ssize_t ret = Socket->Send(ptr, len); if (ret < 0) { - ythrow TSystemError(-(int)ret) << "can not write to socket output stream"; + ythrow TSystemError(-(int)ret) << "can not write to socket output stream"; } Y_ASSERT((size_t)ret <= len); diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 597740e285..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -6,7 +6,7 @@ #include <util/system/defaults.h> #include <util/system/byteorder.h> - + #if defined(_unix_) #include <netdb.h> #include <sys/types.h> @@ -51,16 +51,16 @@ using namespace NAddr; #if defined(_win_) int inet_aton(const char* cp, struct in_addr* inp) { - sockaddr_in addr; - addr.sin_family = AF_INET; - int psz = sizeof(addr); + sockaddr_in addr; + addr.sin_family = AF_INET; + int psz = sizeof(addr); if (0 == WSAStringToAddress((char*)cp, AF_INET, nullptr, (LPSOCKADDR)&addr, &psz)) { - memcpy(inp, &addr.sin_addr, sizeof(in_addr)); - return 1; - } - return 0; -} - + memcpy(inp, &addr.sin_addr, sizeof(in_addr)); + return 1; + } + return 0; +} + #if (_WIN32_WINNT < 0x0600) const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) { if (af != AF_INET) { @@ -238,8 +238,8 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept { } #endif -#endif - +#endif + bool GetRemoteAddr(SOCKET Socket, char* str, socklen_t size) { if (!size) { return false; @@ -267,7 +267,7 @@ bool GetRemoteAddr(SOCKET Socket, char* str, socklen_t size) { void SetSocketTimeout(SOCKET s, long timeout) { SetSocketTimeout(s, timeout, 0); -} +} void SetSocketTimeout(SOCKET s, long sec, long msec) { #ifdef SO_SNDTIMEO @@ -282,15 +282,15 @@ void SetSocketTimeout(SOCKET s, long sec, long msec) { CheckedSetSockOpt(s, SOL_SOCKET, SO_SNDTIMEO, timeout, "send timeout"); #endif } - + void SetLinger(SOCKET s, bool on, unsigned len) { -#ifdef SO_LINGER - struct linger l = {on, (u_short)len}; +#ifdef SO_LINGER + struct linger l = {on, (u_short)len}; CheckedSetSockOpt(s, SOL_SOCKET, SO_LINGER, l, "linger"); -#endif -} - +#endif +} + void SetZeroLinger(SOCKET s) { SetLinger(s, 1, 0); } @@ -659,7 +659,7 @@ static inline SOCKET DoConnectImpl(const struct addrinfo* res, const TInstant& d SetNonBlock(s, true); - if (connect(s, res->ai_addr, (int)res->ai_addrlen)) { + if (connect(s, res->ai_addr, (int)res->ai_addrlen)) { int err = LastSystemError(); if (err == EINPROGRESS || err == EAGAIN || err == EWOULDBLOCK) { @@ -671,13 +671,13 @@ static inline SOCKET DoConnectImpl(const struct addrinfo* res, const TInstant& d POLLOUT, 0}; - const ssize_t n = PollD(&p, 1, deadLine); + const ssize_t n = PollD(&p, 1, deadLine); /* * timeout occured */ if (n < 0) { - ythrow TSystemError(-(int)n) << "can not connect"; + ythrow TSystemError(-(int)n) << "can not connect"; } CheckedGetSockOpt(s, SOL_SOCKET, SO_ERROR, err, "socket error"); @@ -902,7 +902,7 @@ size_t TSocketInput::DoRead(void* buf, size_t len) { return (size_t)ret; } - ythrow TSystemError(-(int)ret) << "can not read from socket input stream"; + ythrow TSystemError(-(int)ret) << "can not read from socket input stream"; } TSocketOutput::TSocketOutput(const TSocket& s) noexcept @@ -936,7 +936,7 @@ void TSocketOutput::DoWriteV(const TPart* parts, size_t count) { const ssize_t ret = S_.SendV(parts, count); if (ret < 0) { - ythrow TSystemError(-(int)ret) << "can not writev to socket output stream"; + ythrow TSystemError(-(int)ret) << "can not writev to socket output stream"; } /* @@ -1157,7 +1157,7 @@ static inline bool FlagsAreEnabled(int fd, int flags) { #endif #if defined(_win_) -static inline void SetNonBlockSocket(SOCKET fd, int value) { +static inline void SetNonBlockSocket(SOCKET fd, int value) { unsigned long inbuf = value; unsigned long outbuf = 0; DWORD written = 0; @@ -1171,7 +1171,7 @@ static inline void SetNonBlockSocket(SOCKET fd, int value) { } } -static inline bool IsNonBlockSocket(SOCKET fd) { +static inline bool IsNonBlockSocket(SOCKET fd) { unsigned long buf = 0; if (WSAIoctl(fd, FIONBIO, 0, 0, &buf, sizeof(buf), 0, 0, 0) == SOCKET_ERROR) { @@ -1182,7 +1182,7 @@ static inline bool IsNonBlockSocket(SOCKET fd) { } #endif -void SetNonBlock(SOCKET fd, bool value) { +void SetNonBlock(SOCKET fd, bool value) { #if defined(_unix_) #if defined(FIONBIO) Y_UNUSED(SetFlag); // shut up clang about unused function @@ -1201,7 +1201,7 @@ void SetNonBlock(SOCKET fd, bool value) { #endif } -bool IsNonBlock(SOCKET fd) { +bool IsNonBlock(SOCKET fd) { #if defined(_unix_) return FlagsAreEnabled(fd, O_NONBLOCK); #elif defined(_win_) diff --git a/util/network/socket.h b/util/network/socket.h index ea9c01f6bb..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -1,17 +1,17 @@ #pragma once - + #include "init.h" #include <util/system/yassert.h> #include <util/system/defaults.h> -#include <util/system/error.h> +#include <util/system/error.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> #include <util/datetime/base.h> - + #include <cerrno> #ifndef INET_ADDRSTRLEN @@ -50,14 +50,14 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept; int inet_aton(const char* cp, struct in_addr* inp); #define get_host_error() WSAGetLastError() - + #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND #define SHUT_RDWR SD_BOTH #define INFTIM (-1) -#endif - +#endif + template <class T> static inline int SetSockOpt(SOCKET s, int level, int optname, T opt) noexcept { return setsockopt(s, level, optname, (const char*)&opt, sizeof(opt)); @@ -141,8 +141,8 @@ bool HasLocalAddress(SOCKET socket); **/ extern "C" bool IsReusePortAvailable(); -bool IsNonBlock(SOCKET fd); -void SetNonBlock(SOCKET fd, bool nonBlock = true); +bool IsNonBlock(SOCKET fd); +void SetNonBlock(SOCKET fd, bool nonBlock = true); struct addrinfo; diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp index ff7a9e6279..6b20e11f70 100644 --- a/util/network/socket_ut.cpp +++ b/util/network/socket_ut.cpp @@ -312,29 +312,29 @@ void TPollTest::TestPollInOut() { } } - int expectedCount = 0; + int expectedCount = 0; for (size_t i = 0; i < connectedSockets.size(); ++i) { pollfd fd = {(i % 5 == 4) ? INVALID_SOCKET : static_cast<SOCKET>(*connectedSockets[i]), POLLIN | POLLOUT, 0}; fds.push_back(fd); - if (i % 5 != 4) - ++expectedCount; + if (i % 5 != 4) + ++expectedCount; } int polledCount = poll(&fds[0], fds.size(), INFTIM); - UNIT_ASSERT_EQUAL(expectedCount, polledCount); + UNIT_ASSERT_EQUAL(expectedCount, polledCount); for (size_t i = 0; i < connectedSockets.size(); ++i) { - short revents = fds[i].revents; + short revents = fds[i].revents; if (i % 5 == 0) { - UNIT_ASSERT_EQUAL(static_cast<short>(POLLRDNORM | POLLWRNORM), revents); + UNIT_ASSERT_EQUAL(static_cast<short>(POLLRDNORM | POLLWRNORM), revents); } else if (i % 5 == 1) { - UNIT_ASSERT_EQUAL(static_cast<short>(POLLOUT | POLLWRNORM), revents); + UNIT_ASSERT_EQUAL(static_cast<short>(POLLOUT | POLLWRNORM), revents); } else if (i % 5 == 2) { - UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLRDNORM | POLLWRNORM), revents); + UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLRDNORM | POLLWRNORM), revents); } else if (i % 5 == 3) { - UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLWRNORM), revents); + UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLWRNORM), revents); } else if (i % 5 == 4) { - UNIT_ASSERT_EQUAL(static_cast<short>(POLLNVAL), revents); + UNIT_ASSERT_EQUAL(static_cast<short>(POLLNVAL), revents); } } #endif |