diff --git a/Sources/Hummingbird/Configuration.swift b/Sources/Hummingbird/Configuration.swift index 420b48709..7aac3e85d 100644 --- a/Sources/Hummingbird/Configuration.swift +++ b/Sources/Hummingbird/Configuration.swift @@ -32,9 +32,9 @@ public struct ApplicationConfiguration: Sendable { /// Defines the maximum length for the queue of pending connections public var backlog: Int /// This will affect how many connections the server accepts at any one time - public let serverMaxMessagesPerRead: UInt + public var serverMaxMessagesPerRead: UInt? /// This will affect how much is read from a connection at any one time - public let childMaxMessagesPerRead: UInt + public var childMaxMessagesPerRead: UInt? /// Allows socket to be bound to an address that is already in use. public var reuseAddress: Bool #if canImport(Network) @@ -52,15 +52,16 @@ public struct ApplicationConfiguration: Sendable { /// - backlog: the maximum length for the queue of pending connections. If a connection request arrives with the queue full, /// the client may receive an error with an indication of ECONNREFUSE /// - serverMaxMessagesPerRead: This will affect how many connections the server accepts before waiting for notification of - /// more. Setting this too high can flood the server with too much work. - /// - childMaxMessagesPerRead: This will affect how much is read from a connection before waiting for notification of more - /// - reuseAddress: Allows socket to be bound to an address that is already in use. + /// more. Setting this too high can flood the server with too much work. DO NOT EDIT this unless you know what you are doing + /// - childMaxMessagesPerRead: This will affect how much is read from a connection before waiting for notification of more. DO + /// NOT EDIT this unless you know what you are doing + /// - reuseAddress: Allows socket to be bound to an address that is already in use. public init( address: Address = .hostname(), serverName: String? = nil, backlog: Int = 256, - serverMaxMessagesPerRead: UInt = 8, - childMaxMessagesPerRead: UInt = 1, + serverMaxMessagesPerRead: UInt? = nil, + childMaxMessagesPerRead: UInt? = nil, reuseAddress: Bool = true ) { self.address = address @@ -94,8 +95,8 @@ public struct ApplicationConfiguration: Sendable { self.tlsOptions = tlsOptions // The following are not used by Network framework self.backlog = 256 - self.serverMaxMessagesPerRead = 8 - self.childMaxMessagesPerRead = 1 + self.serverMaxMessagesPerRead = nil + self.childMaxMessagesPerRead = nil } #endif diff --git a/Sources/HummingbirdCore/Server/Server.swift b/Sources/HummingbirdCore/Server/Server.swift index 77899b70e..83228b362 100644 --- a/Sources/HummingbirdCore/Server/Server.swift +++ b/Sources/HummingbirdCore/Server/Server.swift @@ -239,14 +239,19 @@ public actor Server: Service { private nonisolated func createSocketsBootstrap( configuration: ServerConfiguration ) -> ServerBootstrap { - return ServerBootstrap(group: self.eventLoopGroup) + var bootstrap = ServerBootstrap(group: self.eventLoopGroup) // Specify backlog and enable SO_REUSEADDR for the server itself .serverChannelOption(ChannelOptions.backlog, value: numericCast(configuration.backlog)) .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: configuration.reuseAddress ? 1 : 0) - .serverChannelOption(ChannelOptions.maxMessagesPerRead, value: configuration.serverMaxMessagesPerRead) .childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: configuration.reuseAddress ? 1 : 0) - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: configuration.childMaxMessagesPerRead) .childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + if let serverMaxMessagesPerRead = configuration.serverMaxMessagesPerRead { + bootstrap = bootstrap.serverChannelOption(ChannelOptions.maxMessagesPerRead, value: serverMaxMessagesPerRead) + } + if let childMaxMessagesPerRead = configuration.childMaxMessagesPerRead { + bootstrap = bootstrap.serverChannelOption(ChannelOptions.maxMessagesPerRead, value: childMaxMessagesPerRead) + } + return bootstrap } #if canImport(Network) diff --git a/Sources/HummingbirdCore/Server/ServerConfiguration.swift b/Sources/HummingbirdCore/Server/ServerConfiguration.swift index fa3769e85..da026857f 100644 --- a/Sources/HummingbirdCore/Server/ServerConfiguration.swift +++ b/Sources/HummingbirdCore/Server/ServerConfiguration.swift @@ -17,20 +17,20 @@ import NIOCore /// HTTP server configuration public struct ServerConfiguration: Sendable { /// Bind address for server - public let address: Address + public var address: Address /// Server name to return in "server" header - public let serverName: String? + public var serverName: String? /// Defines the maximum length for the queue of pending connections - public let backlog: Int + public var backlog: Int /// This will affect how many connections the server accepts at any one time - public let serverMaxMessagesPerRead: UInt + public var serverMaxMessagesPerRead: UInt? /// This will affect how much is read from a connection at any one time - public let childMaxMessagesPerRead: UInt + public var childMaxMessagesPerRead: UInt? /// Allows socket to be bound to an address that is already in use. - public let reuseAddress: Bool + public var reuseAddress: Bool #if canImport(Network) /// TLS options for NIO Transport services - public let tlsOptions: TSTLSOptions + public var tlsOptions: TSTLSOptions #endif /// Initialize server configuration @@ -40,15 +40,16 @@ public struct ServerConfiguration: Sendable { /// - backlog: the maximum length for the queue of pending connections. If a connection request arrives with the queue full, /// the client may receive an error with an indication of ECONNREFUSE /// - serverMaxMessagesPerRead: This will affect how many connections the server accepts before waiting for notification of - /// more. Setting this too high can flood the server with too much work. - /// - childMaxMessagesPerRead: This will affect how much is read from a connection before waiting for notification of more - /// - reuseAddress: Allows socket to be bound to an address that is already in use. + /// more. Setting this too high can flood the server with too much work. DO NOT EDIT this unless you know what you are doing + /// - childMaxMessagesPerRead: This will affect how much is read from a connection before waiting for notification of more. DO NOT + /// EDIT this unless you know what you are doing + /// - reuseAddress: Allows socket to be bound to an address that is already in use. public init( address: Address = .hostname(), serverName: String? = nil, backlog: Int = 256, - serverMaxMessagesPerRead: UInt = 8, - childMaxMessagesPerRead: UInt = 1, + serverMaxMessagesPerRead: UInt? = nil, + childMaxMessagesPerRead: UInt? = nil, reuseAddress: Bool = true ) { self.address = address @@ -81,8 +82,8 @@ public struct ServerConfiguration: Sendable { self.tlsOptions = tlsOptions // The following are unsupported by transport services self.backlog = 256 - self.serverMaxMessagesPerRead = 8 - self.childMaxMessagesPerRead = 1 + self.serverMaxMessagesPerRead = nil + self.childMaxMessagesPerRead = nil } #endif }