From 99e2873cc01c2f66feb15a73d315ee48765b0c12 Mon Sep 17 00:00:00 2001 From: Francesco Mecca Date: Sat, 24 Feb 2018 21:28:35 +0100 Subject: [PATCH] assert and stronger condition on TCPConnection.waitForDataAsync assert and stronger condition on TCPConnection.waitForDataAsync --- source/vibe/core/net.d | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index f29d4b8..496b093 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -586,12 +586,6 @@ mixin(tracer); return m_context.readBuffer.length > 0; } - enum WaitForDataAsyncStatus { - noMoreData, - dataAvailable, - waiting - } - WaitForDataAsyncStatus waitForDataAsync(void delegate(bool) @safe read_callback, Duration timeout = Duration.max) { mixin(tracer); @@ -615,8 +609,9 @@ mixin(tracer); auto tm = setTimer(timeout, { eventDriver.sockets.cancelRead(m_socket); runTask(read_callback, false); }); eventDriver.sockets.read(m_socket, m_context.readBuffer.peekDst(), IOMode.once, - (sock, st, nb) { tm.stop(); if(st != IOStatus.ok) runTask(read_callback, false); - else runTask(read_callback, true); + (sock, st, nb) { tm.stop(); assert(m_context.readBuffer.length == 0); + m_context.readBuffer.putN(nb); + runTask(read_callback, m_context.readBuffer.length > 0); }); return WaitForDataAsyncStatus.waiting; } @@ -719,6 +714,16 @@ mixin(tracer); } } +/** Represents possible return values for + TCPConnection.waitForDataAsync. +*/ +enum WaitForDataAsyncStatus { + noMoreData, + dataAvailable, + waiting, +} + + mixin validateConnectionStream!TCPConnection; private void loopWithTimeout(alias LoopBody, ExceptionType = Exception)(Duration timeout)