Skip to content

Commit

Permalink
Restore compile on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Aug 31, 2024
1 parent ee3e7af commit a0eaf47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion source/concurrency/io/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions source/concurrency/io/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
Expand All @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion source/concurrency/scheduler.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ut/concurrency/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import concurrency.operations;
import std.typecons : tuple;
import core.time : msecs;

version (linux):

@safe
@("Schedule.single")
unittest {
Expand Down

0 comments on commit a0eaf47

Please sign in to comment.