If we got an empty message 5 times, set state to not running
This commit is contained in:
parent
286a9baa06
commit
6d578f7e1e
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (expandurl-mastodon
|
||||
VERSION 0.2.3
|
||||
VERSION 0.2.4
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -82,10 +82,14 @@ const void Listener::stop()
|
|||
|
||||
std::vector<Easy::Notification> Listener::get_new_messages()
|
||||
{
|
||||
std::vector<Easy::Notification> v;
|
||||
static std::uint_fast8_t count_empty = 0;
|
||||
|
||||
if (!_stream.empty())
|
||||
{
|
||||
const string buffer = _stream;
|
||||
_stream.clear();
|
||||
|
||||
std::vector<Easy::Notification> v;
|
||||
for (const Easy::stream_event &event : Easy::parse_stream(buffer))
|
||||
{
|
||||
if (event.first == Easy::event_type::Notification)
|
||||
|
@ -93,6 +97,16 @@ std::vector<Easy::Notification> Listener::get_new_messages()
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user