Tcp.swift 687 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // OS.swift
  3. // Swifter
  4. //
  5. // Copyright © 2016 Damian Kołakowski. All rights reserved.
  6. //
  7. import Foundation
  8. public protocol TcpServer: class {
  9. init(_ port: in_port_t, forceIPv4: Bool, bindAddress: String?) throws
  10. func wait(_ callback: ((TcpServerEvent) -> Void)) throws
  11. func write(_ socket: Int32, _ data: Array<UInt8>, _ done: @escaping ((Void) -> TcpWriteDoneAction)) throws
  12. func finish(_ socket: Int32)
  13. }
  14. public enum TcpWriteDoneAction {
  15. case `continue`, terminate
  16. }
  17. public enum TcpServerEvent {
  18. case connect(String, Int32)
  19. case disconnect(String, Int32)
  20. case data(String, Int32, ArraySlice<UInt8>)
  21. }