If we got an empty message 5 times, set state to not running

This commit is contained in:
tastytea 2018-05-17 13:21:45 +02:00
parent 286a9baa06
commit 6d578f7e1e
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
3 changed files with 22 additions and 8 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.2.3
VERSION 0.2.4
LANGUAGES CXX
)

View File

@ -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";

View File

@ -82,15 +82,29 @@ const void Listener::stop()
std::vector<Easy::Notification> Listener::get_new_messages()
{
const string buffer = _stream;
_stream.clear();
std::vector<Easy::Notification> 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;
}
}