event/TimeoutMonitor: eliminate support for periodic events
No caller needs this. Fixes use-after-free after returning from Client::OnTimeout().
This commit is contained in:
@@ -45,21 +45,17 @@ TimeoutMonitor::ScheduleSeconds(unsigned s)
|
||||
source = loop.AddTimeoutSeconds(s, Callback, this);
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
TimeoutMonitor::Run()
|
||||
{
|
||||
bool result = OnTimeout();
|
||||
if (!result && source != nullptr) {
|
||||
g_source_unref(source);
|
||||
source = nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
Cancel();
|
||||
OnTimeout();
|
||||
}
|
||||
|
||||
gboolean
|
||||
TimeoutMonitor::Callback(gpointer data)
|
||||
{
|
||||
TimeoutMonitor &monitor = *(TimeoutMonitor *)data;
|
||||
return monitor.Run();
|
||||
monitor.Run();
|
||||
return false;
|
||||
}
|
||||
|
@@ -47,13 +47,10 @@ public:
|
||||
void Cancel();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @return true reschedules the timeout again
|
||||
*/
|
||||
virtual bool OnTimeout() = 0;
|
||||
virtual void OnTimeout() = 0;
|
||||
|
||||
private:
|
||||
bool Run();
|
||||
void Run();
|
||||
static gboolean Callback(gpointer data);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user