aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/MultiSocketMonitor.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-05 01:28:36 +0100
committerMax Kellermann <max@duempel.org>2014-01-05 01:28:36 +0100
commit7b540f022699e6e2b2e115d13526e12060a5fc9f (patch)
tree0fca20b0dc652f8dc5eacb56868c31115d3700ef /src/event/MultiSocketMonitor.cxx
parente29c22e662d31fb55b0aa4cd071281fca42fabb0 (diff)
downloadmpd-7b540f022699e6e2b2e115d13526e12060a5fc9f.tar.gz
mpd-7b540f022699e6e2b2e115d13526e12060a5fc9f.tar.xz
mpd-7b540f022699e6e2b2e115d13526e12060a5fc9f.zip
event/MultiSocketMonitor: add method ReplaceSocketList()
Move code from AlsaMixerPlugin.
Diffstat (limited to 'src/event/MultiSocketMonitor.cxx')
-rw-r--r--src/event/MultiSocketMonitor.cxx30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/event/MultiSocketMonitor.cxx b/src/event/MultiSocketMonitor.cxx
index 39b6f3e0d..b5114cfb3 100644
--- a/src/event/MultiSocketMonitor.cxx
+++ b/src/event/MultiSocketMonitor.cxx
@@ -20,6 +20,10 @@
#include "config.h"
#include "MultiSocketMonitor.hxx"
+#ifndef WIN32
+#include <poll.h>
+#endif
+
MultiSocketMonitor::MultiSocketMonitor(EventLoop &_loop)
:IdleMonitor(_loop), TimeoutMonitor(_loop), ready(false) {
}
@@ -29,6 +33,32 @@ MultiSocketMonitor::~MultiSocketMonitor()
// TODO
}
+#ifndef WIN32
+
+void
+MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n)
+{
+ pollfd *const end = pfds + n;
+
+ UpdateSocketList([pfds, end](int fd) -> unsigned {
+ auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){
+ return pfd.fd == fd;
+ });
+ if (i == end)
+ return 0;
+
+ auto events = i->events;
+ i->events = 0;
+ return events;
+ });
+
+ for (auto i = pfds; i != end; ++i)
+ if (i->events != 0)
+ AddSocket(i->fd, i->events);
+}
+
+#endif
+
void
MultiSocketMonitor::Prepare()
{