Skip to content

Commit

Permalink
Updated for Net 2.1. Wait a second for each initial launch to catch s…
Browse files Browse the repository at this point in the history
…tartup errors
  • Loading branch information
kjessup committed Dec 4, 2016
1 parent df41175 commit be4f958
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Sources/PerfectHTTPServer/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class HTTPServer {
public func start() throws {
if let (cert, key) = ssl {
let socket = NetTCPSSL()
socket.initSocket()
try socket.bind(port: serverPort, address: serverAddress)
socket.cipherList = self.cipherList

if let verifyMode = certVerifyMode,
Expand Down Expand Up @@ -181,7 +181,7 @@ public class HTTPServer {
Log.info(message: "Starting HTTPS server \(serverName) on \(serverAddress):\(serverPort)")
} else {
self.net = NetTCP()
self.net?.initSocket()
try self.net?.bind(port: serverPort, address: serverAddress)
Log.info(message: "Starting HTTP server \(serverName) on \(serverAddress):\(serverPort)")
}
try self.startInner()
Expand All @@ -197,7 +197,6 @@ public class HTTPServer {
guard let sock = self.net else {
Log.terminal(message: "Server could not be started. Socket was not initialized.")
}
try sock.bind(port: serverPort, address: serverAddress)
if let runAs = self.runAsUser {
try PerfectServer.switchTo(userName: runAs)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/PerfectHTTPServer/HTTPServerEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public extension HTTPServer {
let ctx = servers.map { LaunchContext($0) }
try ctx.forEach { try $0.launchServer() }
if wait {
try ctx.forEach { try $0.wait(seconds: 1.0) }
try ctx.forEach { try $0.wait() }
}
return ctx
Expand All @@ -255,6 +256,7 @@ public extension HTTPServer {
let lc = LaunchContext(.server(name: name, port: port, routes: routes, runAs: runAs, requestFilters: requestFilters, responseFilters: responseFilters))
try lc.launchServer()
if wait {
try lc.wait(seconds: 1.0)
try lc.wait()
}
return lc
Expand All @@ -274,6 +276,7 @@ public extension HTTPServer {
let lc = LaunchContext(.server(name: name, port: port, documentRoot: root, runAs: runAs, requestFilters: requestFilters, responseFilters: responseFilters))
try lc.launchServer()
if wait {
try lc.wait(seconds: 1.0)
try lc.wait()
}
return lc
Expand Down

0 comments on commit be4f958

Please sign in to comment.