From 55cd860ea3d86b2f9b1ee5857fde72e9e052e1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 12 Jan 2021 11:49:05 +0100 Subject: [PATCH 1/2] Implement ThreadedFileEventDriver.truncate on Windows. --- source/eventcore/drivers/threadedfile.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/eventcore/drivers/threadedfile.d b/source/eventcore/drivers/threadedfile.d index 9058483..f9dd6c4 100644 --- a/source/eventcore/drivers/threadedfile.d +++ b/source/eventcore/drivers/threadedfile.d @@ -224,6 +224,26 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil return; } on_finish(file, IOStatus.ok, 0); + } else version (Windows) { + import core.sys.windows.windows : FILE_BEGIN, HANDLE, INVALID_HANDLE_VALUE, + LARGE_INTEGER, SetFilePointerEx, SetEndOfFile; + import core.stdc.stdio : _get_osfhandle; + + auto h = () @trusted { return cast(HANDLE)_get_osfhandle(cast(int)file); } (); + if (h == INVALID_HANDLE_VALUE) { + on_finish(file, IOStatus.error, 0); + return; + } + LARGE_INTEGER ls = { QuadPart: size }; + if (!() @trusted { return SetFilePointerEx(h, ls, null, FILE_BEGIN); } ()) { + on_finish(file, IOStatus.error, 0); + return; + } + if (!() @trusted { return SetEndOfFile(h); } ()) { + on_finish(file, IOStatus.error, 0); + return; + } + on_finish(file, IOStatus.ok, 0); } else { on_finish(file, IOStatus.error, 0); } From 7c2fd87308ad31a701850647077a04ae9b80f864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 12 Jan 2021 14:23:30 +0100 Subject: [PATCH 2/2] Increase I/O buffer size. Uses a buffer size that is more reasonable for modern transfer speeds, while still providing enough granularity for cancellation. This heavily reduces the computational overhead on SSD drives. --- source/eventcore/drivers/threadedfile.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/eventcore/drivers/threadedfile.d b/source/eventcore/drivers/threadedfile.d index f9dd6c4..485fd83 100644 --- a/source/eventcore/drivers/threadedfile.d +++ b/source/eventcore/drivers/threadedfile.d @@ -399,7 +399,7 @@ log("trigger event"); if (bytes.length == 0) safeAtomicStore(f.ioStatus, IOStatus.ok); while (bytes.length > 0) { - auto sz = min(bytes.length, 4096); + auto sz = min(bytes.length, 512*1024); auto ret = () @trusted { return mixin("."~op)(cast(int)file, bytes.ptr, cast(uint)sz); } (); if (ret != sz) { safeAtomicStore(f.ioStatus, IOStatus.error);