Commit 98cbc0ea authored by Max Kellermann's avatar Max Kellermann

event/TimeoutMonitor: eliminate support for periodic events

No caller needs this. Fixes use-after-free after returning from Client::OnTimeout().
parent dca11151
......@@ -30,7 +30,7 @@ Client::SetExpired()
TimeoutMonitor::Schedule(0);
}
bool
void
Client::OnTimeout()
{
if (!IsExpired()) {
......@@ -39,5 +39,4 @@ Client::OnTimeout()
}
Close();
return false;
}
......@@ -120,7 +120,7 @@ private:
virtual void OnSocketClosed() override;
/* virtual methods from class TimeoutMonitor */
virtual bool OnTimeout() override;
virtual void OnTimeout() override;
};
extern int client_timeout;
......
......@@ -38,7 +38,7 @@ enum {
INOTIFY_UPDATE_DELAY_S = 5,
};
bool
void
InotifyQueue::OnTimeout()
{
unsigned id;
......@@ -47,17 +47,16 @@ InotifyQueue::OnTimeout()
const char *uri_utf8 = queue.front().c_str();
id = update_enqueue(uri_utf8, false);
if (id == 0)
if (id == 0) {
/* retry later */
return true;
ScheduleSeconds(INOTIFY_UPDATE_DELAY_S);
return;
}
g_debug("updating '%s' job=%u", uri_utf8, id);
queue.pop_front();
}
/* done, remove the timer event by returning false */
return false;
}
static bool
......
......@@ -35,7 +35,7 @@ public:
void Enqueue(const char *uri_utf8);
private:
virtual bool OnTimeout() override;
virtual void OnTimeout() override;
};
#endif
......@@ -116,9 +116,8 @@ StateFile::CheckModified()
ScheduleSeconds(2 * 60);
}
bool
void
StateFile::OnTimeout()
{
Write();
return false;
}
......@@ -67,7 +67,7 @@ private:
bool IsModified() const;
/* virtual methods from TimeoutMonitor */
virtual bool OnTimeout() override;
virtual void OnTimeout() override;
};
#endif /* STATE_FILE_H */
......@@ -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);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment