Implement protocol property for IOCPTransport

This commit is contained in:
Eugen Wissner 2017-02-08 21:21:12 +01:00
parent 48a49c2a2d
commit 63c6226a2a
3 changed files with 51 additions and 7 deletions

View File

@ -30,30 +30,70 @@ class IOCPStreamTransport : StreamTransport
{
private OverlappedConnectedSocket socket_;
private Protocol protocol_;
private WriteBuffer!ubyte input;
/**
* Creates new completion port transport.
*
* Params:
* socket = Socket.
* socket = Socket.
* protocol = Application protocol.
*
* Precondition: $(D_INLINECODE socket !is null && protocol !is null)
*/
this(OverlappedConnectedSocket socket) @nogc
this(OverlappedConnectedSocket socket, Protocol protocol) @nogc
in
{
assert(socket !is null);
assert(protocol !is null);
}
body
{
socket_ = socket;
protocol_ = protocol;
input = WriteBuffer!ubyte(8192, MmapPool.instance);
}
@property inout(OverlappedConnectedSocket) socket()
inout pure nothrow @safe @nogc
/**
* Returns: Socket.
*/
@property OverlappedConnectedSocket socket() pure nothrow @safe @nogc
{
return socket_;
}
/**
* Returns: Application protocol.
*/
@property Protocol protocol() pure nothrow @safe @nogc
{
return protocol_;
}
/**
* Switches the protocol.
*
* The protocol is deallocated by the event loop, it should currently be
* allocated with $(D_PSYMBOL MmapPool).
*
* Params:
* protocol = Application protocol.
*
* Precondition: $(D_INLINECODE protocol !is null)
*/
@property void protocol(Protocol protocol) pure nothrow @safe @nogc
in
{
assert(protocol !is null);
}
body
{
protocol_ = protocol;
}
/**
* Write some data to the transport.
*
@ -215,8 +255,9 @@ class IOCPLoop : Loop
assert(listener !is null);
auto socket = listener.endAccept(overlapped);
auto transport = MmapPool.instance.make!IOCPStreamTransport(socket);
auto io = MmapPool.instance.make!IOWatcher(transport, connection.protocol);
auto protocol = connection.protocol;
auto transport = MmapPool.instance.make!IOCPStreamTransport(socket, protocol);
auto io = MmapPool.instance.make!IOWatcher(transport, protocol);
connection.incoming.enqueue(io);

View File

@ -65,7 +65,7 @@ class SelectorStreamTransport : StreamTransport
}
/**
* Returns: Transport socket.
* Returns: Socket.
*/
ConnectedSocket socket() pure nothrow @safe @nogc
{

View File

@ -80,6 +80,9 @@ interface DuplexTransport : ReadTransport, WriteTransport
*/
interface SocketTransport : Transport
{
/**
* Returns: Socket.
*/
@property Socket socket() pure nothrow @safe @nogc;
}