Get rid of OVERLAPPED_FILE.

The hEvent member is currently unused for files. Using it for the file handle makes the OVERLAPPED_CORE struct sufficient.
This commit is contained in:
Sönke Ludwig 2018-03-11 00:27:14 +01:00
parent 0e1d74cc41
commit 9dc8b796e5
2 changed files with 12 additions and 19 deletions

View file

@ -225,7 +225,7 @@ private struct HandleSlot {
package struct FileSlot { package struct FileSlot {
static struct Direction(bool RO) { static struct Direction(bool RO) {
OVERLAPPED_FILE overlapped; OVERLAPPED_CORE overlapped;
FileIOCallback callback; FileIOCallback callback;
ulong offset; ulong offset;
size_t bytesTransferred; size_t bytesTransferred;
@ -238,7 +238,7 @@ package struct FileSlot {
auto cb = this.callback; auto cb = this.callback;
this.callback = null; this.callback = null;
assert(cb !is null); assert(cb !is null);
cb(overlapped.handle, status, bytes_transferred); cb(cast(FileFD)cast(size_t)overlapped.hEvent, status, bytes_transferred);
} }
} }
Direction!false read; Direction!false read;
@ -259,12 +259,6 @@ package struct OVERLAPPED_CORE {
WinAPIEventDriverCore driver; WinAPIEventDriverCore driver;
} }
package struct OVERLAPPED_FILE {
OVERLAPPED_CORE core;
alias core this;
FileFD handle;
}
package struct IOEvent { package struct IOEvent {
void function(DWORD err, DWORD bts, OVERLAPPED_CORE*) @safe nothrow process; void function(DWORD err, DWORD bts, OVERLAPPED_CORE*) @safe nothrow process;
DWORD error; DWORD error;

View file

@ -64,9 +64,9 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
auto s = m_core.setupSlot!FileSlot(handle); auto s = m_core.setupSlot!FileSlot(handle);
s.read.overlapped.driver = m_core; s.read.overlapped.driver = m_core;
s.read.overlapped.handle = FileFD(cast(size_t)handle); s.read.overlapped.hEvent = handle;
s.write.overlapped.driver = m_core; s.write.overlapped.driver = m_core;
s.write.overlapped.handle = FileFD(cast(size_t)handle); s.write.overlapped.hEvent = handle;
return FileFD(cast(size_t)handle); return FileFD(cast(size_t)handle);
} }
@ -75,9 +75,9 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
{ {
auto h = idToHandle(file); auto h = idToHandle(file);
auto slot = () @trusted { return &m_core.m_handles[h].file(); } (); auto slot = () @trusted { return &m_core.m_handles[h].file(); } ();
if (slot.read.overlapped.handle != FileFD.invalid) { if (slot.read.overlapped.hEvent != INVALID_HANDLE_VALUE) {
CloseHandle(h); CloseHandle(h);
slot.read.overlapped.handle = slot.write.overlapped.handle = FileFD.invalid; slot.read.overlapped.hEvent = slot.write.overlapped.hEvent = INVALID_HANDLE_VALUE;
} }
} }
@ -183,15 +183,14 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
} }
private static nothrow private static nothrow
void onIOFinished(alias fun, bool RO)(DWORD error, DWORD bytes_transferred, OVERLAPPED_CORE* _overlapped) void onIOFinished(alias fun, bool RO)(DWORD error, DWORD bytes_transferred, OVERLAPPED_CORE* overlapped)
{ {
auto ctx = () @trusted { return cast(OVERLAPPED_FILE*)_overlapped; } (); FileFD id = cast(FileFD)cast(size_t)overlapped.hEvent;
FileFD id = ctx.handle;
auto handle = idToHandle(id); auto handle = idToHandle(id);
static if (RO) static if (RO)
auto slot = () @trusted { return &ctx.driver.m_handles[handle].file.write; } (); auto slot = () @trusted { return &overlapped.driver.m_handles[handle].file.write; } ();
else else
auto slot = () @trusted { return &ctx.driver.m_handles[handle].file.read; } (); auto slot = () @trusted { return &overlapped.driver.m_handles[handle].file.read; } ();
assert(slot !is null); assert(slot !is null);
if (!slot.callback) { if (!slot.callback) {
@ -200,7 +199,7 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
} }
if (error != 0) { if (error != 0) {
ctx.driver.removeWaiter(); overlapped.driver.removeWaiter();
slot.invokeCallback(IOStatus.error, slot.bytesTransferred + bytes_transferred); slot.invokeCallback(IOStatus.error, slot.bytesTransferred + bytes_transferred);
return; return;
} }
@ -209,7 +208,7 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
slot.offset += bytes_transferred; slot.offset += bytes_transferred;
if (slot.bytesTransferred >= slot.buffer.length || slot.mode != IOMode.all) { if (slot.bytesTransferred >= slot.buffer.length || slot.mode != IOMode.all) {
ctx.driver.removeWaiter(); overlapped.driver.removeWaiter();
slot.invokeCallback(IOStatus.ok, slot.bytesTransferred); slot.invokeCallback(IOStatus.ok, slot.bytesTransferred);
} else { } else {
startIO!(fun, RO)(handle, slot); startIO!(fun, RO)(handle, slot);