Check for new messages every 2 seconds (was: 5), made the connection-brokenness-detection easier to understand
This commit is contained in:
parent
f70b5f1a82
commit
209743fd55
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (expandurl-mastodon
|
project (expandurl-mastodon
|
||||||
VERSION 0.9.6
|
VERSION 0.9.7
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
if (!listener.stillrunning())
|
if (!listener.stillrunning())
|
||||||
{
|
{
|
||||||
listener.stop();
|
listener.stop();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <chrono>
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include "expandurl-mastodon.hpp"
|
#include "expandurl-mastodon.hpp"
|
||||||
|
|
||||||
|
@ -139,16 +140,15 @@ const void Listener::stop()
|
||||||
|
|
||||||
const std::vector<Easy::Notification> Listener::get_new_messages()
|
const std::vector<Easy::Notification> Listener::get_new_messages()
|
||||||
{
|
{
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
std::vector<Easy::Notification> v;
|
std::vector<Easy::Notification> v;
|
||||||
static std::uint_fast8_t count_empty = 0;
|
static system_clock::time_point lastping = system_clock::now();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(_ptr->get_mutex());
|
std::lock_guard<std::mutex> lock(_ptr->get_mutex());
|
||||||
if (!_stream.empty())
|
if (!_stream.empty())
|
||||||
{
|
{
|
||||||
const string buffer = _stream;
|
for (const Easy::stream_event &event : Easy::parse_stream(_stream))
|
||||||
_stream.clear();
|
|
||||||
|
|
||||||
for (const Easy::stream_event &event : Easy::parse_stream(buffer))
|
|
||||||
{
|
{
|
||||||
if (event.first == Easy::event_type::Notification)
|
if (event.first == Easy::event_type::Notification)
|
||||||
{
|
{
|
||||||
|
@ -159,15 +159,15 @@ const std::vector<Easy::Notification> Listener::get_new_messages()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count_empty = 0;
|
_stream.clear();
|
||||||
|
lastping = system_clock::now();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If we got an empty message 5 times, set state to not running
|
// If the last keep-alive packet was received 25 seconds or more ago
|
||||||
++count_empty;
|
if (duration_cast<seconds>(lastping - system_clock::now()).count() >= 25)
|
||||||
if (count_empty > 5)
|
|
||||||
{
|
{
|
||||||
count_empty = 0;
|
lastping = system_clock::now();
|
||||||
syslog(LOG_NOTICE, "Detected broken connection.");
|
syslog(LOG_NOTICE, "Detected broken connection.");
|
||||||
_running = false;
|
_running = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user