From e8ed523c08e9b6e4742c16f9b75ca7bfe06e7196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 15 Mar 2020 19:50:21 +0100 Subject: [PATCH] Fix transferred byte counter for windows stream socket reads/writes. Fixes read/write sizes that are sometimes reported too small. --- source/eventcore/drivers/winapi/sockets.d | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/eventcore/drivers/winapi/sockets.d b/source/eventcore/drivers/winapi/sockets.d index 03673fc..051b111 100644 --- a/source/eventcore/drivers/winapi/sockets.d +++ b/source/eventcore/drivers/winapi/sockets.d @@ -249,6 +249,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { { auto slot = () @trusted { return &m_sockets[socket].streamSocket(); } (); slot.read.buffer = buffer; + slot.read.bytesTransferred = 0; slot.read.mode = mode; slot.read.wsabuf[0].len = buffer.length; slot.read.wsabuf[0].buf = () @trusted { return buffer.ptr; } (); @@ -306,7 +307,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { } if (slot.streamSocket.read.mode == IOMode.once || !slot.streamSocket.read.buffer.length) { - invokeCallback(IOStatus.ok, cbTransferred); + invokeCallback(IOStatus.ok, slot.streamSocket.read.bytesTransferred); return; } @@ -332,6 +333,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { { auto slot = () @trusted { return &m_sockets[socket].streamSocket(); } (); slot.write.buffer = buffer; + slot.write.bytesTransferred = 0; slot.write.mode = mode; slot.write.wsabuf[0].len = buffer.length; slot.write.wsabuf[0].buf = () @trusted { return cast(ubyte*)buffer.ptr; } (); @@ -381,7 +383,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { } if (slot.streamSocket.write.mode == IOMode.once || !slot.streamSocket.write.buffer.length) { - invokeCallback(IOStatus.ok, cbTransferred); + invokeCallback(IOStatus.ok, slot.streamSocket.write.bytesTransferred); return; } @@ -854,8 +856,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets { cb(cast(StreamSocketFD)sock, ConnectStatus.refused); } else { slot.streamSocket.state = ConnectionState.connected; - if (slot.common.driver.releaseRef(cast(StreamSocketFD)sock)) - cb(cast(StreamSocketFD)sock, ConnectStatus.connected); + cb(cast(StreamSocketFD)sock, ConnectStatus.connected); } break; case FD_READ: