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)
|
||||
project (expandurl-mastodon
|
||||
VERSION 0.9.6
|
||||
VERSION 0.9.7
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
while (running)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
if (!listener.stillrunning())
|
||||
{
|
||||
listener.stop();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <syslog.h>
|
||||
#include <chrono>
|
||||
#include "version.hpp"
|
||||
#include "expandurl-mastodon.hpp"
|
||||
|
||||
|
@ -139,16 +140,15 @@ const void Listener::stop()
|
|||
|
||||
const std::vector<Easy::Notification> Listener::get_new_messages()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
|
||||
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());
|
||||
if (!_stream.empty())
|
||||
{
|
||||
const string buffer = _stream;
|
||||
_stream.clear();
|
||||
|
||||
for (const Easy::stream_event &event : Easy::parse_stream(buffer))
|
||||
for (const Easy::stream_event &event : Easy::parse_stream(_stream))
|
||||
{
|
||||
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
|
||||
{
|
||||
// If we got an empty message 5 times, set state to not running
|
||||
++count_empty;
|
||||
if (count_empty > 5)
|
||||
// If the last keep-alive packet was received 25 seconds or more ago
|
||||
if (duration_cast<seconds>(lastping - system_clock::now()).count() >= 25)
|
||||
{
|
||||
count_empty = 0;
|
||||
lastping = system_clock::now();
|
||||
syslog(LOG_NOTICE, "Detected broken connection.");
|
||||
_running = false;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ const void init_replacements()
|
|||
const std::array<const replace_pair, 5> replace_array =
|
||||
{{
|
||||
{ "[\\?&]utm_[^&]+", "" }, // Google
|
||||
{ "[\\?&]wt_?[^&]+", "" }, // Twitter?
|
||||
{ "[\\?&]wt_?[^&]+", "" }, // Twitter?
|
||||
{ "[\\?&]__twitter_impression=[^&]+", "" }, // Twitter?
|
||||
{ "//amp\\.", "//" } // AMP
|
||||
}};
|
||||
|
|
Loading…
Reference in New Issue
Block a user