0001    #if os(Linux)
0002    import Glibc
0003    #else
0004    import Darwin
0005    #endif
0006    
0007    import Nest
0008    import Commander
0009    import Inquiline
0010    
0011    
0012    extension Address : ArgumentConvertible {
0013      init(parser: ArgumentParser) throws {
0014        if let value = parser.shift() {
0015          let components = value.characters.split(":").map(String.init)
0016          if components.count != 2 {
0017            throw ArgumentError.InvalidType(value: value, type: "hostname and port separated by `:`.", argument: nil)
0018          }
0019    
0020          if let port = UInt16(components[1]) {
0021            self = .IP(hostname: components[0], port: port)
0022          } else {
0023            throw ArgumentError.InvalidType(value: components[1], type: "number", argument: "port")
0024          }
0025        } else {
0026          throw ArgumentError.MissingValue(argument: nil)
0027        }
0028      }
0029    }
0030    
0031    
0032    @noreturn public func serve(closure: RequestType -> ResponseType) {
0033      command(
0034        Option("workers", 1, description: "The number of processes for handling requests."),
0035        Option("bind", Address.IP(hostname: "0.0.0.0", port: 8000), description: "The address to bind sockets."),
0036        Option("timeout", 30, description: "Amount of seconds to wait on a worker without activity before killing and restarting the worker.")
0037      ) { workers, address, timeout in
0038        let arbiter = Arbiter<SyncronousWorker>(application: closure, workers: workers, addresses: [address], timeout: timeout)
0039        try arbiter.run()
0040      }.run()
0041    }
0042