From 95c9eea3df4623dc7eb7f8ba4e3c0cc5c29b9336 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 26 May 2018 11:14:08 +0200 Subject: [PATCH] Added 30-second delay on stream error --- CMakeLists.txt | 2 +- src/masto.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a83bf87..f16bf1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.6.4 + VERSION 0.6.5 LANGUAGES CXX ) diff --git a/src/masto.cpp b/src/masto.cpp index 2fab7ac..805d555 100644 --- a/src/masto.cpp +++ b/src/masto.cpp @@ -110,12 +110,19 @@ const void Listener::start() { _thread = std::thread([=] { + std::uint_fast16_t ret = 0; _running = true; Easy masto(_instance, _access_token); masto.set_useragent(static_cast("expandurl-mastodon/") + global::version); - masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr); + ret = masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr); syslog(LOG_DEBUG, "Connection lost."); + if (ret != 0 && ret != 14) // 14 means canceled by user + { + syslog(LOG_ERR, "Connection terminated: Error %u", ret); + syslog(LOG_INFO, "Waiting for 30 seconds"); + std::this_thread::sleep_for(std::chrono::seconds(30)); + } _running = false; }); while (_ptr == nullptr)