fix north service handling in case of errors
@@ -57,22 +57,31 @@ DataSender::~DataSender()
*/
void DataSender::sendThread()
{
+ ReadingSet *readings = nullptr;
+ unsigned long lastSent = 0;
+
while (!m_shutdown)
{
- ReadingSet *readings = m_loader->fetchReadings(true);
+
+ if (readings == nullptr) {
+
+ readings = m_loader->fetchReadings(true);
+ }
if (!readings)
{
m_logger->warn(
"Sending thread closing down after failing to fetch readings");
return;
}
- unsigned long lastSent = send(readings);
+ // Sends the new block or retries the previous one
+ lastSent = send(readings);
if (lastSent)
{
m_loader->updateLastSentId(lastSent);
- }
delete readings;
+ readings = nullptr;
+ }
}
m_logger->info("Sending thread shutdown");
}
@@ -85,12 +94,18 @@ void DataSender::sendThread()
*/
unsigned long DataSender::send(ReadingSet *readings)
{
+ unsigned long lastSent;
+
+
blockPause();
+ lastSent = 0;
uint32_t sent = m_plugin->send(readings->getAllReadings());
- releasePause();
- unsigned long lastSent = readings->getLastId();
+
if (sent > 0)
{
+ releasePause();
+ lastSent = readings->getLastId();
+
// Update asset tracker table/cache, if required
vector<Reading *> *vec = readings->getAllReadingsPtr();
