Let TCPConnection.waitForData amd leastSize act gracefully on closed connections.

This commit is contained in:
Sönke Ludwig 2017-01-30 12:04:21 +01:00
parent ac811ba501
commit 2dccd43277
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -472,7 +472,7 @@ struct TCPConnection {
return s >= ConnectionState.connected && s < ConnectionState.activeClose; return s >= ConnectionState.connected && s < ConnectionState.activeClose;
} }
@property bool empty() { return leastSize == 0; } @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); } @property bool dataAvailableForRead() { return waitForData(0.seconds); }
void close() void close()
@ -489,6 +489,7 @@ struct TCPConnection {
bool waitForData(Duration timeout = Duration.max) bool waitForData(Duration timeout = Duration.max)
{ {
mixin(tracer); mixin(tracer);
if (!m_context) return false;
if (m_context.readBuffer.length > 0) return true; if (m_context.readBuffer.length > 0) return true;
auto mode = timeout <= 0.seconds ? IOMode.immediate : IOMode.once; auto mode = timeout <= 0.seconds ? IOMode.immediate : IOMode.once;