aboutsummaryrefslogtreecommitdiffstats
path: root/src/event
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 11:21:38 +0200
committerMax Kellermann <max@duempel.org>2013-08-10 11:52:31 +0200
commit84ac79bb08696230157912a1d927d35004b12e8c (patch)
tree857369be445009e0368e4123d1aea8b03411b4d1 /src/event
parentbe0c8495cdb60847279ffbb6b6e1c1efed607e98 (diff)
downloadmpd-84ac79bb08696230157912a1d927d35004b12e8c.tar.gz
mpd-84ac79bb08696230157912a1d927d35004b12e8c.tar.xz
mpd-84ac79bb08696230157912a1d927d35004b12e8c.zip
event/MultiSocketMonitor: eliminate virtual method CheckSockets()
Handle timeout internally.
Diffstat (limited to 'src/event')
-rw-r--r--src/event/MultiSocketMonitor.cxx16
-rw-r--r--src/event/MultiSocketMonitor.hxx8
2 files changed, 16 insertions, 8 deletions
diff --git a/src/event/MultiSocketMonitor.cxx b/src/event/MultiSocketMonitor.cxx
index d8a9ffd6a..3fcc4375c 100644
--- a/src/event/MultiSocketMonitor.cxx
+++ b/src/event/MultiSocketMonitor.cxx
@@ -42,7 +42,8 @@ static GSourceFuncs multi_socket_monitor_source_funcs = {
MultiSocketMonitor::MultiSocketMonitor(EventLoop &_loop)
:loop(_loop),
source((Source *)g_source_new(&multi_socket_monitor_source_funcs,
- sizeof(*source))) {
+ sizeof(*source))),
+ absolute_timeout_us(G_MAXINT64) {
source->monitor = this;
g_source_attach(&source->base, loop.GetContext());
@@ -56,9 +57,20 @@ MultiSocketMonitor::~MultiSocketMonitor()
}
bool
+MultiSocketMonitor::Prepare(gint *timeout_r)
+{
+ int timeout_ms = *timeout_r = PrepareSockets();
+ absolute_timeout_us = timeout_ms < 0
+ ? G_MAXINT64
+ : GetTime() + gint64(timeout_ms) * 1000;
+
+ return false;
+}
+
+bool
MultiSocketMonitor::Check() const
{
- if (CheckSockets())
+ if (GetTime() >= absolute_timeout_us)
return true;
for (const auto &i : fds)
diff --git a/src/event/MultiSocketMonitor.hxx b/src/event/MultiSocketMonitor.hxx
index 50be18070..941487534 100644
--- a/src/event/MultiSocketMonitor.hxx
+++ b/src/event/MultiSocketMonitor.hxx
@@ -52,6 +52,7 @@ class MultiSocketMonitor {
EventLoop &loop;
Source *source;
+ gint64 absolute_timeout_us;
std::forward_list<GPollFD> fds;
public:
@@ -105,7 +106,6 @@ protected:
* @return timeout [ms] or -1 for no timeout
*/
virtual int PrepareSockets() = 0;
- virtual bool CheckSockets() const { return false; }
virtual void DispatchSockets() = 0;
public:
@@ -116,11 +116,7 @@ public:
gpointer user_data);
private:
- bool Prepare(gint *timeout_r) {
- *timeout_r = PrepareSockets();
- return false;
- }
-
+ bool Prepare(gint *timeout_r);
bool Check() const;
void Dispatch() {