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)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (expandurl-mastodon
|
project (expandurl-mastodon
|
||||||
VERSION 0.2.3
|
VERSION 0.2.4
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
if (!listener.stillrunning())
|
if (!listener.stillrunning())
|
||||||
{
|
{
|
||||||
cout << "DEBUG: Reestablishing connection...\n";
|
cout << "DEBUG: Reestablishing connection...\n";
|
||||||
|
|
|
@ -82,15 +82,29 @@ const void Listener::stop()
|
||||||
|
|
||||||
std::vector<Easy::Notification> Listener::get_new_messages()
|
std::vector<Easy::Notification> Listener::get_new_messages()
|
||||||
{
|
{
|
||||||
const string buffer = _stream;
|
|
||||||
_stream.clear();
|
|
||||||
|
|
||||||
std::vector<Easy::Notification> v;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user