From 00b8607fc1338aa478b34d56121c1a6e3344102d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 15 Mar 2020 20:24:55 +0100 Subject: [PATCH] Fix IOMode.immediate for Windows sockets to guarantee calling the callback. --- source/eventcore/drivers/winapi/sockets.d | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/eventcore/drivers/winapi/sockets.d b/source/eventcore/drivers/winapi/sockets.d index 051b111..8d82029 100644 --- a/source/eventcore/drivers/winapi/sockets.d +++ b/source/eventcore/drivers/winapi/sockets.d @@ -552,8 +552,11 @@ final class WinAPIEventDriverSockets : EventDriverSockets { } } - if (mode == IOMode.immediate) + if (mode == IOMode.immediate) { () @trusted { CancelIoEx(cast(HANDLE)cast(SOCKET)socket, cast(LPOVERLAPPED)&slot.read.overlapped); } (); + on_read_finish(socket, IOStatus.wouldBlock, 0, null); + return; + } slot.read.callback = on_read_finish; addRef(socket); @@ -646,8 +649,11 @@ final class WinAPIEventDriverSockets : EventDriverSockets { } } - if (mode == IOMode.immediate) + if (mode == IOMode.immediate) { () @trusted { CancelIoEx(cast(HANDLE)cast(SOCKET)socket, cast(LPOVERLAPPED)&slot.write.overlapped); } (); + on_write_finish(socket, IOStatus.wouldBlock, 0, null); + return; + } slot.write.callback = on_write_finish; addRef(socket);