From 2dccd4327728b2d9a82936e34b8afd12f1c03f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 30 Jan 2017 12:04:21 +0100 Subject: [PATCH] Let TCPConnection.waitForData amd leastSize act gracefully on closed connections. --- source/vibe/core/net.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index b0a158d..cf53530 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -472,7 +472,7 @@ struct TCPConnection { return s >= ConnectionState.connected && s < ConnectionState.activeClose; } @property bool empty() { return leastSize == 0; } - @property ulong leastSize() { waitForData(); return m_context.readBuffer.length; } + @property ulong leastSize() { waitForData(); return m_context && m_context.readBuffer.length; } @property bool dataAvailableForRead() { return waitForData(0.seconds); } void close() @@ -489,6 +489,7 @@ struct TCPConnection { bool waitForData(Duration timeout = Duration.max) { mixin(tracer); + if (!m_context) return false; if (m_context.readBuffer.length > 0) return true; auto mode = timeout <= 0.seconds ? IOMode.immediate : IOMode.once;