From 0d78dfe4a938c469f41154fd260b5dd04a2e584c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 16 Jun 2019 09:55:00 +0200 Subject: [PATCH] Let TCPConnection.leastSize time out according to the readTimeout property. Fixes #153. --- source/vibe/core/net.d | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index ec8b027..8fc6933 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -553,7 +553,18 @@ struct TCPConnection { return s >= ConnectionState.connected && s < ConnectionState.activeClose; } @property bool empty() { return leastSize == 0; } - @property ulong leastSize() { waitForData(); return m_context ? m_context.readBuffer.length : 0; } + + @property ulong leastSize() + { + if (!m_context) return 0; + + auto res = waitForDataEx(m_context.readTimeout); + if (res == WaitForDataStatus.timeout) + throw new ReadTimeoutException("Read operation timed out"); + + return m_context.readBuffer.length; + } + @property bool dataAvailableForRead() { return waitForData(0.seconds); } void close()