Skip to content

Instantly share code, notes, and snippets.

@tanner0101
Last active August 16, 2017 19:10
Show Gist options
  • Save tanner0101/b078a1580f540f6999c21eb90d43b3e4 to your computer and use it in GitHub Desktop.
Save tanner0101/b078a1580f540f6999c21eb90d43b3e4 to your computer and use it in GitHub Desktop.
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