diff options
author | Andrey Fomichev <andrey.fomichev@gmail.com> | 2022-02-10 16:49:12 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:12 +0300 |
commit | e542cc14db4240643a06bb0dde87ecf361f101ab (patch) | |
tree | 3b03a4b94acd11a4eca042532035806e5fa08ad1 /library/cpp/messagebus/network.cpp | |
parent | e2ac73225f30f7fcf7df3cb225cba257f56144c1 (diff) | |
download | ydb-e542cc14db4240643a06bb0dde87ecf361f101ab.tar.gz |
Restoring authorship annotation for Andrey Fomichev <andrey.fomichev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/network.cpp')
-rw-r--r-- | library/cpp/messagebus/network.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/library/cpp/messagebus/network.cpp b/library/cpp/messagebus/network.cpp index 304bedae5a..a8dc5f6155 100644 --- a/library/cpp/messagebus/network.cpp +++ b/library/cpp/messagebus/network.cpp @@ -10,7 +10,7 @@ using namespace NBus; using namespace NBus::NPrivate; namespace { - TBindResult BindOnPortProto(int port, int af, bool reusePort) { + TBindResult BindOnPortProto(int port, int af, bool reusePort) { Y_VERIFY(af == AF_INET || af == AF_INET6, "wrong af"); SOCKET fd = ::socket(af, SOCK_STREAM, 0); @@ -24,17 +24,17 @@ namespace { ythrow TSystemError() << "failed to setsockopt SO_REUSEADDR"; } -#ifdef SO_REUSEPORT - if (reusePort) { - int r = SetSockOpt(fd, SOL_SOCKET, SO_REUSEPORT, one); - if (r < 0) { - ythrow TSystemError() << "failed to setsockopt SO_REUSEPORT"; - } - } -#else - Y_UNUSED(reusePort); -#endif - +#ifdef SO_REUSEPORT + if (reusePort) { + int r = SetSockOpt(fd, SOL_SOCKET, SO_REUSEPORT, one); + if (r < 0) { + ythrow TSystemError() << "failed to setsockopt SO_REUSEPORT"; + } + } +#else + Y_UNUSED(reusePort); +#endif + THolder<TOpaqueAddr> addr(new TOpaqueAddr); sockaddr* sa = addr->MutableAddr(); sa->sa_family = af; @@ -73,7 +73,7 @@ namespace { return r; } - TMaybe<TBindResult> TryBindOnPortProto(int port, int af, bool reusePort) { + TMaybe<TBindResult> TryBindOnPortProto(int port, int af, bool reusePort) { try { return {BindOnPortProto(port, af, reusePort)}; } catch (const TSystemError&) { @@ -93,23 +93,23 @@ namespace { } } -std::pair<unsigned, TVector<TBindResult>> NBus::BindOnPort(int port, bool reusePort) { +std::pair<unsigned, TVector<TBindResult>> NBus::BindOnPort(int port, bool reusePort) { std::pair<unsigned, TVector<TBindResult>> r; r.second.reserve(2); if (port != 0) { - return AggregateBindResults(BindOnPortProto(port, AF_INET, reusePort), + return AggregateBindResults(BindOnPortProto(port, AF_INET, reusePort), BindOnPortProto(port, AF_INET6, reusePort)); } // use nothrow versions in cycle for (int i = 0; i < 1000; ++i) { - TMaybe<TBindResult> in4 = TryBindOnPortProto(0, AF_INET, reusePort); + TMaybe<TBindResult> in4 = TryBindOnPortProto(0, AF_INET, reusePort); if (!in4) { continue; } - TMaybe<TBindResult> in6 = TryBindOnPortProto(in4->Addr.GetPort(), AF_INET6, reusePort); + TMaybe<TBindResult> in6 = TryBindOnPortProto(in4->Addr.GetPort(), AF_INET6, reusePort); if (!in6) { continue; } @@ -117,8 +117,8 @@ std::pair<unsigned, TVector<TBindResult>> NBus::BindOnPort(int port, bool reuseP return AggregateBindResults(std::move(*in4), std::move(*in6)); } - TBindResult in4 = BindOnPortProto(0, AF_INET, reusePort); - TBindResult in6 = BindOnPortProto(in4.Addr.GetPort(), AF_INET6, reusePort); + TBindResult in4 = BindOnPortProto(0, AF_INET, reusePort); + TBindResult in6 = BindOnPortProto(in4.Addr.GetPort(), AF_INET6, reusePort); return AggregateBindResults(std::move(in4), std::move(in6)); } |