43 lines
968 B
C++
43 lines
968 B
C++
#include "watchdog_thread.hpp"
|
|
|
|
#include "connection.hpp"
|
|
#include "irc_parse_thread.hpp"
|
|
|
|
#include <chrono>
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
WatchdogThread::WatchdogThread(Connection * connection) noexcept
|
|
: connection_{connection}
|
|
{
|
|
}
|
|
|
|
auto WatchdogThread::priority() const -> priority_type
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
auto WatchdogThread::on_event(Event const& event) -> std::pair<ThreadOutcome, EventOutcome>
|
|
{
|
|
if (auto const irc_event = dynamic_cast<LineEvent const*>(&event))
|
|
{
|
|
timer_.expires_from_now(30s);
|
|
return {};
|
|
}
|
|
if (auto const connect_event = dynamic_cast<ConnectEvent const*>(&event))
|
|
{
|
|
timer_.expires_from_now(30s);
|
|
timer_.async_wait([weak = weak_from_this()](auto error)
|
|
{
|
|
if (not error)
|
|
{
|
|
if (auto self = weak.lock())
|
|
{
|
|
self->connection_->close();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return {};
|
|
}
|