aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/network.cpp
diff options
context:
space:
mode:
authorAndrey Fomichev <andrey.fomichev@gmail.com>2022-02-10 16:49:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:15 +0300
commit1c61afbf3db63940d05e6fefa3104b03457788a1 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/messagebus/network.cpp
parente542cc14db4240643a06bb0dde87ecf361f101ab (diff)
downloadydb-1c61afbf3db63940d05e6fefa3104b03457788a1.tar.gz
Restoring authorship annotation for Andrey Fomichev <andrey.fomichev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/network.cpp')
-rw-r--r--library/cpp/messagebus/network.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/library/cpp/messagebus/network.cpp b/library/cpp/messagebus/network.cpp
index a8dc5f6155..304bedae5a 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));
}