Fix possible hang after partial socket reads.

This commit is contained in:
Sönke Ludwig 2020-03-17 15:15:19 +01:00
parent 5c4e8be20a
commit 7c3fdc5ddf

View file

@ -455,6 +455,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
assert(m_loop.m_fds[socket].common.refCount > 0);
}
while (true) {
sizediff_t ret = 0;
() @trusted { ret = .recv(cast(sock_t)socket, slot.readBuffer.ptr, min(slot.readBuffer.length, int.max), 0); } ();
if (ret < 0) {
@ -481,6 +482,11 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
return;
}
}
// retry if this was just a partial read, as it could mean that
// the connection was closed by the remove peer
if (ret <= 0 || !slot.readBuffer.length) break;
}
}
private static IOStatus handleReadError(int err, ref StreamSocketSlot slot)