summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-02-08 21:21:12 +0100
committerEugen Wissner <belka@caraus.de>2017-02-08 21:21:12 +0100
commit63c6226a2ae758d68429667a07ec723d09007c4e (patch)
tree6f0b9f41b042eebb24356c70888e176ba74eefbb
parent48a49c2a2d8b246b75fb9e2114f65a3d51f96239 (diff)
downloadtanya-63c6226a2ae758d68429667a07ec723d09007c4e.tar.gz
Implement protocol property for IOCPTransport
-rw-r--r--source/tanya/async/event/iocp.d53
-rw-r--r--source/tanya/async/event/selector.d2
-rw-r--r--source/tanya/async/transport.d3
3 files changed, 51 insertions, 7 deletions
diff --git a/source/tanya/async/event/iocp.d b/source/tanya/async/event/iocp.d
index ff2b4c4..08d60ac 100644
--- a/source/tanya/async/event/iocp.d
+++ b/source/tanya/async/event/iocp.d
@@ -30,31 +30,71 @@ 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.
*
* Params:
@@ -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);
diff --git a/source/tanya/async/event/selector.d b/source/tanya/async/event/selector.d
index 0b2143f..76b0530 100644
--- a/source/tanya/async/event/selector.d
+++ b/source/tanya/async/event/selector.d
@@ -65,7 +65,7 @@ class SelectorStreamTransport : StreamTransport
}
/**
- * Returns: Transport socket.
+ * Returns: Socket.
*/
ConnectedSocket socket() pure nothrow @safe @nogc
{
diff --git a/source/tanya/async/transport.d b/source/tanya/async/transport.d
index 6e4460c..b06bec7 100644
--- a/source/tanya/async/transport.d
+++ b/source/tanya/async/transport.d
@@ -80,6 +80,9 @@ interface DuplexTransport : ReadTransport, WriteTransport
*/
interface SocketTransport : Transport
{
+ /**
+ * Returns: Socket.
+ */
@property Socket socket() pure nothrow @safe @nogc;
}