From b556849af210c7f9805801e9c1466c3be9f5662e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 23 Jan 2017 10:03:36 +0100 Subject: [PATCH] Fully fix the Win64 build (test might still fail). --- dub.sdl | 2 +- source/eventcore/driver.d | 13 +++---- source/eventcore/drivers/posix.d | 46 +++++++++++++------------ source/eventcore/drivers/threadedfile.d | 12 +++---- source/eventcore/drivers/winapi.d | 2 +- source/eventcore/internal/utils.d | 2 +- 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/dub.sdl b/dub.sdl index ad570ce..d207b87 100644 --- a/dub.sdl +++ b/dub.sdl @@ -6,7 +6,7 @@ copyright "Copyright © 2012-2016 rejectedsoftware e.K." targetType "library" libs "anl" platform="linux" -libs "ws2_32" platform="windows" +libs "ws2_32" "user32" platform="windows" dependency "taggedalgebraic" version="~>0.10.4" diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index 49e7e12..efada2a 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -570,7 +570,8 @@ struct FileChange { } struct Handle(string NAME, T, T invalid_value = T.init) { - static if (is(T : Handle!(N, V, M), string N, V, int M)) alias BaseType = T.BaseType; + import std.traits : isInstanceOf; + static if (isInstanceOf!(.Handle, T)) alias BaseType = T.BaseType; else alias BaseType = T; alias name = NAME; @@ -601,8 +602,8 @@ alias StreamListenSocketFD = Handle!("streamListen", SocketFD); alias DatagramSocketFD = Handle!("datagramSocket", SocketFD); alias FileFD = Handle!("file", FD); alias EventID = Handle!("event", FD); -alias TimerID = Handle!("timer", int); -alias WatcherID = Handle!("watcher", int); -alias EventWaitID = Handle!("eventWait", int); -alias SignalListenID = Handle!("signal", int); -alias DNSLookupID = Handle!("dns", int); +alias TimerID = Handle!("timer", size_t); +alias WatcherID = Handle!("watcher", size_t); +alias EventWaitID = Handle!("eventWait", size_t); +alias SignalListenID = Handle!("signal", size_t); +alias DNSLookupID = Handle!("dns", size_t); diff --git a/source/eventcore/drivers/posix.d b/source/eventcore/drivers/posix.d index 80d5d69..1f891e7 100644 --- a/source/eventcore/drivers/posix.d +++ b/source/eventcore/drivers/posix.d @@ -12,7 +12,7 @@ import eventcore.drivers.threadedfile; import eventcore.internal.consumablequeue : ConsumableQueue; import eventcore.internal.utils; -import std.algorithm.comparison : among; +import std.algorithm.comparison : among, min, max; import std.socket : Address, AddressFamily, InternetAddress, Internet6Address, UnknownAddress; version (Posix) { @@ -33,6 +33,7 @@ version (Windows) { enum SHUT_RDWR = SD_BOTH; enum SHUT_RD = SD_RECEIVE; enum SHUT_WR = SD_SEND; + alias sock_t = size_t; extern (C) int read(int fd, void *buffer, uint count) nothrow; extern (C) int write(int fd, const(void) *buffer, uint count) nothrow; extern (C) int close(int fd) nothrow @safe; @@ -40,6 +41,7 @@ version (Windows) { version (linux) { extern (C) int eventfd(uint initval, int flags); enum EFD_NONBLOCK = 0x800; + alias sock_t = int; } @@ -124,7 +126,7 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime Timers m_timers; Events m_events; bool m_exit = false; - FD m_wakeupEvent; + EventID m_wakeupEvent; } protected this(Loop loop, Timers timers, Events events) @@ -138,7 +140,6 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime final override ExitReason processEvents(Duration timeout) { - import std.algorithm : min, max; import core.time : hnsecs, seconds; if (m_exit) { @@ -182,8 +183,7 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime final override void exit() { m_exit = true; - long one = 1; - () @trusted { .write(m_wakeupEvent, &one, one.sizeof); } (); + () @trusted { (cast(shared)m_events).trigger(m_wakeupEvent, true); } (); } final override void clearExitFlag() @@ -353,7 +353,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets private void onAccept(FD listenfd) { foreach (i; 0 .. 20) { - int sockfd; + sock_t sockfd; sockaddr_storage addr; socklen_t addr_len = addr.sizeof; () @trusted { sockfd = accept(listenfd, () @trusted { return cast(sockaddr*)&addr; } (), &addr_len); } (); @@ -406,7 +406,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets }*/ sizediff_t ret; - () @trusted { ret = .recv(socket, buffer.ptr, buffer.length, 0); } (); + () @trusted { ret = .recv(socket, buffer.ptr, min(buffer.length, int.max), 0); } (); if (ret < 0) { auto err = getSocketError(); @@ -473,7 +473,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets } sizediff_t ret = 0; - () @trusted { ret = .recv(socket, slot.readBuffer.ptr, slot.readBuffer.length, 0); } (); + () @trusted { ret = .recv(socket, slot.readBuffer.ptr, min(slot.readBuffer.length, int.max), 0); } (); if (ret < 0) { auto err = getSocketError(); if (!err.among!(EAGAIN, EINPROGRESS)) { @@ -506,7 +506,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets } sizediff_t ret; - () @trusted { ret = .send(socket, buffer.ptr, buffer.length, 0); } (); + () @trusted { ret = .send(socket, buffer.ptr, min(buffer.length, int.max), 0); } (); if (ret < 0) { auto err = getSocketError(); @@ -564,7 +564,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets auto socket = cast(StreamSocketFD)fd; sizediff_t ret; - () @trusted { ret = .send(socket, slot.writeBuffer.ptr, slot.writeBuffer.length, 0); } (); + () @trusted { ret = .send(socket, slot.writeBuffer.ptr, min(slot.writeBuffer.length, int.max), 0); } (); if (ret < 0) { auto err = getSocketError(); @@ -725,7 +725,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets sizediff_t ret; sockaddr_storage src_addr; socklen_t src_addr_len = src_addr.sizeof; - () @trusted { ret = .recvfrom(socket, buffer.ptr, buffer.length, 0, cast(sockaddr*)&src_addr, &src_addr_len); } (); + () @trusted { ret = .recvfrom(socket, buffer.ptr, min(buffer.length, int.max), 0, cast(sockaddr*)&src_addr, &src_addr_len); } (); if (ret < 0) { auto err = getSocketError(); @@ -769,7 +769,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets sizediff_t ret; sockaddr_storage src_addr; socklen_t src_addr_len = src_addr.sizeof; - () @trusted { ret = .recvfrom(socket, slot.readBuffer.ptr, slot.readBuffer.length, 0, cast(sockaddr*)&src_addr, &src_addr_len); } (); + () @trusted { ret = .recvfrom(socket, slot.readBuffer.ptr, min(slot.readBuffer.length, int.max), 0, cast(sockaddr*)&src_addr, &src_addr_len); } (); if (ret < 0) { auto err = getSocketError(); @@ -791,10 +791,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets sizediff_t ret; if (target_address) { - () @trusted { ret = .sendto(socket, buffer.ptr, buffer.length, 0, target_address.name, target_address.nameLen); } (); + () @trusted { ret = .sendto(socket, buffer.ptr, min(buffer.length, int.max), 0, target_address.name, target_address.nameLen); } (); m_loop.m_fds[socket].datagramSocket.targetAddr = target_address; } else { - () @trusted { ret = .send(socket, buffer.ptr, buffer.length, 0); } (); + () @trusted { ret = .send(socket, buffer.ptr, min(buffer.length, int.max), 0); } (); } if (ret < 0) { @@ -837,9 +837,9 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets sizediff_t ret; if (slot.targetAddr) { - () @trusted { ret = .sendto(socket, slot.writeBuffer.ptr, slot.writeBuffer.length, 0, slot.targetAddr.name, slot.targetAddr.nameLen); } (); + () @trusted { ret = .sendto(socket, slot.writeBuffer.ptr, min(slot.writeBuffer.length, int.max), 0, slot.targetAddr.name, slot.targetAddr.nameLen); } (); } else { - () @trusted { ret = .send(socket, slot.writeBuffer.ptr, slot.writeBuffer.length, 0); } (); + () @trusted { ret = .send(socket, slot.writeBuffer.ptr, min(slot.writeBuffer.length, int.max), 0); } (); } if (ret < 0) { @@ -875,7 +875,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets private SocketFD createSocket(AddressFamily family, int type) { - int sock; + sock_t sock; () @trusted { sock = socket(family, type, 0); } (); if (sock == -1) return SocketFD.invalid; setSocketNonBlocking(cast(SocketFD)sock); @@ -1219,7 +1219,7 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS } } - final override void trigger(EventID event, bool notify_all = true) + final override void trigger(EventID event, bool notify_all) { auto slot = getSlot(event); if (notify_all) { @@ -1234,7 +1234,7 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS } } - final override void trigger(EventID event, bool notify_all = true) + final override void trigger(EventID event, bool notify_all) shared @trusted { import core.atomic : atomicStore; auto thisus = cast(PosixEventDriverEvents)this; @@ -1263,9 +1263,11 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS private void onEvent(FD fd) @trusted { - ulong cnt; EventID event = cast(EventID)fd; - () @trusted { .read(event, &cnt, cnt.sizeof); } (); + version (linux) { + ulong cnt; + () @trusted { .read(event, &cnt, cnt.sizeof); } (); + } import core.atomic : cas; auto all = cas(&getSlot(event).triggerAll, true, false); trigger(event, all); @@ -1763,7 +1765,7 @@ private void closeSocket(SocketFD sockfd) private void setSocketNonBlocking(SocketFD sockfd) { version (Windows) { - size_t enable = 1; + uint enable = 1; () @trusted { ioctlsocket(sockfd, FIONBIO, &enable); } (); } else { () @trusted { fcntl(sockfd, F_SETFL, O_NONBLOCK, 1); } (); diff --git a/source/eventcore/drivers/threadedfile.d b/source/eventcore/drivers/threadedfile.d index 2fc406f..e6a1f18 100644 --- a/source/eventcore/drivers/threadedfile.d +++ b/source/eventcore/drivers/threadedfile.d @@ -162,7 +162,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil void close(FileFD file) { - () @trusted { .close(file); } (); + () @trusted { .close(cast(int)file); } (); } ulong getSize(FileFD file) @@ -172,7 +172,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil return .lseek(file, 0, SEEK_END); } else { stat_t st; - () @trusted { fstat(file, &st); } (); + () @trusted { fstat(cast(int)file, &st); } (); return st.st_size; } } @@ -240,7 +240,7 @@ log("start task"); { auto f = () @trusted { return &m_files[descriptor]; } (); if (!--f.refCount) { - .close(descriptor); + .close(cast(int)descriptor); *f = FileInfo.init; assert(!m_activeReads.contains(descriptor)); assert(!m_activeWrites.contains(descriptor)); @@ -274,18 +274,18 @@ log("start processing"); auto bytes = buffer; version (Windows) { assert(offset <= off_t.max); - .lseek(file, cast(off_t)offset, SEEK_SET); + .lseek(cast(int)file, cast(off_t)offset, SEEK_SET); } else .lseek(file, offset, SEEK_SET); scope (exit) { log("trigger event"); safeAtomicStore(f.bytesWritten, buffer.length - bytes.length); - () @trusted { return cast(shared)fd.m_events; } ().trigger(fd.m_readyEvent); + () @trusted { return cast(shared)fd.m_events; } ().trigger(fd.m_readyEvent, true); } while (bytes.length > 0) { auto sz = min(bytes.length, 4096); - auto ret = () @trusted { return mixin("."~op)(file, bytes.ptr, cast(int)sz); } (); + auto ret = () @trusted { return mixin("."~op)(cast(int)file, bytes.ptr, cast(uint)sz); } (); if (ret != sz) { f.ioStatus = IOStatus.error; log("error"); diff --git a/source/eventcore/drivers/winapi.d b/source/eventcore/drivers/winapi.d index 6aecbbf..4c35631 100644 --- a/source/eventcore/drivers/winapi.d +++ b/source/eventcore/drivers/winapi.d @@ -872,7 +872,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { BOOL ret; () @trusted { - ret = ReadDirectoryChangesW(handle, slot.buffer.ptr, slot.buffer.length, slot.recursive, + ret = ReadDirectoryChangesW(handle, slot.buffer.ptr, cast(DWORD)slot.buffer.length, slot.recursive, notifications, null, &slot.overlapped, &onIOCompleted); } (); diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index 90d7227..db252ef 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -174,7 +174,7 @@ struct AlgebraicChoppedVector(TCommon, TSpecific...) /** Efficient bit set of dynamic size. */ -struct SmallIntegerSet(V : uint) +struct SmallIntegerSet(V : size_t) { private { uint[][4] m_bits;