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" 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() {}