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:
Max Kellermann 2013-04-08 23:14:07 +02:00
parent dca1115196
commit 98cbc0ea79
8 changed files with 17 additions and 27 deletions

View File

@ -30,7 +30,7 @@ Client::SetExpired()
TimeoutMonitor::Schedule(0); TimeoutMonitor::Schedule(0);
} }
bool void
Client::OnTimeout() Client::OnTimeout()
{ {
if (!IsExpired()) { if (!IsExpired()) {
@ -39,5 +39,4 @@ Client::OnTimeout()
} }
Close(); Close();
return false;
} }

View File

@ -120,7 +120,7 @@ private:
virtual void OnSocketClosed() override; virtual void OnSocketClosed() override;
/* virtual methods from class TimeoutMonitor */ /* virtual methods from class TimeoutMonitor */
virtual bool OnTimeout() override; virtual void OnTimeout() override;
}; };
extern int client_timeout; extern int client_timeout;

View File

@ -38,7 +38,7 @@ enum {
INOTIFY_UPDATE_DELAY_S = 5, INOTIFY_UPDATE_DELAY_S = 5,
}; };
bool void
InotifyQueue::OnTimeout() InotifyQueue::OnTimeout()
{ {
unsigned id; unsigned id;
@ -47,17 +47,16 @@ InotifyQueue::OnTimeout()
const char *uri_utf8 = queue.front().c_str(); const char *uri_utf8 = queue.front().c_str();
id = update_enqueue(uri_utf8, false); id = update_enqueue(uri_utf8, false);
if (id == 0) if (id == 0) {
/* retry later */ /* retry later */
return true; ScheduleSeconds(INOTIFY_UPDATE_DELAY_S);
return;
}
g_debug("updating '%s' job=%u", uri_utf8, id); g_debug("updating '%s' job=%u", uri_utf8, id);
queue.pop_front(); queue.pop_front();
} }
/* done, remove the timer event by returning false */
return false;
} }
static bool static bool

View File

@ -35,7 +35,7 @@ public:
void Enqueue(const char *uri_utf8); void Enqueue(const char *uri_utf8);
private: private:
virtual bool OnTimeout() override; virtual void OnTimeout() override;
}; };
#endif #endif

View File

@ -116,9 +116,8 @@ StateFile::CheckModified()
ScheduleSeconds(2 * 60); ScheduleSeconds(2 * 60);
} }
bool void
StateFile::OnTimeout() StateFile::OnTimeout()
{ {
Write(); Write();
return false;
} }

View File

@ -67,7 +67,7 @@ private:
bool IsModified() const; bool IsModified() const;
/* virtual methods from TimeoutMonitor */ /* virtual methods from TimeoutMonitor */
virtual bool OnTimeout() override; virtual void OnTimeout() override;
}; };
#endif /* STATE_FILE_H */ #endif /* STATE_FILE_H */

View File

@ -45,21 +45,17 @@ TimeoutMonitor::ScheduleSeconds(unsigned s)
source = loop.AddTimeoutSeconds(s, Callback, this); source = loop.AddTimeoutSeconds(s, Callback, this);
} }
bool void
TimeoutMonitor::Run() TimeoutMonitor::Run()
{ {
bool result = OnTimeout(); Cancel();
if (!result && source != nullptr) { OnTimeout();
g_source_unref(source);
source = nullptr;
}
return result;
} }
gboolean gboolean
TimeoutMonitor::Callback(gpointer data) TimeoutMonitor::Callback(gpointer data)
{ {
TimeoutMonitor &monitor = *(TimeoutMonitor *)data; TimeoutMonitor &monitor = *(TimeoutMonitor *)data;
return monitor.Run(); monitor.Run();
return false;
} }

View File

@ -47,13 +47,10 @@ public:
void Cancel(); void Cancel();
protected: protected:
/** virtual void OnTimeout() = 0;
* @return true reschedules the timeout again
*/
virtual bool OnTimeout() = 0;
private: private:
bool Run(); void Run();
static gboolean Callback(gpointer data); static gboolean Callback(gpointer data);
}; };