From 54208ba46fe4d4efb9e7f2cf0678563fa08c9e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 4 Jun 2019 15:19:52 +0200 Subject: [PATCH 1/2] Require eventcore 0.8.43 for process and reuseAddress support. --- dub.sdl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dub.sdl b/dub.sdl index 8c4688f..1c96fcd 100644 --- a/dub.sdl +++ b/dub.sdl @@ -4,7 +4,7 @@ authors "Sönke Ludwig" copyright "Copyright © 2016-2018, rejectedsoftware e.K." license "MIT" -dependency "eventcore" version="~>0.8.40" +dependency "eventcore" version="~>0.8.43" dependency "stdx-allocator" version="~>2.77.0" targetName "vibe_core" From 539310966937f8cde47b9679f55800cddffe5bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 4 Jun 2019 15:20:54 +0200 Subject: [PATCH 2/2] Add TCPConnection.waitForDataEx. Allows to distinguish between timeout and no more data cases. --- source/vibe/core/net.d | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index f3a4e42..ec8b027 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -568,10 +568,15 @@ struct TCPConnection { } bool waitForData(Duration timeout = Duration.max) + { + return waitForDataEx(timeout) == WaitForDataStatus.dataAvailable; + } + + WaitForDataStatus waitForDataEx(Duration timeout = Duration.max) { mixin(tracer); - if (!m_context) return false; - if (m_context.readBuffer.length > 0) return true; + if (!m_context) return WaitForDataStatus.noMoreData; + if (m_context.readBuffer.length > 0) return WaitForDataStatus.dataAvailable; auto mode = timeout <= 0.seconds ? IOMode.immediate : IOMode.once; bool cancelled; @@ -592,7 +597,8 @@ mixin(tracer); asyncAwaitAny!(true, waiter)(timeout); - if (cancelled || !m_context) return false; + if (!m_context) return WaitForDataStatus.noMoreData; + if (cancelled) return WaitForDataStatus.timeout; logTrace("Socket %s, read %s bytes: %s", m_socket, nbytes, status); @@ -607,9 +613,10 @@ mixin(tracer); case IOStatus.disconnected: break; } - return m_context.readBuffer.length > 0; + return m_context.readBuffer.length > 0 ? WaitForDataStatus.dataAvailable : WaitForDataStatus.noMoreData; } + /** Waits asynchronously for new data to arrive. This function can be used to detach the `TCPConnection` from a @@ -808,6 +815,12 @@ enum WaitForDataAsyncStatus { waiting, } +enum WaitForDataStatus { + dataAvailable, + noMoreData, + timeout +} + unittest { // test compilation of callback with scoped destruction static struct CB { ~this() {}