1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /** 6 * This module contains transports which are responsible for data dilvery 7 * between two parties of an asynchronous communication. 8 * 9 * Copyright: Eugene Wissner 2016-2020. 10 * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, 11 * Mozilla Public License, v. 2.0). 12 * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) 13 * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/async/transport.d, 14 * tanya/async/transport.d) 15 */ 16 module tanya.async.transport; 17 18 import tanya.async.protocol; 19 import tanya.net.socket; 20 21 /** 22 * Base transport interface. 23 */ 24 interface Transport 25 { 26 } 27 28 /** 29 * Interface for read-only transports. 30 */ 31 interface ReadTransport : Transport 32 { 33 } 34 35 /** 36 * Interface for write-only transports. 37 */ 38 interface WriteTransport : Transport 39 { 40 /** 41 * Write some data to the transport. 42 * 43 * Params: 44 * data = Data to send. 45 */ 46 void write(ubyte[] data) @nogc; 47 } 48 49 /** 50 * Represents a bidirectional transport. 51 */ 52 interface DuplexTransport : ReadTransport, WriteTransport 53 { 54 /** 55 * Returns: Application protocol. 56 * 57 * Postcondition: $(D_INLINECODE protocol !is null) 58 */ 59 @property Protocol protocol() pure nothrow @safe @nogc 60 out (protocol) 61 { 62 assert(protocol !is null); 63 } 64 65 /** 66 * Switches the protocol. 67 * 68 * The protocol is deallocated by the event loop. 69 * 70 * Params: 71 * protocol = Application protocol. 72 * 73 * Precondition: $(D_INLINECODE protocol !is null) 74 */ 75 @property void protocol(Protocol protocol) pure nothrow @safe @nogc 76 in 77 { 78 assert(protocol !is null); 79 } 80 81 82 /** 83 * Returns $(D_PARAM true) if the transport is closing or closed. 84 */ 85 bool isClosing() const pure nothrow @safe @nogc; 86 87 /** 88 * Close the transport. 89 * 90 * Buffered data will be flushed. No more data will be received. 91 */ 92 void close() @nogc; 93 } 94 95 /** 96 * Represents a socket transport. 97 */ 98 interface SocketTransport : Transport 99 { 100 /** 101 * Returns: Socket. 102 */ 103 @property Socket socket() pure nothrow @safe @nogc; 104 }