FastCGIServer
public class FastCGIServer : Server
A server that listens for incoming HTTP requests that are sent using the FastCGI protocol. This can be used to create a new FastCGIServer and have it listen for conenctions and handle a new client FastCGI request.
Usage Example:
//Create a `FastCGI` server on a specified port.
let server = try FastCGIServer.listen(on: port, delegate: delegate)
-
Declaration
Swift
public typealias ServerType = FastCGIServer -
Declaration
Swift
public var delegate: ServerDelegate? -
Port number for listening for new connections
Usage Example:
self.port = portDeclaration
Swift
public private(set) var port: Int? { get } -
The address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
Declaration
Swift
public private(set) var address: String? { get } -
A server state.
Usage Example:
self.state = .startedDeclaration
Swift
public private(set) var state: ServerState { get } -
Whether or not this server allows port reuse (default: disallowed)
Usage Example:
server.allowPortReuse = allowPortReuseDeclaration
Swift
public var allowPortReuse: Bool -
Creates a FastCGI server instance.
Declaration
Swift
public init() -
Listens for connections on a socket
Usage Example:
try server.listen(on: port, address: "localhost")Declaration
Swift
public func listen(on port: Int, address: String? = nil) throwsParameters
onport number for new connections
addressThe address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.
-
Static method to create a new
FastCGIServerand have it listen for conenctionsUsage Example:
let server = try FastCGIServer.listen(on: port, address: "localhost", delegate: delegate)Declaration
Swift
public static func listen(on port: Int, address: String? = nil, delegate: ServerDelegate?) throws -> FastCGIServerParameters
onport number for accepting new connections
addressThe address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.
delegatethe delegate handler for FastCGI/HTTP connections
Return Value
a new
FastCGIServerinstance -
Listens for connections on a socket
Usage Example:
server.listen(port: port, errorHandler: errorHandler)Declaration
Swift
@available(*, deprecated, message: "use 'listen(on:﹚ throws' with 'server.failed(callback:﹚' instead") public func listen(port: Int, errorHandler: ((Swift.Error) -> Void)? = nil)Parameters
portport number for new connections (ex. 9000)
errorHandleroptional callback for error handling
-
Static method to create a new
FastCGIServerand have it listen for conenctionsUsage Example:
let server = FastCGIServer.listen(port: port, delegate: delegate, errorHandler: errorHandler)Declaration
Swift
@available(*, deprecated, message: "use 'listen(on:delegate:﹚ throws' with 'server.failed(callback:﹚' instead") public static func listen(port: Int, delegate: ServerDelegate, errorHandler: ((Swift.Error) -> Void)? = nil) -> FastCGIServerParameters
portport number for accepting new connections
delegatethe delegate handler for FastCGI/HTTP connections
errorHandleroptional callback for error handling
Return Value
a new
FastCGIServerinstance -
Stop listening for new connections.
Usage Example:
server.stop()Declaration
Swift
public func stop() -
Add a new listener for server being started
Usage Example:
server.started(request: request, response: response)Declaration
Swift
@discardableResult public func started(callback: @escaping () -> Void) -> SelfParameters
callbackThe listener callback that will run on server successfull start-up
Return Value
a
FastCGIServerinstance -
Add a new listener for server being stopped
Usage Example:
server.stopped(request: request, response: response)Declaration
Swift
@discardableResult public func stopped(callback: @escaping () -> Void) -> SelfParameters
callbackThe listener callback that will run when server stops
Return Value
a
FastCGIServerinstance -
Add a new listener for server throwing an error
Usage Example:
server.failed(request: request, response: response)Declaration
Swift
@discardableResult public func failed(callback: @escaping (Swift.Error) -> Void) -> SelfParameters
callbackThe listener callback that will run when server throws an error
Return Value
a
FastCGIServerinstance -
Add a new listener for when listenSocket.acceptClientConnection throws an error
Usage Example:
server.clientConnectionFailed() { error in ... }Declaration
Swift
@discardableResult public func clientConnectionFailed(callback: @escaping (Swift.Error) -> Void) -> SelfParameters
callbackThe listener callback that will run
Return Value
a Server instance
View on GitHub
FastCGIServer Class Reference