Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.cpp (1 of 7 files). Show all
Unified · Split
| @@ -67,10 +67,11 @@ struct ClientConnectedInfo · 66 unmodified lines | ||
| 67 | 67 | |
| 68 | 68 | ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandChannelService, IOContext& dataChannelService) : |
| 69 | 69 | m_parent(std::move(parent)), |
| 70 | + m_commandChannelService(commandChannelService), | |
| 70 | 71 | m_subscriberID(NewGuid()), |
| 71 | 72 | m_operationalModes(OperationalModes::NoFlags), |
| 72 | 73 | m_encoding(OperationalEncoding::UTF8), |
| 73 | − m_commandChannelSocket(commandChannelService), | |
| 74 | + m_commandChannelSocket(m_commandChannelService), | |
| 74 | 75 | m_udpPort(0), |
| 75 | 76 | m_dataChannelSocket(dataChannelService), |
| 76 | 77 | m_timeIndex(0), |
| @@ -81,42 +82,6 @@ ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandCh · 4 unmodified lines | ||
| 81 | 82 | m_pingTimer.SetAutoReset(true); |
| 82 | 83 | m_pingTimer.SetCallback(&ClientConnection::PingTimerElapsed); |
| 83 | 84 | m_pingTimer.SetUserData(this); |
| 84 | − | |
| 85 | − // Attempt to lookup remote connection identification for logging purposes | |
| 86 | − auto remoteEndPoint = m_commandChannelSocket.remote_endpoint(); | |
| 87 | − m_ipAddress = remoteEndPoint.address(); | |
| 88 | − | |
| 89 | − if (remoteEndPoint.protocol() == tcp::v6()) | |
| 90 | − m_connectionID = "[" + m_ipAddress.to_string() + "]:" + ToString(remoteEndPoint.port()); | |
| 91 | − else | |
| 92 | − m_connectionID = m_ipAddress.to_string() + ":" + ToString(remoteEndPoint.port()); | |
| 93 | − | |
| 94 | − try | |
| 95 | − { | |
| 96 | − DnsResolver resolver(commandChannelService); | |
| 97 | − const DnsResolver::query query(m_ipAddress.to_string(), ToString(remoteEndPoint.port())); | |
| 98 | − DnsResolver::iterator iterator = resolver.resolve(query); | |
| 99 | − const DnsResolver::iterator end; | |
| 100 | − | |
| 101 | − while (iterator != end) | |
| 102 | − { | |
| 103 | − auto endPoint = *iterator++; | |
| 104 | − | |
| 105 | − if (!endPoint.host_name().empty()) | |
| 106 | − { | |
| 107 | − m_hostName = endPoint.host_name(); | |
| 108 | − m_connectionID = m_hostName + " (" + m_connectionID + ")"; | |
| 109 | − break; | |
| 110 | − } | |
| 111 | − } | |
| 112 | − } | |
| 113 | − catch (...) | |
| 114 | − { //-V565 | |
| 115 | − // DNS lookup failure is not a catastrophe | |
| 116 | − } | |
| 117 | − | |
| 118 | − if (m_hostName.empty()) | |
| 119 | − m_hostName = m_ipAddress.to_string(); | |
| 120 | 85 | } |
| 121 | 86 | |
| 122 | 87 | ClientConnection::~ClientConnection() = default; |
| @@ -190,7 +155,43 @@ std::vector<uint8_t> ClientConnection::IVs(int cipherIndex) · 67 unmodified lines | ||
| 190 | 155 | |
| 191 | 156 | void ClientConnection::Start() |
| 192 | 157 | { |
| 193 | − | |
| 158 | + // Attempt to lookup remote connection identification for logging purposes | |
| 159 | + auto remoteEndPoint = m_commandChannelSocket.remote_endpoint(); | |
| 160 | + m_ipAddress = remoteEndPoint.address(); | |
| 161 | + | |
| 162 | + if (remoteEndPoint.protocol() == tcp::v6()) | |
| 163 | + m_connectionID = "[" + m_ipAddress.to_string() + "]:" + ToString(remoteEndPoint.port()); | |
| 164 | + else | |
| 165 | + m_connectionID = m_ipAddress.to_string() + ":" + ToString(remoteEndPoint.port()); | |
| 166 | + | |
| 167 | + try | |
| 168 | + { | |
| 169 | + DnsResolver resolver(m_commandChannelService); | |
| 170 | + const DnsResolver::query query(m_ipAddress.to_string(), ToString(remoteEndPoint.port())); | |
| 171 | + DnsResolver::iterator iterator = resolver.resolve(query); | |
| 172 | + const DnsResolver::iterator end; | |
| 173 | + | |
| 174 | + while (iterator != end) | |
| 175 | + { | |
| 176 | + auto endPoint = *iterator++; | |
| 177 | + | |
| 178 | + if (!endPoint.host_name().empty()) | |
| 179 | + { | |
| 180 | + m_hostName = endPoint.host_name(); | |
| 181 | + m_connectionID = m_hostName + " (" + m_connectionID + ")"; | |
| 182 | + break; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + } | |
| 186 | + catch (...) | |
| 187 | + { //-V565 | |
| 188 | + // DNS lookup failure is not a catastrophe | |
| 189 | + } | |
| 190 | + | |
| 191 | + if (m_hostName.empty()) | |
| 192 | + m_hostName = m_ipAddress.to_string(); | |
| 193 | + | |
| 194 | + m_pingTimer.Start(); | |
| 194 | 195 | } |
| 195 | 196 | |
| 196 | 197 | void ClientConnection::CommandChannelSendAsync(uint8_t* data, uint32_t offset, uint32_t length) |
| @@ -241,7 +242,6 @@ DataPublisher::DataPublisher(const TcpEndPoint& endpoint) : · 44 unmodified lines | ||
| 241 | 242 | m_errorMessageCallback(nullptr), |
| 242 | 243 | m_clientConnectedCallback(nullptr) |
| 243 | 244 | { |
| 244 | − m_commandChannelService.restart(); | |
| 245 | 245 | m_callbackThread = Thread(bind(&DataPublisher::RunCallbackThread, this)); |
| 246 | 246 | m_commandChannelAcceptThread = Thread(bind(&DataPublisher::RunCommandChannelAcceptThread, this)); |
| 247 | 247 | } |
| @@ -253,6 +253,13 @@ DataPublisher::DataPublisher(uint16_t port, bool ipV6) : · 5 unmodified lines | ||
| 253 | 253 | |
| 254 | 254 | DataPublisher::~DataPublisher() = default; |
| 255 | 255 | |
| 256 | +DataPublisher::CallbackDispatcher::CallbackDispatcher() : | |
| 257 | + Source(nullptr), | |
| 258 | + Data(nullptr), | |
| 259 | + Function(nullptr) | |
| 260 | +{ | |
| 261 | +} | |
| 262 | + | |
| 256 | 263 | void DataPublisher::RunCallbackThread() |
| 257 | 264 | { |
| 258 | 265 | while (true) |
| @@ -346,8 +353,8 @@ void DataPublisher::HandleMetadataRefresh(const ClientConnectionPtr& connection, · 87 unmodified lines | ||
| 346 | 353 | |
| 347 | 354 | if (rowCount > 0) |
| 348 | 355 | { |
| 349 | − const auto elapsedTime = (UtcNow() - startTime).total_seconds(); | |
| 350 | − DispatchStatusMessage(ToString(rowCount) + " records spanning " + ToString(tables.size()) + " tables of meta-data prepared in " + ToString(elapsedTime) + " seconds, sending response to " + connection->GetConnectionID() + "..."); | |
| 356 | + const TimeSpan elapsedTime = UtcNow() - startTime; | |
| 357 | + DispatchStatusMessage(ToString(rowCount) + " records spanning " + ToString(tables.size()) + " tables of meta-data prepared in " + ToString(elapsedTime) + ", sending response to " + connection->GetConnectionID() + "..."); | |
| 351 | 358 | } |
| 352 | 359 | else |
| 353 | 360 | { |