History

TimeSeriesPlatformLibrary: Updated SimplePublish sample to properly run.

J. Ritchie Carroll committed 7 years ago

Commit 4d190cd1 parent 285fcea7 files · +108 −99Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.cpp (1 of 7 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Transport/DataPublisher.cpp+48−41
@@ -67,10 +67,11 @@ struct ClientConnectedInfo · 66 unmodified lines
6767
6868 ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandChannelService, IOContext& dataChannelService) :
6969 m_parent(std::move(parent)),
70+ m_commandChannelService(commandChannelService),
7071 m_subscriberID(NewGuid()),
7172 m_operationalModes(OperationalModes::NoFlags),
7273 m_encoding(OperationalEncoding::UTF8),
73− m_commandChannelSocket(commandChannelService),
74+ m_commandChannelSocket(m_commandChannelService),
7475 m_udpPort(0),
7576 m_dataChannelSocket(dataChannelService),
7677 m_timeIndex(0),
@@ -81,42 +82,6 @@ ClientConnection::ClientConnection(DataPublisherPtr parent, IOContext& commandCh · 4 unmodified lines
8182 m_pingTimer.SetAutoReset(true);
8283 m_pingTimer.SetCallback(&ClientConnection::PingTimerElapsed);
8384 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();
12085 }
12186
12287 ClientConnection::~ClientConnection() = default;
@@ -190,7 +155,43 @@ std::vector<uint8_t> ClientConnection::IVs(int cipherIndex) · 67 unmodified lines
190155
191156 void ClientConnection::Start()
192157 {
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();
194195 }
195196
196197 void ClientConnection::CommandChannelSendAsync(uint8_t* data, uint32_t offset, uint32_t length)
@@ -241,7 +242,6 @@ DataPublisher::DataPublisher(const TcpEndPoint& endpoint) : · 44 unmodified lines
241242 m_errorMessageCallback(nullptr),
242243 m_clientConnectedCallback(nullptr)
243244 {
244− m_commandChannelService.restart();
245245 m_callbackThread = Thread(bind(&DataPublisher::RunCallbackThread, this));
246246 m_commandChannelAcceptThread = Thread(bind(&DataPublisher::RunCommandChannelAcceptThread, this));
247247 }
@@ -253,6 +253,13 @@ DataPublisher::DataPublisher(uint16_t port, bool ipV6) : · 5 unmodified lines
253253
254254 DataPublisher::~DataPublisher() = default;
255255
256+DataPublisher::CallbackDispatcher::CallbackDispatcher() :
257+ Source(nullptr),
258+ Data(nullptr),
259+ Function(nullptr)
260+{
261+}
262+
256263 void DataPublisher::RunCallbackThread()
257264 {
258265 while (true)
@@ -346,8 +353,8 @@ void DataPublisher::HandleMetadataRefresh(const ClientConnectionPtr& connection, · 87 unmodified lines
346353
347354 if (rowCount > 0)
348355 {
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() + "...");
351358 }
352359 else
353360 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t