diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/messagebus/session.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/session.cpp')
-rw-r--r-- | library/cpp/messagebus/session.cpp | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/library/cpp/messagebus/session.cpp b/library/cpp/messagebus/session.cpp index 46a7ece6a8..772984a086 100644 --- a/library/cpp/messagebus/session.cpp +++ b/library/cpp/messagebus/session.cpp @@ -5,126 +5,126 @@ using namespace NBus; namespace NBus { - TBusSession::TBusSession() { - } - - //////////////////////////////////////////////////////////////////// - /// \brief Adds peer of connection into connection list - - int CompareByHost(const IRemoteAddr& l, const IRemoteAddr& r) noexcept { - if (l.Addr()->sa_family != r.Addr()->sa_family) { - return l.Addr()->sa_family < r.Addr()->sa_family ? -1 : +1; - } - - switch (l.Addr()->sa_family) { - case AF_INET: { - return memcmp(&(((const sockaddr_in*)l.Addr())->sin_addr), &(((const sockaddr_in*)r.Addr())->sin_addr), sizeof(in_addr)); - } - - case AF_INET6: { - return memcmp(&(((const sockaddr_in6*)l.Addr())->sin6_addr), &(((const sockaddr_in6*)r.Addr())->sin6_addr), sizeof(in6_addr)); - } + TBusSession::TBusSession() { + } + + //////////////////////////////////////////////////////////////////// + /// \brief Adds peer of connection into connection list + + int CompareByHost(const IRemoteAddr& l, const IRemoteAddr& r) noexcept { + if (l.Addr()->sa_family != r.Addr()->sa_family) { + return l.Addr()->sa_family < r.Addr()->sa_family ? -1 : +1; + } + + switch (l.Addr()->sa_family) { + case AF_INET: { + return memcmp(&(((const sockaddr_in*)l.Addr())->sin_addr), &(((const sockaddr_in*)r.Addr())->sin_addr), sizeof(in_addr)); + } + + case AF_INET6: { + return memcmp(&(((const sockaddr_in6*)l.Addr())->sin6_addr), &(((const sockaddr_in6*)r.Addr())->sin6_addr), sizeof(in6_addr)); + } } - return memcmp(l.Addr(), r.Addr(), Min<size_t>(l.Len(), r.Len())); - } - - bool operator<(const TNetAddr& a1, const TNetAddr& a2) { - return CompareByHost(a1, a2) < 0; - } - - size_t TBusSession::GetInFlight(const TNetAddr& addr) const { - size_t r; - GetInFlightBulk({addr}, MakeArrayRef(&r, 1)); - return r; + return memcmp(l.Addr(), r.Addr(), Min<size_t>(l.Len(), r.Len())); } - size_t TBusSession::GetConnectSyscallsNumForTest(const TNetAddr& addr) const { - size_t r; - GetConnectSyscallsNumBulkForTest({addr}, MakeArrayRef(&r, 1)); - return r; - } - - // Split 'host' into name and port taking into account that host can be specified - // as ipv6 address ('[<ipv6 address]:port' notion). - bool SplitHost(const TString& host, TString* hostName, TString* portNum) { - hostName->clear(); - portNum->clear(); - - // Simple check that we have to deal with ipv6 address specification or - // just host name or ipv4 address. + bool operator<(const TNetAddr& a1, const TNetAddr& a2) { + return CompareByHost(a1, a2) < 0; + } + + size_t TBusSession::GetInFlight(const TNetAddr& addr) const { + size_t r; + GetInFlightBulk({addr}, MakeArrayRef(&r, 1)); + return r; + } + + size_t TBusSession::GetConnectSyscallsNumForTest(const TNetAddr& addr) const { + size_t r; + GetConnectSyscallsNumBulkForTest({addr}, MakeArrayRef(&r, 1)); + return r; + } + + // Split 'host' into name and port taking into account that host can be specified + // as ipv6 address ('[<ipv6 address]:port' notion). + bool SplitHost(const TString& host, TString* hostName, TString* portNum) { + hostName->clear(); + portNum->clear(); + + // Simple check that we have to deal with ipv6 address specification or + // just host name or ipv4 address. if (!host.empty() && (host[0] == '[')) { - size_t pos = host.find(']'); - if (pos < 2 || pos == TString::npos) { - // '[]' and '[<address>' are errors. - return false; + size_t pos = host.find(']'); + if (pos < 2 || pos == TString::npos) { + // '[]' and '[<address>' are errors. + return false; + } + + *hostName = host.substr(1, pos - 1); + + pos++; + if (pos != host.length()) { + if (host[pos] != ':') { + // Do not allow '[...]a' but '[...]:' is ok (as for ipv4 before + return false; + } + + *portNum = host.substr(pos + 1); } - - *hostName = host.substr(1, pos - 1); - - pos++; - if (pos != host.length()) { - if (host[pos] != ':') { - // Do not allow '[...]a' but '[...]:' is ok (as for ipv4 before - return false; - } - - *portNum = host.substr(pos + 1); - } - } else { - size_t pos = host.find(':'); - if (pos != TString::npos) { - if (pos == 0) { - // Treat ':<port>' as errors but allow or '<host>:' for compatibility. - return false; - } - - *portNum = host.substr(pos + 1); + } else { + size_t pos = host.find(':'); + if (pos != TString::npos) { + if (pos == 0) { + // Treat ':<port>' as errors but allow or '<host>:' for compatibility. + return false; + } + + *portNum = host.substr(pos + 1); } - *hostName = host.substr(0, pos); + *hostName = host.substr(0, pos); } - return true; + return true; } - /// registers external session on host:port with locator service - int TBusSession::RegisterService(const char* host, TBusKey start /*= YBUS_KEYMIN*/, TBusKey end /*= YBUS_KEYMAX*/, EIpVersion ipVersion) { - TString hostName; - TString port; - int portNum; + /// registers external session on host:port with locator service + int TBusSession::RegisterService(const char* host, TBusKey start /*= YBUS_KEYMIN*/, TBusKey end /*= YBUS_KEYMAX*/, EIpVersion ipVersion) { + TString hostName; + TString port; + int portNum; - if (!SplitHost(host, &hostName, &port)) { - hostName = host; - } + if (!SplitHost(host, &hostName, &port)) { + hostName = host; + } if (port.empty()) { - portNum = GetProto()->GetPort(); - } else { - try { - portNum = FromString<int>(port); - } catch (const TFromStringException&) { - return -1; - } - } - - TBusService service = GetProto()->GetService(); + portNum = GetProto()->GetPort(); + } else { + try { + portNum = FromString<int>(port); + } catch (const TFromStringException&) { + return -1; + } + } + + TBusService service = GetProto()->GetService(); return GetQueue()->GetLocator()->Register(service, hostName.data(), portNum, start, end, ipVersion); } - TBusSession::~TBusSession() { + TBusSession::~TBusSession() { } } -TBusClientSessionPtr TBusClientSession::Create(TBusProtocol* proto, IBusClientHandler* handler, const TBusClientSessionConfig& config, TBusMessageQueuePtr queue) { +TBusClientSessionPtr TBusClientSession::Create(TBusProtocol* proto, IBusClientHandler* handler, const TBusClientSessionConfig& config, TBusMessageQueuePtr queue) { return queue->CreateSource(proto, handler, config); } -TBusServerSessionPtr TBusServerSession::Create(TBusProtocol* proto, IBusServerHandler* handler, const TBusServerSessionConfig& config, TBusMessageQueuePtr queue) { +TBusServerSessionPtr TBusServerSession::Create(TBusProtocol* proto, IBusServerHandler* handler, const TBusServerSessionConfig& config, TBusMessageQueuePtr queue) { return queue->CreateDestination(proto, handler, config); } -TBusServerSessionPtr TBusServerSession::Create(TBusProtocol* proto, IBusServerHandler* handler, const TBusServerSessionConfig& config, TBusMessageQueuePtr queue, const TVector<TBindResult>& bindTo) { +TBusServerSessionPtr TBusServerSession::Create(TBusProtocol* proto, IBusServerHandler* handler, const TBusServerSessionConfig& config, TBusMessageQueuePtr queue, const TVector<TBindResult>& bindTo) { return queue->CreateDestination(proto, handler, config, bindTo); } |