aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/SocketMonitor.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/event/SocketMonitor.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx
index 0b929dd72..76dab9346 100644
--- a/src/event/SocketMonitor.cxx
+++ b/src/event/SocketMonitor.cxx
@@ -32,6 +32,19 @@
#include <sys/socket.h>
#endif
+#ifdef USE_EPOLL
+
+void
+SocketMonitor::Dispatch(unsigned flags)
+{
+ flags &= GetScheduledFlags();
+
+ if (flags != 0 && !OnSocketReady(flags) && IsDefined())
+ Cancel();
+}
+
+#else
+
/*
* GSource methods
*
@@ -88,6 +101,8 @@ SocketMonitor::SocketMonitor(int _fd, EventLoop &_loop)
Open(_fd);
}
+#endif
+
SocketMonitor::~SocketMonitor()
{
if (IsDefined())
@@ -98,10 +113,14 @@ void
SocketMonitor::Open(int _fd)
{
assert(fd < 0);
+#ifndef USE_EPOLL
assert(source == nullptr);
+#endif
assert(_fd >= 0);
fd = _fd;
+
+#ifndef USE_EPOLL
poll = {fd, 0, 0};
source = (Source *)g_source_new(&socket_monitor_source_funcs,
@@ -110,6 +129,7 @@ SocketMonitor::Open(int _fd)
g_source_attach(&source->base, loop.GetContext());
g_source_add_poll(&source->base, &poll);
+#endif
}
int
@@ -122,9 +142,11 @@ SocketMonitor::Steal()
int result = fd;
fd = -1;
+#ifndef USE_EPOLL
g_source_destroy(&source->base);
g_source_unref(&source->base);
source = nullptr;
+#endif
return result;
}
@@ -143,10 +165,21 @@ SocketMonitor::Schedule(unsigned flags)
if (flags == GetScheduledFlags())
return;
+#ifdef USE_EPOLL
+ if (scheduled_flags == 0)
+ loop.AddFD(fd, flags, *this);
+ else if (flags == 0)
+ loop.RemoveFD(fd, *this);
+ else
+ loop.ModifyFD(fd, flags, *this);
+
+ scheduled_flags = flags;
+#else
poll.events = flags;
poll.revents &= flags;
loop.WakeUp();
+#endif
}
SocketMonitor::ssize_t