From 6d578f7e1ee58e7e8570a1286814a77743dbe12e Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 17 May 2018 13:21:45 +0200 Subject: [PATCH] If we got an empty message 5 times, set state to not running --- CMakeLists.txt | 2 +- src/main.cpp | 2 +- src/masto.cpp | 26 ++++++++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a00e6f0..64cb4ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.2.3 + VERSION 0.2.4 LANGUAGES CXX ) diff --git a/src/main.cpp b/src/main.cpp index 61b34b6..5cb1cab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) while (running) { - std::this_thread::sleep_for(std::chrono::seconds(2)); + std::this_thread::sleep_for(std::chrono::seconds(5)); if (!listener.stillrunning()) { cout << "DEBUG: Reestablishing connection...\n"; diff --git a/src/masto.cpp b/src/masto.cpp index a5aab8e..ffae336 100644 --- a/src/masto.cpp +++ b/src/masto.cpp @@ -82,15 +82,29 @@ const void Listener::stop() std::vector Listener::get_new_messages() { - const string buffer = _stream; - _stream.clear(); - std::vector v; - for (const Easy::stream_event &event : Easy::parse_stream(buffer)) + static std::uint_fast8_t count_empty = 0; + + if (!_stream.empty()) { - if (event.first == Easy::event_type::Notification) + const string buffer = _stream; + _stream.clear(); + + for (const Easy::stream_event &event : Easy::parse_stream(buffer)) { - v.push_back(Easy::Notification(event.second)); + if (event.first == Easy::event_type::Notification) + { + v.push_back(Easy::Notification(event.second)); + } + } + } + else + { + // If we got an empty message 5 times, set state to not running + ++count_empty; + if (count_empty > 5) + { + _running = false; } }