Fully fix the Win64 build (test might still fail).

This commit is contained in:
Sönke Ludwig 2017-01-23 10:03:36 +01:00
parent 2c4534d178
commit b556849af2
6 changed files with 40 additions and 37 deletions

View file

@ -6,7 +6,7 @@ copyright "Copyright © 2012-2016 rejectedsoftware e.K."
targetType "library" targetType "library"
libs "anl" platform="linux" libs "anl" platform="linux"
libs "ws2_32" platform="windows" libs "ws2_32" "user32" platform="windows"
dependency "taggedalgebraic" version="~>0.10.4" dependency "taggedalgebraic" version="~>0.10.4"

View file

@ -570,7 +570,8 @@ struct FileChange {
} }
struct Handle(string NAME, T, T invalid_value = T.init) { 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; else alias BaseType = T;
alias name = NAME; alias name = NAME;
@ -601,8 +602,8 @@ alias StreamListenSocketFD = Handle!("streamListen", SocketFD);
alias DatagramSocketFD = Handle!("datagramSocket", SocketFD); alias DatagramSocketFD = Handle!("datagramSocket", SocketFD);
alias FileFD = Handle!("file", FD); alias FileFD = Handle!("file", FD);
alias EventID = Handle!("event", FD); alias EventID = Handle!("event", FD);
alias TimerID = Handle!("timer", int); alias TimerID = Handle!("timer", size_t);
alias WatcherID = Handle!("watcher", int); alias WatcherID = Handle!("watcher", size_t);
alias EventWaitID = Handle!("eventWait", int); alias EventWaitID = Handle!("eventWait", size_t);
alias SignalListenID = Handle!("signal", int); alias SignalListenID = Handle!("signal", size_t);
alias DNSLookupID = Handle!("dns", int); alias DNSLookupID = Handle!("dns", size_t);

View file

@ -12,7 +12,7 @@ import eventcore.drivers.threadedfile;
import eventcore.internal.consumablequeue : ConsumableQueue; import eventcore.internal.consumablequeue : ConsumableQueue;
import eventcore.internal.utils; import eventcore.internal.utils;
import std.algorithm.comparison : among; import std.algorithm.comparison : among, min, max;
import std.socket : Address, AddressFamily, InternetAddress, Internet6Address, UnknownAddress; import std.socket : Address, AddressFamily, InternetAddress, Internet6Address, UnknownAddress;
version (Posix) { version (Posix) {
@ -33,6 +33,7 @@ version (Windows) {
enum SHUT_RDWR = SD_BOTH; enum SHUT_RDWR = SD_BOTH;
enum SHUT_RD = SD_RECEIVE; enum SHUT_RD = SD_RECEIVE;
enum SHUT_WR = SD_SEND; enum SHUT_WR = SD_SEND;
alias sock_t = size_t;
extern (C) int read(int fd, void *buffer, uint count) nothrow; 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 write(int fd, const(void) *buffer, uint count) nothrow;
extern (C) int close(int fd) nothrow @safe; extern (C) int close(int fd) nothrow @safe;
@ -40,6 +41,7 @@ version (Windows) {
version (linux) { version (linux) {
extern (C) int eventfd(uint initval, int flags); extern (C) int eventfd(uint initval, int flags);
enum EFD_NONBLOCK = 0x800; enum EFD_NONBLOCK = 0x800;
alias sock_t = int;
} }
@ -124,7 +126,7 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime
Timers m_timers; Timers m_timers;
Events m_events; Events m_events;
bool m_exit = false; bool m_exit = false;
FD m_wakeupEvent; EventID m_wakeupEvent;
} }
protected this(Loop loop, Timers timers, Events events) 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) final override ExitReason processEvents(Duration timeout)
{ {
import std.algorithm : min, max;
import core.time : hnsecs, seconds; import core.time : hnsecs, seconds;
if (m_exit) { if (m_exit) {
@ -182,8 +183,7 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime
final override void exit() final override void exit()
{ {
m_exit = true; m_exit = true;
long one = 1; () @trusted { (cast(shared)m_events).trigger(m_wakeupEvent, true); } ();
() @trusted { .write(m_wakeupEvent, &one, one.sizeof); } ();
} }
final override void clearExitFlag() final override void clearExitFlag()
@ -353,7 +353,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
private void onAccept(FD listenfd) private void onAccept(FD listenfd)
{ {
foreach (i; 0 .. 20) { foreach (i; 0 .. 20) {
int sockfd; sock_t sockfd;
sockaddr_storage addr; sockaddr_storage addr;
socklen_t addr_len = addr.sizeof; socklen_t addr_len = addr.sizeof;
() @trusted { sockfd = accept(listenfd, () @trusted { return cast(sockaddr*)&addr; } (), &addr_len); } (); () @trusted { sockfd = accept(listenfd, () @trusted { return cast(sockaddr*)&addr; } (), &addr_len); } ();
@ -406,7 +406,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
}*/ }*/
sizediff_t ret; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
@ -473,7 +473,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
} }
sizediff_t ret = 0; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
if (!err.among!(EAGAIN, EINPROGRESS)) { if (!err.among!(EAGAIN, EINPROGRESS)) {
@ -506,7 +506,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
} }
sizediff_t ret; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
@ -564,7 +564,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
auto socket = cast(StreamSocketFD)fd; auto socket = cast(StreamSocketFD)fd;
sizediff_t ret; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
@ -725,7 +725,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
sizediff_t ret; sizediff_t ret;
sockaddr_storage src_addr; sockaddr_storage src_addr;
socklen_t src_addr_len = src_addr.sizeof; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
@ -769,7 +769,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
sizediff_t ret; sizediff_t ret;
sockaddr_storage src_addr; sockaddr_storage src_addr;
socklen_t src_addr_len = src_addr.sizeof; 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) { if (ret < 0) {
auto err = getSocketError(); auto err = getSocketError();
@ -791,10 +791,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
sizediff_t ret; sizediff_t ret;
if (target_address) { 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; m_loop.m_fds[socket].datagramSocket.targetAddr = target_address;
} else { } 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) { if (ret < 0) {
@ -837,9 +837,9 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
sizediff_t ret; sizediff_t ret;
if (slot.targetAddr) { 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 { } 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) { if (ret < 0) {
@ -875,7 +875,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
private SocketFD createSocket(AddressFamily family, int type) private SocketFD createSocket(AddressFamily family, int type)
{ {
int sock; sock_t sock;
() @trusted { sock = socket(family, type, 0); } (); () @trusted { sock = socket(family, type, 0); } ();
if (sock == -1) return SocketFD.invalid; if (sock == -1) return SocketFD.invalid;
setSocketNonBlocking(cast(SocketFD)sock); 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); auto slot = getSlot(event);
if (notify_all) { 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 { shared @trusted {
import core.atomic : atomicStore; import core.atomic : atomicStore;
auto thisus = cast(PosixEventDriverEvents)this; auto thisus = cast(PosixEventDriverEvents)this;
@ -1263,9 +1263,11 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS
private void onEvent(FD fd) private void onEvent(FD fd)
@trusted { @trusted {
ulong cnt;
EventID event = cast(EventID)fd; 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; import core.atomic : cas;
auto all = cas(&getSlot(event).triggerAll, true, false); auto all = cas(&getSlot(event).triggerAll, true, false);
trigger(event, all); trigger(event, all);
@ -1763,7 +1765,7 @@ private void closeSocket(SocketFD sockfd)
private void setSocketNonBlocking(SocketFD sockfd) private void setSocketNonBlocking(SocketFD sockfd)
{ {
version (Windows) { version (Windows) {
size_t enable = 1; uint enable = 1;
() @trusted { ioctlsocket(sockfd, FIONBIO, &enable); } (); () @trusted { ioctlsocket(sockfd, FIONBIO, &enable); } ();
} else { } else {
() @trusted { fcntl(sockfd, F_SETFL, O_NONBLOCK, 1); } (); () @trusted { fcntl(sockfd, F_SETFL, O_NONBLOCK, 1); } ();

View file

@ -162,7 +162,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil
void close(FileFD file) void close(FileFD file)
{ {
() @trusted { .close(file); } (); () @trusted { .close(cast(int)file); } ();
} }
ulong getSize(FileFD file) ulong getSize(FileFD file)
@ -172,7 +172,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil
return .lseek(file, 0, SEEK_END); return .lseek(file, 0, SEEK_END);
} else { } else {
stat_t st; stat_t st;
() @trusted { fstat(file, &st); } (); () @trusted { fstat(cast(int)file, &st); } ();
return st.st_size; return st.st_size;
} }
} }
@ -240,7 +240,7 @@ log("start task");
{ {
auto f = () @trusted { return &m_files[descriptor]; } (); auto f = () @trusted { return &m_files[descriptor]; } ();
if (!--f.refCount) { if (!--f.refCount) {
.close(descriptor); .close(cast(int)descriptor);
*f = FileInfo.init; *f = FileInfo.init;
assert(!m_activeReads.contains(descriptor)); assert(!m_activeReads.contains(descriptor));
assert(!m_activeWrites.contains(descriptor)); assert(!m_activeWrites.contains(descriptor));
@ -274,18 +274,18 @@ log("start processing");
auto bytes = buffer; auto bytes = buffer;
version (Windows) { version (Windows) {
assert(offset <= off_t.max); 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); } else .lseek(file, offset, SEEK_SET);
scope (exit) { scope (exit) {
log("trigger event"); log("trigger event");
safeAtomicStore(f.bytesWritten, buffer.length - bytes.length); 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) { while (bytes.length > 0) {
auto sz = min(bytes.length, 4096); 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) { if (ret != sz) {
f.ioStatus = IOStatus.error; f.ioStatus = IOStatus.error;
log("error"); log("error");

View file

@ -872,7 +872,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
BOOL ret; BOOL ret;
() @trusted { () @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); notifications, null, &slot.overlapped, &onIOCompleted);
} (); } ();

View file

@ -174,7 +174,7 @@ struct AlgebraicChoppedVector(TCommon, TSpecific...)
/** Efficient bit set of dynamic size. /** Efficient bit set of dynamic size.
*/ */
struct SmallIntegerSet(V : uint) struct SmallIntegerSet(V : size_t)
{ {
private { private {
uint[][4] m_bits; uint[][4] m_bits;