Make the select based configuration compile on Windows.

This commit is contained in:
Sönke Ludwig 2017-01-21 16:19:34 +01:00
parent a1f0cafeb3
commit 64f6bb2a14
2 changed files with 73 additions and 6 deletions

View file

@ -11,7 +11,7 @@ Supported drivers and operating systems
Driver | Linux | Windows | OS X | FreeBSD Driver | Linux | Windows | OS X | FreeBSD
------------------|-------|---------|------|-------- ------------------|-------|---------|------|--------
SelectEventDriver | yes | yes¹ | yes¹ | yes¹ SelectEventDriver | yes | yes | yes¹ | yes¹
EpollEventDriver | yes | no | no | no EpollEventDriver | yes | no | no | no
WinAPIEventDriver | no | yes¹ | no | no WinAPIEventDriver | no | yes¹ | no | no
KqueueEventDriver | no | no | yes¹ | yes¹ KqueueEventDriver | no | no | yes¹ | yes¹

View file

@ -24,6 +24,7 @@ version (Posix) {
import core.sys.posix.fcntl; import core.sys.posix.fcntl;
} }
version (Windows) { version (Windows) {
import core.sys.windows.windows;
import core.sys.windows.winsock2; import core.sys.windows.winsock2;
alias sockaddr_storage = SOCKADDR_STORAGE; alias sockaddr_storage = SOCKADDR_STORAGE;
alias EAGAIN = WSAEWOULDBLOCK; alias EAGAIN = WSAEWOULDBLOCK;
@ -58,8 +59,9 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver {
else alias SignalsDriver = DummyEventDriverSignals!Loop; else alias SignalsDriver = DummyEventDriverSignals!Loop;
alias TimerDriver = LoopTimeoutTimerDriver; alias TimerDriver = LoopTimeoutTimerDriver;
alias SocketsDriver = PosixEventDriverSockets!Loop; alias SocketsDriver = PosixEventDriverSockets!Loop;
/*version (linux) alias DNSDriver = EventDriverDNS_GAIA!(EventsDriver, SignalsDriver); version (Windows) alias DNSDriver = EventDriverDNS_GHBN!(EventsDriver, SignalsDriver);
else*/ alias DNSDriver = EventDriverDNS_GAI!(EventsDriver, SignalsDriver); //version (linux) alias DNSDriver = EventDriverDNS_GAIA!(EventsDriver, SignalsDriver);
else alias DNSDriver = EventDriverDNS_GAI!(EventsDriver, SignalsDriver);
alias FileDriver = ThreadedFileEventDriver!EventsDriver; alias FileDriver = ThreadedFileEventDriver!EventsDriver;
version (linux) alias WatcherDriver = InotifyEventDriverWatchers!Loop; version (linux) alias WatcherDriver = InotifyEventDriverWatchers!Loop;
else alias WatcherDriver = PosixEventDriverWatchers!Loop; else alias WatcherDriver = PosixEventDriverWatchers!Loop;
@ -830,7 +832,8 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
} }
/// getaddrinfo_a based asynchronous lookups /// getaddrinfo+thread based lookup - does not support true cancellation
version (Posix)
final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS { final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS {
import std.parallelism : task, taskPool; import std.parallelism : task, taskPool;
import std.string : toStringz; import std.string : toStringz;
@ -930,7 +933,7 @@ final class EventDriverDNS_GAI(Events : EventDriverEvents, Signals : EventDriver
} }
/// getaddrinfo+thread based lookup - does not support true cancellation /// getaddrinfo_a based asynchronous lookups
final class EventDriverDNS_GAIA(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS { final class EventDriverDNS_GAIA(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS {
import core.sys.posix.signal : SIGEV_SIGNAL, SIGRTMIN, sigevent; import core.sys.posix.signal : SIGEV_SIGNAL, SIGRTMIN, sigevent;
@ -1035,7 +1038,71 @@ version (linux) extern(C) {
int gai_cancel(gaicb *req); int gai_cancel(gaicb *req);
} }
private void passToDNSCallback(DNSLookupID id, scope DNSLookupCallback cb, DNSStatus status, addrinfo* ai_orig)
/// ghbn based lookup - does not support cancellation and blocks the thread!
final class EventDriverDNS_GHBN(Events : EventDriverEvents, Signals : EventDriverSignals) : EventDriverDNS {
import std.parallelism : task, taskPool;
import std.string : toStringz;
private {
static struct Lookup {
DNSLookupCallback callback;
bool success;
int retcode;
string name;
}
size_t m_maxHandle;
}
this(Events events, Signals signals)
{
}
void dispose()
{
}
override DNSLookupID lookupHost(string name, DNSLookupCallback on_lookup_finished)
{
import std.string : toStringz;
auto handle = DNSLookupID(m_maxHandle++);
auto he = () @trusted { return gethostbyname(name.toStringz); } ();
if (he is null) {
on_lookup_finished(handle, DNSStatus.error, null);
return handle;
}
switch (he.h_addrtype) {
default: assert(false, "Invalid address family returned from host lookup.");
case AF_INET: {
sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_addr = () @trusted { return *cast(in_addr*)he.h_addr_list[0]; } ();
scope addr = new RefAddress(() @trusted { return cast(sockaddr*)&sa; } (), sa.sizeof);
RefAddress[1] aa;
aa[0] = addr;
on_lookup_finished(handle, DNSStatus.ok, aa);
} break;
case AF_INET6: {
sockaddr_in6 sa;
sa.sin6_family = AF_INET6;
sa.sin6_addr = () @trusted { return *cast(in6_addr*)he.h_addr_list[0]; } ();
scope addr = new RefAddress(() @trusted { return cast(sockaddr*)&sa; } (), sa.sizeof);
RefAddress[1] aa;
aa[0] = addr;
on_lookup_finished(handle, DNSStatus.ok, aa);
} break;
}
return handle;
}
override void cancelLookup(DNSLookupID) {}
}
private void passToDNSCallback()(DNSLookupID id, scope DNSLookupCallback cb, DNSStatus status, addrinfo* ai_orig)
@trusted nothrow @trusted nothrow
{ {
import std.typecons : scoped; import std.typecons : scoped;