diff --git a/source/concurrency/io/package.d b/source/concurrency/io/package.d index ff8a644..d78a08a 100644 --- a/source/concurrency/io/package.d +++ b/source/concurrency/io/package.d @@ -7,7 +7,6 @@ import std.socket : socket_t; version (linux) alias IOContext = IOUringContext; -else static assert(false, "No IOContext for platform"); auto readAsync(socket_t fd, ubyte[] buffer, long offset = 0) @safe nothrow @nogc { return ReadAsyncSender(fd, buffer, offset); diff --git a/source/concurrency/io/socket.d b/source/concurrency/io/socket.d index 87d67b8..c9efff9 100644 --- a/source/concurrency/io/socket.d +++ b/source/concurrency/io/socket.d @@ -17,9 +17,14 @@ auto tcpSocket() @trusted { version(linux) { import core.sys.linux.sys.eventfd; enum SOCK_NONBLOCK = 0x800; + socket_t sock = cast(socket_t) socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); + } else version(Windows) { + socket_t sock = cast(socket_t) socket(AF_INET, SOCK_STREAM, 0); + uint nonblocking_long = 1; + if (ioctlsocket(sock, FIONBIO, &nonblocking_long) == SOCKET_ERROR) + throw new Exception("ioctlsocket failed"); } - socket_t sock = cast(socket_t) socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); if (sock == -1) throw new Exception("socket"); @@ -48,7 +53,6 @@ auto listenTcp(string address = "", ushort port = 0, int backlog = 128) @trusted version(linux) { import core.sys.linux.sys.eventfd; - enum SOCK_NONBLOCK = 0x800; } import core.stdc.errno; @@ -76,7 +80,7 @@ auto listenTcp(string address = "", ushort port = 0, int backlog = 128) @trusted throw new Exception("bind"); } - if (core.sys.posix.sys.socket.listen(sock, backlog) == -1) { + if (listen(sock, backlog) == -1) { closeSocket(sock); throw new Exception("listen"); } @@ -86,9 +90,10 @@ auto listenTcp(string address = "", ushort port = 0, int backlog = 128) @trusted auto closeSocket(socket_t sock) @trusted { import core.sys.posix.unistd; - version(Windows) + version(Windows) { + import core.sys.windows.windows; closesocket(sock); - else + } else close(sock); } diff --git a/source/concurrency/scheduler.d b/source/concurrency/scheduler.d index 748f7a1..b851baf 100644 --- a/source/concurrency/scheduler.d +++ b/source/concurrency/scheduler.d @@ -19,7 +19,12 @@ enum isScheduler(T) = is(typeof(checkScheduler!T)); struct Client { import std.socket : socket_t; - import core.sys.posix.sys.socket : sockaddr, socklen_t; + version(Windows) { + import core.sys.windows.windows : sockaddr, socklen_t; + } else version(Posix) { + import core.sys.posix.sys.socket : sockaddr, socklen_t; + } + socket_t fd; sockaddr addr; socklen_t addrlen; diff --git a/tests/ut/concurrency/io.d b/tests/ut/concurrency/io.d index e182362..e54afcb 100644 --- a/tests/ut/concurrency/io.d +++ b/tests/ut/concurrency/io.d @@ -8,6 +8,8 @@ import concurrency.operations; import std.typecons : tuple; import core.time : msecs; +version (linux): + @safe @("Schedule.single") unittest {