From 406367b6c62ee53d98f82d1db751b2deee22b8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 24 Oct 2018 12:08:38 +0200 Subject: [PATCH] Fix epoll compile error on older frontends. --- source/eventcore/drivers/posix/epoll.d | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/source/eventcore/drivers/posix/epoll.d b/source/eventcore/drivers/posix/epoll.d index e33f7d2..6a700b0 100644 --- a/source/eventcore/drivers/posix/epoll.d +++ b/source/eventcore/drivers/posix/epoll.d @@ -31,7 +31,9 @@ final class EpollEventLoop : PosixEventLoop { this() @nogc { - m_epoll = () @trusted { return epoll_create1(SOCK_CLOEXEC); } (); + assumeSafeNoGC({ + m_epoll = epoll_create1(SOCK_CLOEXEC); + }); } override bool doProcessEvents(Duration timeout) @@ -73,13 +75,17 @@ final class EpollEventLoop : PosixEventLoop { if (mask & EventMask.write) ev.events |= EPOLLOUT; if (mask & EventMask.status) ev.events |= EPOLLERR|EPOLLHUP|EPOLLRDHUP; ev.data.fd = cast(int)fd; - () @trusted { epoll_ctl(m_epoll, EPOLL_CTL_ADD, cast(int)fd, &ev); } (); + assumeSafeNoGC({ + epoll_ctl(m_epoll, EPOLL_CTL_ADD, cast(int)fd, &ev); + }); } override void unregisterFD(FD fd, EventMask mask) { debug (EventCoreEpollDebug) print("Epoll unregister FD %s", fd); - () @trusted { epoll_ctl(m_epoll, EPOLL_CTL_DEL, cast(int)fd, null); } (); + assumeSafeNoGC({ + epoll_ctl(m_epoll, EPOLL_CTL_DEL, cast(int)fd, null); + }); } override void updateFD(FD fd, EventMask old_mask, EventMask mask, bool edge_triggered = true) @@ -92,7 +98,9 @@ final class EpollEventLoop : PosixEventLoop { if (mask & EventMask.write) ev.events |= EPOLLOUT; if (mask & EventMask.status) ev.events |= EPOLLERR|EPOLLHUP|EPOLLRDHUP; ev.data.fd = cast(int)fd; - () @trusted { epoll_ctl(m_epoll, EPOLL_CTL_MOD, cast(int)fd, &ev); } (); + assumeSafeNoGC({ + epoll_ctl(m_epoll, EPOLL_CTL_MOD, cast(int)fd, &ev); + }); } } @@ -102,3 +110,8 @@ private timeval toTimeVal(Duration dur) dur.split!("seconds", "usecs")(tvdur.tv_sec, tvdur.tv_usec); return tvdur; } + +private void assumeSafeNoGC(scope void delegate() nothrow doit) +@trusted { + (cast(void delegate() nothrow @nogc)doit)(); +}