reestablishing connection after it is lost
This commit is contained in:
parent
dbebbd934f
commit
18b92496e5
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (expandurl-mastodon
|
||||
VERSION 0.1.3
|
||||
VERSION 0.2.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ public:
|
|||
const bool send_reply(const Easy::Status &to_status, const string &message);
|
||||
const std::uint_fast64_t get_parent_id(Easy::Notification ¬if);
|
||||
|
||||
const bool stillrunning() const;
|
||||
|
||||
private:
|
||||
string _instance;
|
||||
string _access_token;
|
||||
|
@ -85,6 +87,7 @@ private:
|
|||
string _stream;
|
||||
std::unique_ptr<API::http> _ptr;
|
||||
std::thread _thread;
|
||||
bool _running;
|
||||
};
|
||||
|
||||
#endif // EXPANDURL_MASTODON_HPP
|
||||
|
|
|
@ -74,6 +74,11 @@ int main(int argc, char *argv[])
|
|||
while (running)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
if (!listener.stillrunning())
|
||||
{
|
||||
cerr << "DEBUG: Reestablishing connection...\n";
|
||||
listener.start();
|
||||
}
|
||||
|
||||
for (Easy::Notification ¬if : listener.get_new_messages())
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@ Listener::Listener()
|
|||
, _access_token("")
|
||||
, _stream("")
|
||||
, _ptr(nullptr)
|
||||
, _running(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -56,10 +57,13 @@ const bool Listener::start()
|
|||
|
||||
_thread = std::thread([=]
|
||||
{
|
||||
_running = true;
|
||||
Easy masto(_instance, _access_token);
|
||||
masto.set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
||||
global::version);
|
||||
masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr);
|
||||
cerr << "DEBUG: Connection lost.\n";
|
||||
_running = false;
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -182,3 +186,8 @@ const std::uint_fast64_t Listener::get_parent_id(Easy::Notification ¬if)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bool Listener::stillrunning() const
|
||||
{
|
||||
return _running;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user