From 95ccc347d587610e1ba7545ce4c01eedf241febc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 5 Oct 2016 14:38:29 +0200 Subject: [PATCH] Add stub libasync support. --- dub.sdl | 9 + source/eventcore/core.d | 4 +- source/eventcore/drivers/libasync.d | 312 ++++++++++++++++++++++++++++ 3 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 source/eventcore/drivers/libasync.d diff --git a/dub.sdl b/dub.sdl index 0da712d..d7cbd9e 100644 --- a/dub.sdl +++ b/dub.sdl @@ -2,3 +2,12 @@ name "eventcore" description "Experimental callback based abstraction layer over operating system asynchronous I/O facilities." license "MIT" copyright "Copyright © 2012-2016 rejectedsoftware e.K." + +targetType "library" + +configuration "native" { +} + +configuration "libasync" { + dependency "libasync" version="~>0.7.9" +} diff --git a/source/eventcore/core.d b/source/eventcore/core.d index 14bde46..5f003d8 100644 --- a/source/eventcore/core.d +++ b/source/eventcore/core.d @@ -3,9 +3,11 @@ module eventcore.core; public import eventcore.driver; import eventcore.drivers.epoll; +import eventcore.drivers.libasync; import eventcore.drivers.select; -alias NativeEventDriver = SelectEventDriver; +version (Have_libasync) alias NativeEventDriver = LibasyncEventDriver; +else alias NativeEventDriver = SelectEventDriver; @property EventDriver eventDriver() @safe @nogc nothrow { diff --git a/source/eventcore/drivers/libasync.d b/source/eventcore/drivers/libasync.d new file mode 100644 index 0000000..c2fb831 --- /dev/null +++ b/source/eventcore/drivers/libasync.d @@ -0,0 +1,312 @@ +module eventcore.drivers.libasync; + +version (Have_libasync): + +import eventcore.driver; +import std.socket : Address; +import core.time : Duration; + + +final class LibasyncEventDriver : EventDriver { +@safe: /*@nogc:*/ nothrow: + + private { + LibasyncEventDriverCore m_core; + LibasyncEventDriverFiles m_files; + LibasyncEventDriverSockets m_sockets; + LibasyncEventDriverTimers m_timers; + LibasyncEventDriverEvents m_events; + LibasyncEventDriverSignals m_signals; + LibasyncEventDriverWatchers m_watchers; + } + + this() + { + m_core = new LibasyncEventDriverCore(); + m_files = new LibasyncEventDriverFiles(); + m_sockets = new LibasyncEventDriverSockets(); + m_timers = new LibasyncEventDriverTimers(); + m_events = new LibasyncEventDriverEvents(); + m_signals = new LibasyncEventDriverSignals(); + m_watchers = new LibasyncEventDriverWatchers(); + } + + override @property LibasyncEventDriverCore core() { return m_core; } + override @property LibasyncEventDriverFiles files() { return m_files; } + override @property LibasyncEventDriverSockets sockets() { return m_sockets; } + override @property LibasyncEventDriverTimers timers() { return m_timers; } + override @property LibasyncEventDriverEvents events() { return m_events; } + override @property LibasyncEventDriverSignals signals() { return m_signals; } + override @property LibasyncEventDriverWatchers watchers() { return m_watchers; } +} + +final class LibasyncEventDriverCore : EventDriverCore { +@safe: /*@nogc:*/ nothrow: + override void dispose() + { + assert(false, "TODO!"); + } + + override size_t waiterCount() + { + assert(false, "TODO!"); + } + + override ExitReason processEvents(Duration timeout = Duration.max) + { + assert(false, "TODO!"); + } + + override void exit() + { + assert(false, "TODO!"); + } + + override void clearExitFlag() + { + assert(false, "TODO!"); + } + + protected override void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverSockets : EventDriverSockets { +@safe: /*@nogc:*/ nothrow: + override StreamSocketFD connectStream(scope Address peer_address, ConnectCallback on_connect) + { + assert(false, "TODO!"); + } + + override StreamListenSocketFD listenStream(scope Address bind_address, AcceptCallback on_accept) + { + assert(false, "TODO!"); + } + + override void waitForConnections(StreamListenSocketFD sock, AcceptCallback on_accept) + { + assert(false, "TODO!"); + } + + override ConnectionState getConnectionState(StreamSocketFD sock) + { + assert(false, "TODO!"); + } + + override void setTCPNoDelay(StreamSocketFD socket, bool enable) + { + assert(false, "TODO!"); + } + + override void read(StreamSocketFD socket, ubyte[] buffer, IOMode mode, IOCallback on_read_finish) + { + assert(false, "TODO!"); + } + + override void write(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, IOCallback on_write_finish) + { + assert(false, "TODO!"); + } + + override void waitForData(StreamSocketFD socket, IOCallback on_data_available) + { + assert(false, "TODO!"); + } + + override void shutdown(StreamSocketFD socket, bool shut_read = true, bool shut_write = true) + { + assert(false, "TODO!"); + } + + override void cancelRead(StreamSocketFD socket) + { + assert(false, "TODO!"); + } + + override void cancelWrite(StreamSocketFD socket) + { + assert(false, "TODO!"); + } + + override void addRef(SocketFD descriptor) + { + assert(false, "TODO!"); + } + + override void releaseRef(SocketFD descriptor) + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverFiles : EventDriverFiles { +@safe: /*@nogc:*/ nothrow: + override FileFD open(string path, FileOpenMode mode) + { + assert(false, "TODO!"); + } + + override FileFD createTemp() + { + assert(false, "TODO!"); + } + + override void write(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_write_finish) + { + assert(false, "TODO!"); + } + + override void read(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_read_finish) + { + assert(false, "TODO!"); + } + + override void cancelWrite(FileFD file) + { + assert(false, "TODO!"); + } + + override void cancelRead(FileFD file) + { + assert(false, "TODO!"); + } + + override void addRef(FileFD descriptor) + { + assert(false, "TODO!"); + } + + override void releaseRef(FileFD descriptor) + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverEvents : EventDriverEvents { +@safe: /*@nogc:*/ nothrow: + override EventID create() + { + assert(false, "TODO!"); + } + + override void trigger(EventID event, bool notify_all = true) + { + assert(false, "TODO!"); + } + + override void trigger(EventID event, bool notify_all = true) shared + { + assert(false, "TODO!"); + } + + override void wait(EventID event, EventCallback on_event) + { + assert(false, "TODO!"); + } + + override void cancelWait(EventID event, EventCallback on_event) + { + assert(false, "TODO!"); + } + + override void addRef(EventID descriptor) + { + assert(false, "TODO!"); + } + + override void releaseRef(EventID descriptor) + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverSignals : EventDriverSignals { +@safe: /*@nogc:*/ nothrow: + override void wait(int sig, SignalCallback on_signal) + { + assert(false, "TODO!"); + } + + override void cancelWait(int sig) + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverTimers : EventDriverTimers { +@safe: /*@nogc:*/ nothrow: + override TimerID create() + { + assert(false, "TODO!"); + } + + override void set(TimerID timer, Duration timeout, Duration repeat = Duration.zero) + { + assert(false, "TODO!"); + } + + override void stop(TimerID timer) + { + assert(false, "TODO!"); + } + + override bool isPending(TimerID timer) + { + assert(false, "TODO!"); + } + + override bool isPeriodic(TimerID timer) + { + assert(false, "TODO!"); + } + + override void wait(TimerID timer, TimerCallback callback) + { + assert(false, "TODO!"); + } + + override void cancelWait(TimerID timer, TimerCallback callback) + { + assert(false, "TODO!"); + } + + override void addRef(TimerID descriptor) + { + assert(false, "TODO!"); + } + + override void releaseRef(TimerID descriptor) + { + assert(false, "TODO!"); + } +} + +final class LibasyncEventDriverWatchers : EventDriverWatchers { +@safe: /*@nogc:*/ nothrow: + override WatcherID watchDirectory(string path, bool recursive) + { + assert(false, "TODO!"); + } + + override void wait(WatcherID watcher, FileChangesCallback callback) + { + assert(false, "TODO!"); + } + + override void cancelWait(WatcherID watcher) + { + assert(false, "TODO!"); + } + + override void addRef(WatcherID descriptor) + { + assert(false, "TODO!"); + } + + override void releaseRef(WatcherID descriptor) + { + assert(false, "TODO!"); + } +}