aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus
diff options
context:
space:
mode:
authoruzhas <uzhas@yandex-team.ru>2022-02-10 16:47:07 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:07 +0300
commit531b7c7053348b9d4c8ff3832d1b8db5a1918125 (patch)
treeb83306b6e37edeea782e9eed673d89286c4fef35 /library/cpp/messagebus
parent2002caab389ddffd0e7db4d8c4db835fa4c99f83 (diff)
downloadydb-531b7c7053348b9d4c8ff3832d1b8db5a1918125.tar.gz
Restoring authorship annotation for <uzhas@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus')
-rw-r--r--library/cpp/messagebus/message.h10
-rw-r--r--library/cpp/messagebus/message_ptr_and_header.h4
-rw-r--r--library/cpp/messagebus/network.cpp88
-rw-r--r--library/cpp/messagebus/network_ut.cpp6
4 files changed, 54 insertions, 54 deletions
diff --git a/library/cpp/messagebus/message.h b/library/cpp/messagebus/message.h
index 0fc1a1b707..005ca10c65 100644
--- a/library/cpp/messagebus/message.h
+++ b/library/cpp/messagebus/message.h
@@ -120,11 +120,11 @@ namespace NBus {
struct TBusHeader {
friend class TBusMessage;
- TBusKey Id = 0; ///< unique message ID
- ui32 Size = 0; ///< total size of the message
- TBusInstant SendTime = 0; ///< time the message was sent
- ui16 FlagsInternal = 0; ///< TRACE is one of the flags
- ui16 Type = 0; ///< to be used by TBusProtocol
+ TBusKey Id = 0; ///< unique message ID
+ ui32 Size = 0; ///< total size of the message
+ TBusInstant SendTime = 0; ///< time the message was sent
+ ui16 FlagsInternal = 0; ///< TRACE is one of the flags
+ ui16 Type = 0; ///< to be used by TBusProtocol
int GetVersionInternal() {
return (FlagsInternal & MESSAGE_VERSION_INTERNAL) >> 4;
diff --git a/library/cpp/messagebus/message_ptr_and_header.h b/library/cpp/messagebus/message_ptr_and_header.h
index c4364f690f..9b4e2fd270 100644
--- a/library/cpp/messagebus/message_ptr_and_header.h
+++ b/library/cpp/messagebus/message_ptr_and_header.h
@@ -18,8 +18,8 @@ namespace NBus {
{
}
- explicit TBusMessagePtrAndHeader(TBusMessage* messagePtr)
- : MessagePtr(messagePtr)
+ explicit TBusMessagePtrAndHeader(TBusMessage* messagePtr)
+ : MessagePtr(messagePtr)
, Header(*MessagePtr->GetHeader())
, LocalFlags(MessagePtr->LocalFlags)
{
diff --git a/library/cpp/messagebus/network.cpp b/library/cpp/messagebus/network.cpp
index 1e2a89d605..304bedae5a 100644
--- a/library/cpp/messagebus/network.cpp
+++ b/library/cpp/messagebus/network.cpp
@@ -14,15 +14,15 @@ namespace {
Y_VERIFY(af == AF_INET || af == AF_INET6, "wrong af");
SOCKET fd = ::socket(af, SOCK_STREAM, 0);
- if (fd == INVALID_SOCKET) {
- ythrow TSystemError() << "failed to create a socket";
- }
+ if (fd == INVALID_SOCKET) {
+ ythrow TSystemError() << "failed to create a socket";
+ }
int one = 1;
int r1 = SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, one);
- if (r1 < 0) {
- ythrow TSystemError() << "failed to setsockopt SO_REUSEADDR";
- }
+ if (r1 < 0) {
+ ythrow TSystemError() << "failed to setsockopt SO_REUSEADDR";
+ }
#ifdef SO_REUSEPORT
if (reusePort) {
@@ -54,72 +54,72 @@ namespace {
int r2 = ::bind(fd, sa, len);
if (r2 < 0) {
- ythrow TSystemError() << "failed to bind on port " << port;
+ ythrow TSystemError() << "failed to bind on port " << port;
}
int rsn = ::getsockname(fd, addr->MutableAddr(), addr->LenPtr());
- if (rsn < 0) {
- ythrow TSystemError() << "failed to getsockname";
- }
+ if (rsn < 0) {
+ ythrow TSystemError() << "failed to getsockname";
+ }
int r3 = ::listen(fd, 50);
- if (r3 < 0) {
- ythrow TSystemError() << "listen failed";
- }
+ if (r3 < 0) {
+ ythrow TSystemError() << "listen failed";
+ }
TBindResult r;
r.Socket.Reset(new TSocketHolder(fd));
r.Addr = TNetAddr(addr.Release());
return r;
}
-
+
TMaybe<TBindResult> TryBindOnPortProto(int port, int af, bool reusePort) {
- try {
+ try {
return {BindOnPortProto(port, af, reusePort)};
- } catch (const TSystemError&) {
- return {};
- }
- }
-
- std::pair<unsigned, TVector<TBindResult>> AggregateBindResults(TBindResult&& r1, TBindResult&& r2) {
- Y_VERIFY(r1.Addr.GetPort() == r2.Addr.GetPort(), "internal");
- std::pair<unsigned, TVector<TBindResult>> r;
- r.second.reserve(2);
-
- r.first = r1.Addr.GetPort();
- r.second.emplace_back(std::move(r1));
- r.second.emplace_back(std::move(r2));
- return r;
- }
+ } catch (const TSystemError&) {
+ return {};
+ }
+ }
+
+ std::pair<unsigned, TVector<TBindResult>> AggregateBindResults(TBindResult&& r1, TBindResult&& r2) {
+ Y_VERIFY(r1.Addr.GetPort() == r2.Addr.GetPort(), "internal");
+ std::pair<unsigned, TVector<TBindResult>> r;
+ r.second.reserve(2);
+
+ r.first = r1.Addr.GetPort();
+ r.second.emplace_back(std::move(r1));
+ r.second.emplace_back(std::move(r2));
+ return r;
+ }
}
std::pair<unsigned, TVector<TBindResult>> NBus::BindOnPort(int port, bool reusePort) {
std::pair<unsigned, TVector<TBindResult>> r;
- r.second.reserve(2);
+ r.second.reserve(2);
if (port != 0) {
return AggregateBindResults(BindOnPortProto(port, AF_INET, reusePort),
BindOnPortProto(port, AF_INET6, reusePort));
- }
-
- // use nothrow versions in cycle
- for (int i = 0; i < 1000; ++i) {
+ }
+
+ // use nothrow versions in cycle
+ for (int i = 0; i < 1000; ++i) {
TMaybe<TBindResult> in4 = TryBindOnPortProto(0, AF_INET, reusePort);
- if (!in4) {
- continue;
+ if (!in4) {
+ continue;
}
-
+
TMaybe<TBindResult> in6 = TryBindOnPortProto(in4->Addr.GetPort(), AF_INET6, reusePort);
- if (!in6) {
- continue;
+ if (!in6) {
+ continue;
}
-
- return AggregateBindResults(std::move(*in4), std::move(*in6));
+
+ return AggregateBindResults(std::move(*in4), std::move(*in6));
}
-
+
TBindResult in4 = BindOnPortProto(0, AF_INET, reusePort);
TBindResult in6 = BindOnPortProto(in4.Addr.GetPort(), AF_INET6, reusePort);
- return AggregateBindResults(std::move(in4), std::move(in6));
+ return AggregateBindResults(std::move(in4), std::move(in6));
}
void NBus::NPrivate::SetSockOptTcpCork(SOCKET s, bool value) {
diff --git a/library/cpp/messagebus/network_ut.cpp b/library/cpp/messagebus/network_ut.cpp
index f919286e8d..f1798419db 100644
--- a/library/cpp/messagebus/network_ut.cpp
+++ b/library/cpp/messagebus/network_ut.cpp
@@ -56,10 +56,10 @@ Y_UNIT_TEST_SUITE(Network) {
UNIT_ASSERT_VALUES_EQUAL(r.at(0).Addr.GetPort(), r.at(1).Addr.GetPort());
}
-
+
Y_UNIT_TEST(BindOnBusyPort) {
auto r = BindOnPort(0, false);
-
+
UNIT_ASSERT_EXCEPTION_CONTAINS(BindOnPort(r.first, false), TSystemError, "failed to bind on port " + ToString(r.first));
- }
+ }
}