-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
128 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public protocol AsyncConnection: AsyncStream { | ||
func open(timingOut deadline: Double, completion: ((Void) throws -> AsyncConnection) -> Void) throws | ||
func open(deadline: Double, completion: ((Void) throws -> AsyncConnection) -> Void) throws | ||
} | ||
|
||
extension AsyncConnection { | ||
public func open(completion: ((Void) throws -> AsyncConnection) -> Void) throws { | ||
try open(timingOut: .never, completion: completion) | ||
try open(deadline: .never, completion: completion) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public protocol AsyncHost { | ||
func accept(timingOut deadline: Double, completion: ((Void) throws -> AsyncStream) -> Void) | ||
func accept(deadline: Double, completion: ((Void) throws -> AsyncStream) -> Void) | ||
} | ||
|
||
extension AsyncHost { | ||
public func accept(completion: ((Void) throws -> AsyncStream) -> Void) { | ||
accept(timingOut: .never, completion: completion) | ||
accept(deadline: .never, completion: completion) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
public protocol AsyncSending { | ||
func send(_ data: Data, timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) | ||
func flush(timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) | ||
public protocol AsyncWritable { | ||
func write(_ data: Data, deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) | ||
func flush(deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) | ||
} | ||
|
||
public protocol AsyncReceiving { | ||
func receive(upTo byteCount: Int, timingOut deadline: Double, completion: ((Void) throws -> Data) -> Void) | ||
} | ||
|
||
public protocol AsyncSendingStream: Closable, AsyncSending {} | ||
public protocol AsyncReceivingStream: Closable, AsyncReceiving {} | ||
public protocol AsyncStream: AsyncSendingStream, AsyncReceivingStream {} | ||
extension AsyncWritable { | ||
public func write(_ data: Data, completion: @escaping ((Void) throws -> Void) -> Void) { | ||
write(data, deadline: .never, completion: completion) | ||
} | ||
|
||
extension AsyncSending { | ||
public func send(_ data: Data, completion: ((Void) throws -> Void) -> Void) { | ||
send(data, timingOut: .never, completion: completion) | ||
public func write(_ convertible: DataConvertible, deadline: Double = .never, completion: @escaping ((Void) throws -> Void) -> Void) { | ||
write(convertible.data, deadline: deadline, completion: completion) | ||
} | ||
public func flush(completion: ((Void) throws -> Void) -> Void) { | ||
flush(timingOut: .never, completion: completion) | ||
|
||
public func flush(completion: @escaping ((Void) throws -> Void) -> Void) { | ||
flush(deadline: .never, completion: completion) | ||
} | ||
} | ||
|
||
extension AsyncReceiving { | ||
public func receive(upTo byteCount: Int, completion: ((Void) throws -> Data) -> Void) { | ||
receive(upTo: byteCount, timingOut: .never, completion: completion) | ||
public protocol AsyncReadable { | ||
func read(upTo byteCount: Int, deadline: Double, completion: @escaping ((Void) throws -> Data) -> Void) | ||
} | ||
|
||
extension AsyncReadable { | ||
public func read(upTo byteCount: Int, completion: @escaping ((Void) throws -> Data) -> Void) { | ||
read(upTo: byteCount, deadline: .never, completion: completion) | ||
} | ||
} | ||
|
||
public protocol AsyncOutputStream: Closable, AsyncWritable {} | ||
public protocol AsyncInputStream: Closable, AsyncReadable {} | ||
public protocol AsyncStream: AsyncOutputStream, AsyncInputStream {} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public protocol Connection: Stream { | ||
func open(timingOut deadline: Double) throws | ||
func open(deadline: Double) throws | ||
} | ||
|
||
extension Connection { | ||
public func open() throws { | ||
try open(timingOut: .never) | ||
try open(deadline: .never) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public enum FileMode { | ||
case read | ||
case createWrite | ||
case truncateWrite | ||
case appendWrite | ||
case readWrite | ||
case createReadWrite | ||
case truncateReadWrite | ||
case appendReadWrite | ||
} | ||
|
||
public protocol File : Stream { | ||
init(path: String, mode: FileMode) throws | ||
var fileExtension: String? { get } | ||
static func changeWorkingDirectory(path: String) throws | ||
|
||
func read(_ byteCount: Int, deadline: Double) throws -> Data | ||
func readAll(deadline: Double) throws -> Data | ||
} | ||
|
||
extension File { | ||
public func read(_ byteCount: Int) throws -> Data { | ||
return try read(byteCount, deadline: .never) | ||
} | ||
|
||
public func readAll() throws -> Data { | ||
return try readAll(deadline: .never) | ||
} | ||
} | ||
|
||
extension File { | ||
public init(path: String) throws { | ||
try self.init(path: path, mode: .read) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public protocol Host { | ||
func accept(timingOut deadline: Double) throws -> Stream | ||
func accept(deadline: Double) throws -> Stream | ||
} | ||
|
||
extension Host { | ||
func accept() throws -> Stream { | ||
return try accept(timingOut: .never) | ||
public func accept() throws -> Stream { | ||
return try accept(deadline: .never) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,57 @@ | ||
public protocol Sending: AsyncSending { | ||
func send(_ data: Data, timingOut deadline: Double) throws | ||
func flush(timingOut deadline: Double) throws | ||
public protocol Closable { | ||
var closed: Bool { get } | ||
func close() throws | ||
} | ||
|
||
public protocol Receiving: AsyncReceiving { | ||
func receive(upTo byteCount: Int, timingOut deadline: Double) throws -> Data | ||
public enum ClosableError: Error { | ||
case alreadyClosed | ||
} | ||
|
||
public protocol SendingStream: Closable, Sending {} | ||
public protocol ReceivingStream: Closable, Receiving {} | ||
public protocol Stream: SendingStream, ReceivingStream {} | ||
public protocol Writable: AsyncWritable { | ||
func write(_ data: Data, deadline: Double) throws | ||
func flush(deadline: Double) throws | ||
} | ||
|
||
extension Sending { | ||
public func send(_ data: Data, timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) { | ||
completion { try self.send(data, timingOut: deadline) } | ||
extension Writable { | ||
public func write(_ data: Data) throws { | ||
try write(data, deadline: .never) | ||
} | ||
|
||
public func flush(timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) { | ||
completion { try self.flush(timingOut: deadline) } | ||
public func write(_ convertible: DataConvertible, deadline: Double = .never) throws { | ||
try write(convertible.data, deadline: deadline) | ||
} | ||
|
||
public func flush() throws { | ||
try flush(deadline: .never) | ||
} | ||
} | ||
|
||
extension Sending { | ||
public func send(_ data: Data) throws { | ||
try send(data, timingOut: .never) | ||
extension Writable { | ||
public func write(_ data: Data, deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) { | ||
completion { try self.write(data, deadline: deadline) } | ||
} | ||
public func flush() throws { | ||
try flush(timingOut: .never) | ||
|
||
public func flush(deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) { | ||
completion { try self.flush(deadline: deadline) } | ||
} | ||
} | ||
|
||
extension Receiving { | ||
public func receive(upTo byteCount: Int, timingOut deadline: Double, completion: ((Void) throws -> Data) -> Void) { | ||
completion { try self.receive(upTo: byteCount, timingOut: deadline) } | ||
public protocol Readable: AsyncReadable { | ||
func read(upTo byteCount: Int, deadline: Double) throws -> Data | ||
} | ||
|
||
extension Readable { | ||
public func read(upTo byteCount: Int) throws -> Data { | ||
return try read(upTo: byteCount, deadline: .never) | ||
} | ||
} | ||
|
||
extension Receiving { | ||
public func receive(upTo byteCount: Int) throws -> Data { | ||
return try receive(upTo: byteCount, timingOut: .never) | ||
extension Readable { | ||
public func read(upTo byteCount: Int, deadline: Double, completion: @escaping ((Void) throws -> Data) -> Void) { | ||
completion { try self.read(upTo: byteCount, deadline: deadline) } | ||
} | ||
} | ||
} | ||
|
||
public protocol OutputStream: Closable, Writable, AsyncOutputStream {} | ||
public protocol InputStream: Closable, Readable, AsyncInputStream {} | ||
public protocol Stream: OutputStream, InputStream, AsyncStream {} |
Oops, something went wrong.