Last active
August 16, 2017 19:10
-
-
Save tanner0101/b078a1580f540f6999c21eb90d43b3e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public protocol Stream: class { | |
var isClosed: Bool { get } | |
func close() throws | |
func setTimeout(_ timeout: Double) throws | |
} | |
public protocol ReadableStream: Stream { | |
func read(max: Int, into buffer: inout Data) throws -> Int | |
} | |
public protocol WriteableStream: Stream { | |
func write(max: Int, from buffer: Data) throws -> Int | |
} | |
public typealias DuplexStream = ReadableStream & WriteableStream | |
// MARK: Program | |
public protocol InternetStream { | |
var scheme: String { get } | |
var hostname: String { get } | |
var port: Port { get } | |
} | |
public protocol ClientStream: InternetStream, DuplexStream { | |
func connect() throws | |
} | |
public protocol ServerStream: InternetStream { | |
associatedtype Client: DuplexStream | |
func bind() throws | |
func listen(max: Int) throws | |
func accept() throws -> Client | |
} | |
public typealias ProgramStream = ClientStream & ServerStream |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment