Add DNS API and update Libasync stub.

This commit is contained in:
Sönke Ludwig 2016-10-14 22:24:31 +02:00
parent c6dec730d8
commit 2518a6c301
3 changed files with 90 additions and 5 deletions

View file

@ -12,6 +12,7 @@ interface EventDriver {
@property EventDriverEvents events(); @property EventDriverEvents events();
@property EventDriverSignals signals(); @property EventDriverSignals signals();
@property EventDriverSockets sockets(); @property EventDriverSockets sockets();
@property EventDriverDNS dns();
@property EventDriverFiles files(); @property EventDriverFiles files();
@property EventDriverWatchers watchers(); @property EventDriverWatchers watchers();
@ -106,6 +107,12 @@ interface EventDriverSockets {
void releaseRef(SocketFD descriptor); void releaseRef(SocketFD descriptor);
} }
interface EventDriverDNS {
@safe: /*@nogc:*/ nothrow:
DNSLookupID lookupHost(string name, DNSLookupCallback on_lookup_finished);
void cancelLookup(DNSLookupID handle);
}
interface EventDriverFiles { interface EventDriverFiles {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
FileFD open(string path, FileOpenMode mode); FileFD open(string path, FileOpenMode mode);
@ -202,6 +209,7 @@ alias ConnectCallback = void delegate(StreamSocketFD, ConnectStatus);
alias AcceptCallback = void delegate(StreamListenSocketFD, StreamSocketFD); alias AcceptCallback = void delegate(StreamListenSocketFD, StreamSocketFD);
alias IOCallback = void delegate(StreamSocketFD, IOStatus, size_t); alias IOCallback = void delegate(StreamSocketFD, IOStatus, size_t);
alias DatagramIOCallback = void delegate(DatagramSocketFD, IOStatus, size_t, scope Address); alias DatagramIOCallback = void delegate(DatagramSocketFD, IOStatus, size_t, scope Address);
alias DNSLookupCallback = void delegate(DNSLookupID, scope Address[] results);
alias FileIOCallback = void delegate(FileFD, IOStatus, size_t); alias FileIOCallback = void delegate(FileFD, IOStatus, size_t);
alias EventCallback = void delegate(EventID); alias EventCallback = void delegate(EventID);
alias SignalCallback = void delegate(int); alias SignalCallback = void delegate(int);
@ -315,3 +323,4 @@ alias EventID = Handle!("Event", FD);
alias TimerID = Handle!("Timer", int); alias TimerID = Handle!("Timer", int);
alias WatcherID = Handle!("Watcher", int); alias WatcherID = Handle!("Watcher", int);
alias EventWaitID = Handle!("EventWait", int); alias EventWaitID = Handle!("EventWait", int);
alias DNSLookupID = Handle!("DNS", int);

View file

@ -14,6 +14,7 @@ final class LibasyncEventDriver : EventDriver {
LibasyncEventDriverCore m_core; LibasyncEventDriverCore m_core;
LibasyncEventDriverFiles m_files; LibasyncEventDriverFiles m_files;
LibasyncEventDriverSockets m_sockets; LibasyncEventDriverSockets m_sockets;
LibasyncEventDriverDNS m_dns;
LibasyncEventDriverTimers m_timers; LibasyncEventDriverTimers m_timers;
LibasyncEventDriverEvents m_events; LibasyncEventDriverEvents m_events;
LibasyncEventDriverSignals m_signals; LibasyncEventDriverSignals m_signals;
@ -25,6 +26,7 @@ final class LibasyncEventDriver : EventDriver {
m_core = new LibasyncEventDriverCore(); m_core = new LibasyncEventDriverCore();
m_files = new LibasyncEventDriverFiles(); m_files = new LibasyncEventDriverFiles();
m_sockets = new LibasyncEventDriverSockets(); m_sockets = new LibasyncEventDriverSockets();
m_dns = new LibasyncEventDriverDNS();
m_timers = new LibasyncEventDriverTimers(); m_timers = new LibasyncEventDriverTimers();
m_events = new LibasyncEventDriverEvents(); m_events = new LibasyncEventDriverEvents();
m_signals = new LibasyncEventDriverSignals(); m_signals = new LibasyncEventDriverSignals();
@ -34,19 +36,20 @@ final class LibasyncEventDriver : EventDriver {
override @property LibasyncEventDriverCore core() { return m_core; } override @property LibasyncEventDriverCore core() { return m_core; }
override @property LibasyncEventDriverFiles files() { return m_files; } override @property LibasyncEventDriverFiles files() { return m_files; }
override @property LibasyncEventDriverSockets sockets() { return m_sockets; } override @property LibasyncEventDriverSockets sockets() { return m_sockets; }
override @property LibasyncEventDriverDNS dns() { return m_dns; }
override @property LibasyncEventDriverTimers timers() { return m_timers; } override @property LibasyncEventDriverTimers timers() { return m_timers; }
override @property LibasyncEventDriverEvents events() { return m_events; } override @property LibasyncEventDriverEvents events() { return m_events; }
override @property LibasyncEventDriverSignals signals() { return m_signals; } override @property LibasyncEventDriverSignals signals() { return m_signals; }
override @property LibasyncEventDriverWatchers watchers() { return m_watchers; } override @property LibasyncEventDriverWatchers watchers() { return m_watchers; }
}
final class LibasyncEventDriverCore : EventDriverCore {
@safe: /*@nogc:*/ nothrow:
override void dispose() override void dispose()
{ {
assert(false, "TODO!"); assert(false, "TODO!");
} }
}
final class LibasyncEventDriverCore : EventDriverCore {
@safe: /*@nogc:*/ nothrow:
override size_t waiterCount() override size_t waiterCount()
{ {
assert(false, "TODO!"); assert(false, "TODO!");
@ -130,6 +133,31 @@ final class LibasyncEventDriverSockets : EventDriverSockets {
assert(false, "TODO!"); assert(false, "TODO!");
} }
override DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address)
{
assert(false, "TODO!");
}
override void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish)
{
assert(false, "TODO!");
}
override void cancelReceive(DatagramSocketFD socket)
{
assert(false, "TODO!");
}
override void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, DatagramIOCallback on_send_finish, Address target_address = null)
{
assert(false, "TODO!");
}
override void cancelSend(DatagramSocketFD socket)
{
assert(false, "TODO!");
}
override void addRef(SocketFD descriptor) override void addRef(SocketFD descriptor)
{ {
assert(false, "TODO!"); assert(false, "TODO!");
@ -141,6 +169,21 @@ final class LibasyncEventDriverSockets : EventDriverSockets {
} }
} }
final class LibasyncEventDriverDNS : EventDriverDNS {
@safe: /*@nogc:*/ nothrow:
DNSLookupID lookupHost(string name, DNSLookupCallback on_lookup_finished)
{
assert(false, "TODO!");
}
void cancelLookup(DNSLookupID handle)
{
assert(false, "TODO!");
}
}
final class LibasyncEventDriverFiles : EventDriverFiles { final class LibasyncEventDriverFiles : EventDriverFiles {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
override FileFD open(string path, FileOpenMode mode) override FileFD open(string path, FileOpenMode mode)
@ -153,12 +196,22 @@ final class LibasyncEventDriverFiles : EventDriverFiles {
assert(false, "TODO!"); assert(false, "TODO!");
} }
override void write(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_write_finish) override void close(FileFD file)
{ {
assert(false, "TODO!"); assert(false, "TODO!");
} }
override void read(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_read_finish) override ulong getSize(FileFD file)
{
assert(false, "TODO!");
}
override void write(FileFD file, ulong offset, const(ubyte)[] buffer, FileIOCallback on_write_finish)
{
assert(false, "TODO!");
}
override void read(FileFD file, ulong offset, ubyte[] buffer, FileIOCallback on_read_finish)
{ {
assert(false, "TODO!"); assert(false, "TODO!");
} }

View file

@ -46,6 +46,7 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver {
alias SignalsDriver = PosixEventDriverSignals!Loop; alias SignalsDriver = PosixEventDriverSignals!Loop;
alias TimerDriver = LoopTimeoutTimerDriver; alias TimerDriver = LoopTimeoutTimerDriver;
alias SocketsDriver = PosixEventDriverSockets!Loop; alias SocketsDriver = PosixEventDriverSockets!Loop;
alias DNSDriver = EventDriverDNS_GAI!(EventsDriver, SignalsDriver);
alias FileDriver = ThreadedFileEventDriver!EventsDriver; alias FileDriver = ThreadedFileEventDriver!EventsDriver;
alias WatcherDriver = PosixEventDriverWatchers!Loop; alias WatcherDriver = PosixEventDriverWatchers!Loop;
@ -55,6 +56,7 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver {
SignalsDriver m_signals; SignalsDriver m_signals;
LoopTimeoutTimerDriver m_timers; LoopTimeoutTimerDriver m_timers;
SocketsDriver m_sockets; SocketsDriver m_sockets;
DNSDriver m_dns;
FileDriver m_files; FileDriver m_files;
WatcherDriver m_watchers; WatcherDriver m_watchers;
} }
@ -67,6 +69,7 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver {
m_timers = new TimerDriver; m_timers = new TimerDriver;
m_core = new CoreDriver(m_loop, m_timers); m_core = new CoreDriver(m_loop, m_timers);
m_sockets = new SocketsDriver(m_loop); m_sockets = new SocketsDriver(m_loop);
m_dns = new DNSDriver(m_events, m_signals);
m_files = new FileDriver(m_events); m_files = new FileDriver(m_events);
m_watchers = new WatcherDriver(m_loop); m_watchers = new WatcherDriver(m_loop);
} }
@ -77,6 +80,7 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver {
final override @property SignalsDriver signals() { return m_signals; } final override @property SignalsDriver signals() { return m_signals; }
final override @property TimerDriver timers() { return m_timers; } final override @property TimerDriver timers() { return m_timers; }
final override @property SocketsDriver sockets() { return m_sockets; } final override @property SocketsDriver sockets() { return m_sockets; }
final override @property DNSDriver dns() { return m_dns; }
final override @property FileDriver files() { return m_files; } final override @property FileDriver files() { return m_files; }
final override @property WatcherDriver watchers() { return m_watchers; } final override @property WatcherDriver watchers() { return m_watchers; }
@ -747,6 +751,25 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
} }
/// getaddrinfo_a based asynchronous lookups
final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS {
this(Events events, Signals signals)
{
}
override DNSLookupID lookupHost(string name, DNSLookupCallback on_lookup_finished)
{
assert(false, "TODO!");
}
override void cancelLookup(DNSLookupID handle)
{
assert(false, "TODO!");
}
}
final class PosixEventDriverEvents(Loop : PosixEventLoop) : EventDriverEvents { final class PosixEventDriverEvents(Loop : PosixEventLoop) : EventDriverEvents {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
private Loop m_loop; private Loop m_loop;