diff options
author | Max Kellermann <max@duempel.org> | 2013-08-07 22:16:59 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-10 13:54:23 +0200 |
commit | c1f4f1fdb64d97b5c3461723a8482ca64efea30e (patch) | |
tree | 54c8a9c1466beec0dbfac1c0b5f5773060c1aa2b /src/event/SocketMonitor.cxx | |
parent | 342333f72a484e9f394026666c4b20e54dc9b756 (diff) | |
download | mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.gz mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.xz mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.zip |
EventLoop: new implementation using epoll
Implement an event loop without GLib.
Diffstat (limited to 'src/event/SocketMonitor.cxx')
-rw-r--r-- | src/event/SocketMonitor.cxx | 33 |
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 |