summaryrefslogtreecommitdiff
path: root/src/event
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-09 20:42:33 +0100
committerMax Kellermann <max@musicpd.org>2017-02-09 21:12:23 +0100
commiteda06993f8cba429e247cac5e75b1e5938fb3a3e (patch)
tree1135b98d9fc63eeec4efdf38b602ce47421edb83 /src/event
parent4b30ef1cf216df3d5395033c2ad7cfaff4aeaa51 (diff)
event/MultiSocketMonitor: add method Reset()
Diffstat (limited to 'src/event')
-rw-r--r--src/event/MultiSocketMonitor.cxx10
-rw-r--r--src/event/MultiSocketMonitor.hxx19
2 files changed, 25 insertions, 4 deletions
diff --git a/src/event/MultiSocketMonitor.cxx b/src/event/MultiSocketMonitor.cxx
index 9a28dd71d..02a51e96f 100644
--- a/src/event/MultiSocketMonitor.cxx
+++ b/src/event/MultiSocketMonitor.cxx
@@ -31,9 +31,15 @@ MultiSocketMonitor::MultiSocketMonitor(EventLoop &_loop)
:IdleMonitor(_loop), TimeoutMonitor(_loop) {
}
-MultiSocketMonitor::~MultiSocketMonitor()
+void
+MultiSocketMonitor::Reset()
{
- // TODO
+ assert(GetEventLoop().IsInsideOrNull());
+
+ fds.clear();
+ IdleMonitor::Cancel();
+ TimeoutMonitor::Cancel();
+ ready = refresh = false;
}
void
diff --git a/src/event/MultiSocketMonitor.hxx b/src/event/MultiSocketMonitor.hxx
index d6c400b9e..db6bec3cb 100644
--- a/src/event/MultiSocketMonitor.hxx
+++ b/src/event/MultiSocketMonitor.hxx
@@ -119,11 +119,26 @@ public:
static constexpr unsigned HANGUP = SocketMonitor::HANGUP;
MultiSocketMonitor(EventLoop &_loop);
- ~MultiSocketMonitor();
using IdleMonitor::GetEventLoop;
-public:
+ /**
+ * Clear the socket list and disable all #EventLoop
+ * registrations. Run this in the #EventLoop thread before
+ * destroying this object.
+ *
+ * Later, this object can be reused and reactivated by calling
+ * InvalidateSockets().
+ *
+ * Note that this class doesn't have a destructor which calls
+ * this method, because this would be racy and thus pointless:
+ * at the time ~MultiSocketMonitor() is called, our virtual
+ * methods have been morphed to be pure again, and in the
+ * meantime the #EventLoop thread could invoke those pure
+ * methods.
+ */
+ void Reset();
+
/**
* Invalidate the socket list. A call to PrepareSockets() is
* scheduled which will then update the list.