assert and stronger condition on TCPConnection.waitForDataAsync

assert and stronger condition on TCPConnection.waitForDataAsync
This commit is contained in:
Francesco Mecca 2018-02-24 21:28:35 +01:00
parent 20e32cf327
commit 99e2873cc0

View file

@ -586,12 +586,6 @@ mixin(tracer);
return m_context.readBuffer.length > 0; return m_context.readBuffer.length > 0;
} }
enum WaitForDataAsyncStatus {
noMoreData,
dataAvailable,
waiting
}
WaitForDataAsyncStatus waitForDataAsync(void delegate(bool) @safe read_callback, Duration timeout = Duration.max) WaitForDataAsyncStatus waitForDataAsync(void delegate(bool) @safe read_callback, Duration timeout = Duration.max)
{ {
mixin(tracer); mixin(tracer);
@ -615,8 +609,9 @@ mixin(tracer);
auto tm = setTimer(timeout, { eventDriver.sockets.cancelRead(m_socket); auto tm = setTimer(timeout, { eventDriver.sockets.cancelRead(m_socket);
runTask(read_callback, false); }); runTask(read_callback, false); });
eventDriver.sockets.read(m_socket, m_context.readBuffer.peekDst(), IOMode.once, eventDriver.sockets.read(m_socket, m_context.readBuffer.peekDst(), IOMode.once,
(sock, st, nb) { tm.stop(); if(st != IOStatus.ok) runTask(read_callback, false); (sock, st, nb) { tm.stop(); assert(m_context.readBuffer.length == 0);
else runTask(read_callback, true); m_context.readBuffer.putN(nb);
runTask(read_callback, m_context.readBuffer.length > 0);
}); });
return WaitForDataAsyncStatus.waiting; return WaitForDataAsyncStatus.waiting;
} }
@ -719,6 +714,16 @@ mixin(tracer);
} }
} }
/** Represents possible return values for
TCPConnection.waitForDataAsync.
*/
enum WaitForDataAsyncStatus {
noMoreData,
dataAvailable,
waiting,
}
mixin validateConnectionStream!TCPConnection; mixin validateConnectionStream!TCPConnection;
private void loopWithTimeout(alias LoopBody, ExceptionType = Exception)(Duration timeout) private void loopWithTimeout(alias LoopBody, ExceptionType = Exception)(Duration timeout)