Add DuplexTransport.close for the selector transport
This commit is contained in:
parent
3454a1965a
commit
e86ff63f91
@ -37,6 +37,8 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
|
|
||||||
private Protocol protocol_;
|
private Protocol protocol_;
|
||||||
|
|
||||||
|
private bool closing;
|
||||||
|
|
||||||
/// Received notification that the underlying socket is write-ready.
|
/// Received notification that the underlying socket is write-ready.
|
||||||
package bool writeReady;
|
package bool writeReady;
|
||||||
|
|
||||||
@ -115,6 +117,25 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
protocol_ = protocol;
|
protocol_ = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns $(D_PARAM true) if the transport is closing or closed.
|
||||||
|
*/
|
||||||
|
bool isClosing() const pure nothrow @safe @nogc
|
||||||
|
{
|
||||||
|
return closing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the transport.
|
||||||
|
*
|
||||||
|
* Buffered data will be flushed. No more data will be received.
|
||||||
|
*/
|
||||||
|
void close() @nogc
|
||||||
|
{
|
||||||
|
closing = true;
|
||||||
|
loop.reify(this, EventMask(Event.read, Event.write), EventMask(Event.write));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the watcher callback.
|
* Invokes the watcher callback.
|
||||||
*/
|
*/
|
||||||
@ -124,6 +145,10 @@ package class StreamTransport : SocketWatcher, DuplexTransport, SocketTransport
|
|||||||
{
|
{
|
||||||
protocol.received(output[0 .. $]);
|
protocol.received(output[0 .. $]);
|
||||||
output.clear();
|
output.clear();
|
||||||
|
if (isClosing() && input.length == 0)
|
||||||
|
{
|
||||||
|
loop.kill(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,6 +306,10 @@ abstract class SelectorLoop : Loop
|
|||||||
kill(transport, exception);
|
kill(transport, exception);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (transport.input.length == 0 && transport.isClosing())
|
||||||
|
{
|
||||||
|
kill(transport);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,19 @@ interface DuplexTransport : ReadTransport, WriteTransport
|
|||||||
{
|
{
|
||||||
assert(protocol !is null);
|
assert(protocol !is null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns $(D_PARAM true) if the transport is closing or closed.
|
||||||
|
*/
|
||||||
|
bool isClosing() const pure nothrow @safe @nogc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the transport.
|
||||||
|
*
|
||||||
|
* Buffered data will be flushed. No more data will be received.
|
||||||
|
*/
|
||||||
|
void close() @nogc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user