From bad48b319abbc078dbdb397c5c52a699ff174577 Mon Sep 17 00:00:00 2001 From: Ayush Garg Date: Mon, 29 Jul 2024 11:31:20 +0100 Subject: [PATCH 1/3] ChannelOption: Allow types to be accessed with leading dot syntax --- Sources/NIOCore/ChannelOption.swift | 91 +++++++++++++++++++++++++++++ Sources/NIOPosix/VsockAddress.swift | 4 ++ 2 files changed, 95 insertions(+) diff --git a/Sources/NIOCore/ChannelOption.swift b/Sources/NIOCore/ChannelOption.swift index a4e0746a04..a6e6ebc1cf 100644 --- a/Sources/NIOCore/ChannelOption.swift +++ b/Sources/NIOCore/ChannelOption.swift @@ -360,6 +360,97 @@ public struct ChannelOptions: Sendable { public static let receivePacketInfo = Types.ReceivePacketInfo() } +/// - seealso: `SocketOption`. +extension ChannelOption where Self == ChannelOptions.Types.SocketOption { + #if !(os(Windows)) + public static func socket(_ level: SocketOptionLevel, _ name: SocketOptionName) -> Self { + .init(level: NIOBSDSocket.OptionLevel(rawValue: CInt(level)), name: NIOBSDSocket.Option(rawValue: CInt(name))) + } + #endif + + public static func socketOption(_ name: NIOBSDSocket.Option) -> Self { + .init(level: .socket, name: name) + } + + public static func ipOption(_ name: NIOBSDSocket.Option) -> Self { + .init(level: .ip, name: name) + } + + public static func tcpOption(_ name: NIOBSDSocket.Option) -> Self { + .init(level: .tcp, name: name) + } +} + +/// - seealso: `AllocatorOption`. +extension ChannelOption where Self == ChannelOptions.Types.AllocatorOption { + public static var allocator: Self {.init()} +} + +/// - seealso: `RecvAllocatorOption`. +extension ChannelOption where Self == ChannelOptions.Types.RecvAllocatorOption { + public static var recvAllocator: Self {.init()} +} + +/// - seealso: `AutoReadOption`. +extension ChannelOption where Self == ChannelOptions.Types.AutoReadOption { + public static var autoRead: Self {.init()} +} + +/// - seealso: `MaxMessagesPerReadOption`. +extension ChannelOption where Self == ChannelOptions.Types.MaxMessagesPerReadOption { + public static var maxMessagesPerRead: Self {.init()} +} + +/// - seealso: `BacklogOption`. +extension ChannelOption where Self == ChannelOptions.Types.BacklogOption { + public static var backlog: Self {.init()} +} + +/// - seealso: `WriteSpinOption`. +extension ChannelOption where Self == ChannelOptions.Types.WriteSpinOption { + public static var writeSpin: Self {.init()} +} + +/// - seealso: `WriteBufferWaterMarkOption`. +extension ChannelOption where Self == ChannelOptions.Types.WriteBufferWaterMarkOption { + public static var writeBufferWaterMark: Self {.init()} +} + +/// - seealso: `ConnectTimeoutOption`. +extension ChannelOption where Self == ChannelOptions.Types.ConnectTimeoutOption { + public static var connectTimeout: Self {.init()} +} + +/// - seealso: `AllowRemoteHalfClosureOption`. +extension ChannelOption where Self == ChannelOptions.Types.AllowRemoteHalfClosureOption { + public static var allowRemoteHalfClosure: Self {.init()} +} + +/// - seealso: `DatagramVectorReadMessageCountOption`. +extension ChannelOption where Self == ChannelOptions.Types.DatagramVectorReadMessageCountOption { + public static var datagramVectorReadMessageCount: Self {.init()} +} + +/// - seealso: `DatagramSegmentSize`. +extension ChannelOption where Self == ChannelOptions.Types.DatagramSegmentSize { + public static var datagramSegmentSize: Self {.init()} +} + +/// - seealso: `DatagramReceiveOffload`. +extension ChannelOption where Self == ChannelOptions.Types.DatagramReceiveOffload { + public static var datagramReceiveOffload: Self {.init()} +} + +/// - seealso: `ExplicitCongestionNotificationsOption`. +extension ChannelOption where Self == ChannelOptions.Types.ExplicitCongestionNotificationsOption { + public static var explicitCongestionNotification: Self {.init()} +} + +/// - seealso: `ReceivePacketInfo`. +extension ChannelOption where Self == ChannelOptions.Types.ReceivePacketInfo { + public static var receivePacketInfo: Self {.init()} +} + extension ChannelOptions { /// A type-safe storage facility for `ChannelOption`s. You will only ever need this if you implement your own /// `Channel` that needs to store `ChannelOption`s. diff --git a/Sources/NIOPosix/VsockAddress.swift b/Sources/NIOPosix/VsockAddress.swift index d4197e2dc6..0df25cf483 100644 --- a/Sources/NIOPosix/VsockAddress.swift +++ b/Sources/NIOPosix/VsockAddress.swift @@ -156,6 +156,10 @@ extension ChannelOptions { public static let localVsockContextID = Types.LocalVsockContextID() } +extension ChannelOption where Self == ChannelOptions.Types.LocalVsockContextID { + public static var localVsockContextID: Self {.init()} +} + extension ChannelOptions.Types { /// This get-only option is used on channels backed by vsock sockets to get the local VSOCK context ID. public struct LocalVsockContextID: ChannelOption, Sendable { From ab0960a681248001d6ab441540c809e6d4fa9112 Mon Sep 17 00:00:00 2001 From: Ayush Garg Date: Mon, 29 Jul 2024 11:31:29 +0100 Subject: [PATCH 2/3] Update code and tests to use dot syntac for ChannelOption --- .../test_01_resources/shared.swift | 2 +- .../test_1000_autoReadGetAndSet.swift | 4 +- .../test_1000_autoReadGetAndSet_sync.swift | 4 +- .../test_1000_tcpconnections.swift | 2 +- .../test_1000_udp_reqs.swift | 4 +- .../test_ping_pong_1000_reqs_1_conn.swift | 6 +- Sources/NIOChatClient/main.swift | 2 +- Sources/NIOChatServer/main.swift | 10 +- .../NIOCore/ConvenienceOptionSupport.swift | 6 +- Sources/NIOCrashTester/OutputGrepper.swift | 2 +- Sources/NIOEchoClient/main.swift | 2 +- Sources/NIOEchoServer/main.swift | 10 +- Sources/NIOHTTP1Client/main.swift | 2 +- Sources/NIOHTTP1Server/main.swift | 14 +-- Sources/NIOMulticastChat/main.swift | 2 +- .../NIOPerformanceTester/UDPBenchmark.swift | 4 +- Sources/NIOPerformanceTester/main.swift | 2 +- Sources/NIOPosix/BaseSocketChannel.swift | 2 +- Sources/NIOPosix/Bootstrap.swift | 18 ++-- Sources/NIOTCPEchoServer/Server.swift | 2 +- Sources/NIOTestUtils/NIOHTTP1TestServer.swift | 4 +- Sources/NIOUDPEchoClient/main.swift | 2 +- Sources/NIOUDPEchoServer/main.swift | 6 +- Sources/NIOWebSocketServer/Server.swift | 2 +- .../ChannelOptionStorageTest.swift | 32 +++--- .../AsyncTestingChannelTests.swift | 12 +-- .../EmbeddedChannelTest.swift | 10 +- .../NIOHTTP1Tests/HTTPServerClientTest.swift | 14 +-- .../HTTPServerUpgradeTests.swift | 4 +- .../AcceptBackoffHandlerTest.swift | 2 +- .../AsyncChannelBootstrapTests.swift | 14 +-- Tests/NIOPosixTests/BootstrapTest.swift | 44 ++++---- .../ChannelNotificationTest.swift | 8 +- Tests/NIOPosixTests/ChannelTests.swift | 80 +++++++------- .../NIOPosixTests/DatagramChannelTests.swift | 102 +++++++++--------- .../NIOPosixTests/EchoServerClientTest.swift | 36 +++---- Tests/NIOPosixTests/EventLoopTest.swift | 10 +- Tests/NIOPosixTests/FileRegionTest.swift | 6 +- .../NIOPosixTests/IdleStateHandlerTest.swift | 2 +- Tests/NIOPosixTests/MulticastTest.swift | 20 ++-- Tests/NIOPosixTests/PipeChannelTest.swift | 2 +- .../RawSocketBootstrapTests.swift | 2 +- Tests/NIOPosixTests/SALChannelTests.swift | 26 ++--- Tests/NIOPosixTests/SelectorTest.swift | 4 +- Tests/NIOPosixTests/SocketChannelTest.swift | 26 ++--- Tests/NIOPosixTests/StreamChannelsTest.swift | 46 ++++---- Tests/NIOPosixTests/TestUtils.swift | 2 +- .../UniversalBootstrapSupportTest.swift | 2 +- Tests/NIOPosixTests/VsockAddressTest.swift | 2 +- .../NIOHTTP1TestServerTest.swift | 2 +- 50 files changed, 312 insertions(+), 312 deletions(-) diff --git a/IntegrationTests/tests_04_performance/test_01_resources/shared.swift b/IntegrationTests/tests_04_performance/test_01_resources/shared.swift index 8f540d8651..6677fdc016 100644 --- a/IntegrationTests/tests_04_performance/test_01_resources/shared.swift +++ b/IntegrationTests/tests_04_performance/test_01_resources/shared.swift @@ -109,7 +109,7 @@ private final class SimpleHTTPServer: ChannelInboundHandler { func doRequests(group: EventLoopGroup, number numberOfRequests: Int) throws -> Int { let serverChannel = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.configureHTTPServerPipeline( withPipeliningAssistance: true, diff --git a/IntegrationTests/tests_04_performance/test_01_resources/test_1000_autoReadGetAndSet.swift b/IntegrationTests/tests_04_performance/test_01_resources/test_1000_autoReadGetAndSet.swift index 8f143e1a87..c74ce7d969 100644 --- a/IntegrationTests/tests_04_performance/test_01_resources/test_1000_autoReadGetAndSet.swift +++ b/IntegrationTests/tests_04_performance/test_01_resources/test_1000_autoReadGetAndSet.swift @@ -32,8 +32,8 @@ func run(identifier: String) { let iterations = 1000 for _ in 0.. Int { let serverChannel = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4)) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4)) .childChannelInitializer { channel in channel.pipeline.addHandler(ByteToMessageHandler(PongDecoder())).flatMap { channel.pipeline.addHandler(PongHandler()) @@ -137,7 +137,7 @@ func doPingPongRequests(group: EventLoopGroup, number numberOfRequests: Int) thr .channelInitializer { channel in channel.pipeline.addHandler(pingHandler) } - .channelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4)) + .channelOption(.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4)) .connect(to: serverChannel.localAddress!) .wait() diff --git a/Sources/NIOChatClient/main.swift b/Sources/NIOChatClient/main.swift index 399d671088..c41250e39d 100644 --- a/Sources/NIOChatClient/main.swift +++ b/Sources/NIOChatClient/main.swift @@ -45,7 +45,7 @@ private final class ChatHandler: ChannelInboundHandler { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) let bootstrap = ClientBootstrap(group: group) // Enable SO_REUSEADDR. - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler(ChatHandler()) } diff --git a/Sources/NIOChatServer/main.swift b/Sources/NIOChatServer/main.swift index df9f6e9655..791634f1d7 100644 --- a/Sources/NIOChatServer/main.swift +++ b/Sources/NIOChatServer/main.swift @@ -130,8 +130,8 @@ let chatHandler = ChatHandler() let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) let bootstrap = ServerBootstrap(group: group) // Specify backlog and enable SO_REUSEADDR for the server itself - .serverChannelOption(ChannelOptions.backlog, value: 256) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.backlog, value: 256) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are applied to the accepted Channels .childChannelInitializer { channel in @@ -143,9 +143,9 @@ let bootstrap = ServerBootstrap(group: group) } // Enable SO_REUSEADDR for the accepted Channels - .childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 16) - .childChannelOption(ChannelOptions.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) + .childChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.maxMessagesPerRead, value: 16) + .childChannelOption(.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) defer { try! group.syncShutdownGracefully() } diff --git a/Sources/NIOCore/ConvenienceOptionSupport.swift b/Sources/NIOCore/ConvenienceOptionSupport.swift index 0ef1c61519..69a5439b80 100644 --- a/Sources/NIOCore/ConvenienceOptionSupport.swift +++ b/Sources/NIOCore/ConvenienceOptionSupport.swift @@ -176,13 +176,13 @@ extension ChannelOptions { mutating func applyFallbackMapping(_ universalBootstrap: NIOClientTCPBootstrap) -> NIOClientTCPBootstrap { var result = universalBootstrap if self.consumeAllowLocalEndpointReuse().isSet { - result = result.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + result = result.channelOption(.socketOption(.so_reuseaddr), value: 1) } if self.consumeAllowRemoteHalfClosure().isSet { - result = result.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + result = result.channelOption(.allowRemoteHalfClosure, value: true) } if self.consumeDisableAutoRead().isSet { - result = result.channelOption(ChannelOptions.autoRead, value: false) + result = result.channelOption(.autoRead, value: false) } return result } diff --git a/Sources/NIOCrashTester/OutputGrepper.swift b/Sources/NIOCrashTester/OutputGrepper.swift index 7802fe83b9..069f182fae 100644 --- a/Sources/NIOCrashTester/OutputGrepper.swift +++ b/Sources/NIOCrashTester/OutputGrepper.swift @@ -29,7 +29,7 @@ internal struct OutputGrepper { // We gotta `dup` everything because Pipe is bad and closes file descriptors on `deinit` :( let channelFuture = NIOPipeBootstrap(group: group) - .channelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + .channelOption(.allowRemoteHalfClosure, value: true) .channelInitializer { channel in channel.eventLoop.makeCompletedFuture { try channel.pipeline.syncOperations.addHandlers([ diff --git a/Sources/NIOEchoClient/main.swift b/Sources/NIOEchoClient/main.swift index 5e846a1cba..d7de8eb35b 100644 --- a/Sources/NIOEchoClient/main.swift +++ b/Sources/NIOEchoClient/main.swift @@ -56,7 +56,7 @@ private final class EchoHandler: ChannelInboundHandler { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) let bootstrap = ClientBootstrap(group: group) // Enable SO_REUSEADDR. - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler(EchoHandler()) } diff --git a/Sources/NIOEchoServer/main.swift b/Sources/NIOEchoServer/main.swift index 111ca580f3..eed04e44c5 100644 --- a/Sources/NIOEchoServer/main.swift +++ b/Sources/NIOEchoServer/main.swift @@ -40,8 +40,8 @@ private final class EchoHandler: ChannelInboundHandler { let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) let bootstrap = ServerBootstrap(group: group) // Specify backlog and enable SO_REUSEADDR for the server itself - .serverChannelOption(ChannelOptions.backlog, value: 256) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.backlog, value: 256) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -53,9 +53,9 @@ let bootstrap = ServerBootstrap(group: group) } // Enable SO_REUSEADDR for the accepted Channels - .childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 16) - .childChannelOption(ChannelOptions.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) + .childChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.maxMessagesPerRead, value: 16) + .childChannelOption(.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) defer { try! group.syncShutdownGracefully() } diff --git a/Sources/NIOHTTP1Client/main.swift b/Sources/NIOHTTP1Client/main.swift index 4afd26600b..31a058bbe5 100644 --- a/Sources/NIOHTTP1Client/main.swift +++ b/Sources/NIOHTTP1Client/main.swift @@ -79,7 +79,7 @@ private final class HTTPEchoHandler: ChannelInboundHandler { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) let bootstrap = ClientBootstrap(group: group) // Enable SO_REUSEADDR. - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHTTPClientHandlers( position: .first, diff --git a/Sources/NIOHTTP1Server/main.swift b/Sources/NIOHTTP1Server/main.swift index 728512fac8..9683a40943 100644 --- a/Sources/NIOHTTP1Server/main.swift +++ b/Sources/NIOHTTP1Server/main.swift @@ -604,22 +604,22 @@ func childChannelInitializer(channel: Channel) -> EventLoopFuture { let fileIO = NonBlockingFileIO(threadPool: .singleton) let socketBootstrap = ServerBootstrap(group: MultiThreadedEventLoopGroup.singleton) // Specify backlog and enable SO_REUSEADDR for the server itself - .serverChannelOption(ChannelOptions.backlog, value: 256) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.backlog, value: 256) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are applied to the accepted Channels .childChannelInitializer(childChannelInitializer(channel:)) // Enable SO_REUSEADDR for the accepted Channels - .childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) - .childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: allowHalfClosure) + .childChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.maxMessagesPerRead, value: 1) + .childChannelOption(.allowRemoteHalfClosure, value: allowHalfClosure) let pipeBootstrap = NIOPipeBootstrap(group: MultiThreadedEventLoopGroup.singleton) // Set the handlers that are applied to the accepted Channels .channelInitializer(childChannelInitializer(channel:)) - .channelOption(ChannelOptions.maxMessagesPerRead, value: 1) - .channelOption(ChannelOptions.allowRemoteHalfClosure, value: allowHalfClosure) + .channelOption(.maxMessagesPerRead, value: 1) + .channelOption(.allowRemoteHalfClosure, value: allowHalfClosure) print("htdocs = \(htdocs)") let channel = try { () -> Channel in diff --git a/Sources/NIOMulticastChat/main.swift b/Sources/NIOMulticastChat/main.swift index 60818b0f3f..94beddc8fd 100644 --- a/Sources/NIOMulticastChat/main.swift +++ b/Sources/NIOMulticastChat/main.swift @@ -69,7 +69,7 @@ let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) // Begin by setting up the basics of the bootstrap. var datagramBootstrap = DatagramBootstrap(group: group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler(ChatMessageEncoder()).flatMap { channel.pipeline.addHandler(ChatMessageDecoder()) diff --git a/Sources/NIOPerformanceTester/UDPBenchmark.swift b/Sources/NIOPerformanceTester/UDPBenchmark.swift index 090b261bb8..a6463e8d29 100644 --- a/Sources/NIOPerformanceTester/UDPBenchmark.swift +++ b/Sources/NIOPerformanceTester/UDPBenchmark.swift @@ -45,7 +45,7 @@ extension UDPBenchmark: Benchmark { let address = try SocketAddress.makeAddressResolvingHost("127.0.0.1", port: 0) self.server = try DatagramBootstrap(group: group) // zero is the same as not applying the option. - .channelOption(ChannelOptions.datagramVectorReadMessageCount, value: self.vectorReads) + .channelOption(.datagramVectorReadMessageCount, value: self.vectorReads) .channelInitializer { channel in channel.pipeline.addHandler(EchoHandler()) } @@ -56,7 +56,7 @@ extension UDPBenchmark: Benchmark { self.client = try DatagramBootstrap(group: group) // zero is the same as not applying the option. - .channelOption(ChannelOptions.datagramVectorReadMessageCount, value: self.vectorReads) + .channelOption(.datagramVectorReadMessageCount, value: self.vectorReads) .channelInitializer { channel in let handler = EchoHandlerClient( eventLoop: channel.eventLoop, diff --git a/Sources/NIOPerformanceTester/main.swift b/Sources/NIOPerformanceTester/main.swift index 3b40b7a15c..644246073b 100644 --- a/Sources/NIOPerformanceTester/main.swift +++ b/Sources/NIOPerformanceTester/main.swift @@ -160,7 +160,7 @@ defer { } let serverChannel = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: true).flatMap { channel.pipeline.addHandler(SimpleHTTPServer()) diff --git a/Sources/NIOPosix/BaseSocketChannel.swift b/Sources/NIOPosix/BaseSocketChannel.swift index 98cd75a57d..3af11f72fc 100644 --- a/Sources/NIOPosix/BaseSocketChannel.swift +++ b/Sources/NIOPosix/BaseSocketChannel.swift @@ -1140,7 +1140,7 @@ class BaseSocketChannel: SelectableChannel, Chan // // getOption0 can only fail if the channel is not active anymore but we assert further up that it is. If // that's not the case this is a precondition failure and we would like to know. - let allowRemoteHalfClosure = try! self.getOption0(ChannelOptions.allowRemoteHalfClosure) + let allowRemoteHalfClosure = try! self.getOption0(.allowRemoteHalfClosure) // For EOF, we always fire read complete. self.pipeline.syncOperations.fireChannelReadComplete() diff --git a/Sources/NIOPosix/Bootstrap.swift b/Sources/NIOPosix/Bootstrap.swift index 6deaae1e1c..2438435ac0 100644 --- a/Sources/NIOPosix/Bootstrap.swift +++ b/Sources/NIOPosix/Bootstrap.swift @@ -46,8 +46,8 @@ internal enum NIOOnSocketsBootstraps { /// } /// let bootstrap = ServerBootstrap(group: group) /// // Specify backlog and enable SO_REUSEADDR for the server itself -/// .serverChannelOption(ChannelOptions.backlog, value: 256) -/// .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) +/// .serverChannelOption(.backlog, value: 256) +/// .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) /// /// // Set the handlers that are applied to the accepted child `Channel`s. /// .childChannelInitializer { channel in @@ -60,9 +60,9 @@ internal enum NIOOnSocketsBootstraps { /// } /// /// // Enable SO_REUSEADDR for the accepted Channels -/// .childChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) -/// .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 16) -/// .childChannelOption(ChannelOptions.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) +/// .childChannelOption(.socketOption(.so_reuseaddr), value: 1) +/// .childChannelOption(.maxMessagesPerRead, value: 16) +/// .childChannelOption(.recvAllocator, value: AdaptiveRecvByteBufferAllocator()) /// let channel = try! bootstrap.bind(host: host, port: port).wait() /// /* the server will now be accepting connections */ /// @@ -150,7 +150,7 @@ public final class ServerBootstrap { self._childChannelOptions = ChannelOptions.Storage() self.serverChannelInit = nil self.childChannelInit = nil - self._serverChannelOptions.append(key: ChannelOptions.tcpOption(.tcp_nodelay), value: 1) + self._serverChannelOptions.append(key: .tcpOption(.tcp_nodelay), value: 1) self.enableMPTCP = false } @@ -240,7 +240,7 @@ public final class ServerBootstrap { // This is a temporary workaround until we get some stable Linux kernel // versions that support TCP_NODELAY and MPTCP. if value { - self._serverChannelOptions.remove(key: ChannelOptions.tcpOption(.tcp_nodelay)) + self._serverChannelOptions.remove(key: .tcpOption(.tcp_nodelay)) } return self @@ -839,7 +839,7 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { } self.group = group self._channelOptions = ChannelOptions.Storage() - self._channelOptions.append(key: ChannelOptions.tcpOption(.tcp_nodelay), value: 1) + self._channelOptions.append(key: .tcpOption(.tcp_nodelay), value: 1) self._channelInitializer = { channel in channel.eventLoop.makeSucceededFuture(()) } self.protocolHandlers = nil self.resolver = nil @@ -930,7 +930,7 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { // This is a temporary workaround until we get some stable Linux kernel // versions that support TCP_NODELAY and MPTCP. if value { - self._channelOptions.remove(key: ChannelOptions.tcpOption(.tcp_nodelay)) + self._channelOptions.remove(key: .tcpOption(.tcp_nodelay)) } return self diff --git a/Sources/NIOTCPEchoServer/Server.swift b/Sources/NIOTCPEchoServer/Server.swift index 451d687b89..c8f2200410 100644 --- a/Sources/NIOTCPEchoServer/Server.swift +++ b/Sources/NIOTCPEchoServer/Server.swift @@ -38,7 +38,7 @@ struct Server { /// This method starts the server and handles incoming connections. func run() async throws { let channel = try await ServerBootstrap(group: self.eventLoopGroup) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind( host: self.host, port: self.port diff --git a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift index b4326f5c58..acac209039 100644 --- a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift +++ b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift @@ -226,7 +226,7 @@ public final class NIOHTTP1TestServer { }.flatMap { channel.pipeline.addHandler(WebServerHandler(webServer: self)) }.whenSuccess { - _ = channel.setOption(ChannelOptions.autoRead, value: true) + _ = channel.setOption(.autoRead, value: true) } } @@ -239,7 +239,7 @@ public final class NIOHTTP1TestServer { self.aggregateBody = aggregateBody self.serverChannel = try! ServerBootstrap(group: self.eventLoop) - .childChannelOption(ChannelOptions.autoRead, value: false) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { channel in switch self.state { case .channelsAvailable(var channels): diff --git a/Sources/NIOUDPEchoClient/main.swift b/Sources/NIOUDPEchoClient/main.swift index f0348b7cd6..3a74de9d04 100644 --- a/Sources/NIOUDPEchoClient/main.swift +++ b/Sources/NIOUDPEchoClient/main.swift @@ -127,7 +127,7 @@ let remoteAddress = { () -> SocketAddress in let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) let bootstrap = DatagramBootstrap(group: group) // Enable SO_REUSEADDR. - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler(EchoHandler(remoteAddressInitializer: remoteAddress)) } diff --git a/Sources/NIOUDPEchoServer/main.swift b/Sources/NIOUDPEchoServer/main.swift index bc942740ce..a33de6780b 100644 --- a/Sources/NIOUDPEchoServer/main.swift +++ b/Sources/NIOUDPEchoServer/main.swift @@ -43,7 +43,7 @@ private final class EchoHandler: ChannelInboundHandler { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) var bootstrap = DatagramBootstrap(group: group) // Specify backlog and enable SO_REUSEADDR - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are applied to the bound channel .channelInitializer { channel in @@ -57,9 +57,9 @@ defer { var arguments = CommandLine.arguments.dropFirst(0) // just to get an ArraySlice from [String] if arguments.dropFirst().first == .some("--enable-gathering-reads") { - bootstrap = bootstrap.channelOption(ChannelOptions.datagramVectorReadMessageCount, value: 30) + bootstrap = bootstrap.channelOption(.datagramVectorReadMessageCount, value: 30) bootstrap = bootstrap.channelOption( - ChannelOptions.recvAllocator, + .recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 30 * 2048) ) arguments = arguments.dropFirst() diff --git a/Sources/NIOWebSocketServer/Server.swift b/Sources/NIOWebSocketServer/Server.swift index 6a9252b0e9..7f3c8fdbcc 100644 --- a/Sources/NIOWebSocketServer/Server.swift +++ b/Sources/NIOWebSocketServer/Server.swift @@ -73,7 +73,7 @@ struct Server { let channel: NIOAsyncChannel, Never> = try await ServerBootstrap( group: self.eventLoopGroup ) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind( host: self.host, port: self.port diff --git a/Tests/NIOCoreTests/ChannelOptionStorageTest.swift b/Tests/NIOCoreTests/ChannelOptionStorageTest.swift index 638beb76e5..be568e696c 100644 --- a/Tests/NIOCoreTests/ChannelOptionStorageTest.swift +++ b/Tests/NIOCoreTests/ChannelOptionStorageTest.swift @@ -27,16 +27,16 @@ class ChannelOptionStorageTest: XCTestCase { func testSetTwoOptionsOfDifferentType() throws { var cos = ChannelOptions.Storage() let optionsCollector = OptionsCollectingChannel() - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 1) - cos.append(key: ChannelOptions.backlog, value: 2) + cos.append(key: .socketOption(.so_reuseaddr), value: 1) + cos.append(key: .backlog, value: 2) XCTAssertNoThrow(try cos.applyAllChannelOptions(to: optionsCollector).wait()) XCTAssertEqual(2, optionsCollector.allOptions.count) } func testSetTwoOptionsOfSameType() throws { let options: [(ChannelOptions.Types.SocketOption, SocketOptionValue)] = [ - (ChannelOptions.socketOption(.so_reuseaddr), 1), - (ChannelOptions.socketOption(.so_rcvtimeo), 2), + (.socketOption(.so_reuseaddr), 1), + (.socketOption(.so_rcvtimeo), 2), ] var cos = ChannelOptions.Storage() let optionsCollector = OptionsCollectingChannel() @@ -62,12 +62,12 @@ class ChannelOptionStorageTest: XCTestCase { func testSetOneOptionTwice() throws { var cos = ChannelOptions.Storage() let optionsCollector = OptionsCollectingChannel() - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 1) - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 2) + cos.append(key: .socketOption(.so_reuseaddr), value: 1) + cos.append(key: .socketOption(.so_reuseaddr), value: 2) XCTAssertNoThrow(try cos.applyAllChannelOptions(to: optionsCollector).wait()) XCTAssertEqual(1, optionsCollector.allOptions.count) XCTAssertEqual( - [ChannelOptions.socketOption(.so_reuseaddr)], + [.socketOption(.so_reuseaddr)], optionsCollector.allOptions.map { option in option.0 as! ChannelOptions.Types.SocketOption } @@ -83,19 +83,19 @@ class ChannelOptionStorageTest: XCTestCase { func testClearingOptions() throws { var cos = ChannelOptions.Storage() let optionsCollector = OptionsCollectingChannel() - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 1) - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 2) - cos.append(key: ChannelOptions.socketOption(.so_keepalive), value: 3) - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 4) - cos.append(key: ChannelOptions.socketOption(.so_rcvbuf), value: 5) - cos.append(key: ChannelOptions.socketOption(.so_reuseaddr), value: 6) - cos.remove(key: ChannelOptions.socketOption(.so_reuseaddr)) + cos.append(key: .socketOption(.so_reuseaddr), value: 1) + cos.append(key: .socketOption(.so_reuseaddr), value: 2) + cos.append(key: .socketOption(.so_keepalive), value: 3) + cos.append(key: .socketOption(.so_reuseaddr), value: 4) + cos.append(key: .socketOption(.so_rcvbuf), value: 5) + cos.append(key: .socketOption(.so_reuseaddr), value: 6) + cos.remove(key: .socketOption(.so_reuseaddr)) XCTAssertNoThrow(try cos.applyAllChannelOptions(to: optionsCollector).wait()) XCTAssertEqual(2, optionsCollector.allOptions.count) XCTAssertEqual( [ - ChannelOptions.socketOption(.so_keepalive), - ChannelOptions.socketOption(.so_rcvbuf), + .socketOption(.so_keepalive), + .socketOption(.so_rcvbuf), ], optionsCollector.allOptions.map { option in option.0 as! ChannelOptions.Types.SocketOption diff --git a/Tests/NIOEmbeddedTests/AsyncTestingChannelTests.swift b/Tests/NIOEmbeddedTests/AsyncTestingChannelTests.swift index 8e0ada12ba..92690716ca 100644 --- a/Tests/NIOEmbeddedTests/AsyncTestingChannelTests.swift +++ b/Tests/NIOEmbeddedTests/AsyncTestingChannelTests.swift @@ -514,7 +514,7 @@ class AsyncTestingChannelTests: XCTestCase { let options = channel.syncOptions XCTAssertNotNil(options) // Unconditionally returns true. - XCTAssertEqual(try options?.getOption(ChannelOptions.autoRead), true) + XCTAssertEqual(try options?.getOption(.autoRead), true) // (Setting options isn't supported.) }.wait() } @@ -525,7 +525,7 @@ class AsyncTestingChannelTests: XCTestCase { let options = channel.syncOptions XCTAssertNotNil(options) // Unconditionally returns true. - XCTAssertEqual(try options?.getOption(ChannelOptions.autoRead), true) + XCTAssertEqual(try options?.getOption(.autoRead), true) }.wait() } @@ -536,13 +536,13 @@ class AsyncTestingChannelTests: XCTestCase { XCTAssertNotNil(options) // allowRemoteHalfClosure should be false by default - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), false) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), false) channel.allowRemoteHalfClosure = true - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), true) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), true) - XCTAssertNoThrow(try options?.setOption(ChannelOptions.allowRemoteHalfClosure, value: false)) - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), false) + XCTAssertNoThrow(try options?.setOption(.allowRemoteHalfClosure, value: false)) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), false) }.wait() } diff --git a/Tests/NIOEmbeddedTests/EmbeddedChannelTest.swift b/Tests/NIOEmbeddedTests/EmbeddedChannelTest.swift index b4adc09b68..62490ae2a5 100644 --- a/Tests/NIOEmbeddedTests/EmbeddedChannelTest.swift +++ b/Tests/NIOEmbeddedTests/EmbeddedChannelTest.swift @@ -516,7 +516,7 @@ class EmbeddedChannelTest: XCTestCase { let options = channel.syncOptions XCTAssertNotNil(options) // Unconditionally returns true. - XCTAssertEqual(try options?.getOption(ChannelOptions.autoRead), true) + XCTAssertEqual(try options?.getOption(.autoRead), true) } func testSetGetChannelOptionAllowRemoteHalfClosureIsSupported() { @@ -525,13 +525,13 @@ class EmbeddedChannelTest: XCTestCase { XCTAssertNotNil(options) // allowRemoteHalfClosure should be false by default - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), false) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), false) channel.allowRemoteHalfClosure = true - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), true) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), true) - XCTAssertNoThrow(try options?.setOption(ChannelOptions.allowRemoteHalfClosure, value: false)) - XCTAssertEqual(try options?.getOption(ChannelOptions.allowRemoteHalfClosure), false) + XCTAssertNoThrow(try options?.setOption(.allowRemoteHalfClosure, value: false)) + XCTAssertEqual(try options?.getOption(.allowRemoteHalfClosure), false) } func testLocalAddress0() throws { diff --git a/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift b/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift index 94ab77a4b2..59ff595102 100644 --- a/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift @@ -371,7 +371,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(mode) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -432,7 +432,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(mode) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -491,7 +491,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(.byteBuffer) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -553,7 +553,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(mode) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap { channel.pipeline.addHandler(httpHandler) @@ -613,7 +613,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(mode) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -659,7 +659,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(.byteBuffer) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap { channel.pipeline.addHandler(httpHandler) @@ -707,7 +707,7 @@ class HTTPServerClientTest: XCTestCase { let httpHandler = SimpleHTTPServer(.byteBuffer) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap { channel.pipeline.addHandler(httpHandler) diff --git a/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift b/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift index 343b6b9138..b928d4a595 100644 --- a/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift @@ -120,7 +120,7 @@ private func serverHTTPChannelWithAutoremoval( ) throws -> (Channel, EventLoopFuture) { let p = group.next().makePromise(of: Channel.self) let c = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in p.succeed(channel) let upgradeConfig = (upgraders: upgraders, completionHandler: upgradeCompletionHandler) @@ -1774,7 +1774,7 @@ final class TypedHTTPServerUpgradeTestCase: HTTPServerUpgradeTestCase { ) throws -> (Channel, Channel, Channel) { let connectionChannelPromise = Self.eventLoop.makePromise(of: Channel.self) let serverChannelFuture = ServerBootstrap(group: Self.eventLoop) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.eventLoop.makeCompletedFuture { connectionChannelPromise.succeed(channel) diff --git a/Tests/NIOPosixTests/AcceptBackoffHandlerTest.swift b/Tests/NIOPosixTests/AcceptBackoffHandlerTest.swift index 162cb454ba..b3b88a4f1c 100644 --- a/Tests/NIOPosixTests/AcceptBackoffHandlerTest.swift +++ b/Tests/NIOPosixTests/AcceptBackoffHandlerTest.swift @@ -328,7 +328,7 @@ public final class AcceptBackoffHandlerTest: XCTestCase { ) ) - XCTAssertNoThrow(try serverChannel.setOption(ChannelOptions.autoRead, value: false).wait()) + XCTAssertNoThrow(try serverChannel.setOption(.autoRead, value: false).wait()) XCTAssertNoThrow( try serverChannel.pipeline.addHandler(readCountHandler).flatMap { _ in serverChannel.pipeline.addHandler( diff --git a/Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift b/Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift index b1fc060feb..c425de8d81 100644 --- a/Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift +++ b/Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift @@ -220,8 +220,8 @@ final class AsyncChannelBootstrapTests: XCTestCase { } let channel = try await ServerBootstrap(group: eventLoopGroup) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: true) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: true) .bind( host: "127.0.0.1", port: 0 @@ -281,8 +281,8 @@ final class AsyncChannelBootstrapTests: XCTestCase { let channel: NIOAsyncChannel, Never> = try await ServerBootstrap( group: eventLoopGroup ) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: true) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: true) .bind( host: "127.0.0.1", port: 0 @@ -367,7 +367,7 @@ final class AsyncChannelBootstrapTests: XCTestCase { let channel: NIOAsyncChannel>, Never> = try await ServerBootstrap(group: eventLoopGroup) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind( host: "127.0.0.1", port: 0 @@ -506,13 +506,13 @@ final class AsyncChannelBootstrapTests: XCTestCase { let channel: NIOAsyncChannel, Never> = try await ServerBootstrap( group: eventLoopGroup ) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .serverChannelInitializer { channel in channel.eventLoop.makeCompletedFuture { try channel.pipeline.syncOperations.addHandler(CollectingHandler(channels: channels)) } } - .childChannelOption(ChannelOptions.autoRead, value: true) + .childChannelOption(.autoRead, value: true) .bind( host: "127.0.0.1", port: 0 diff --git a/Tests/NIOPosixTests/BootstrapTest.swift b/Tests/NIOPosixTests/BootstrapTest.swift index 250db702cd..a6120ca94f 100644 --- a/Tests/NIOPosixTests/BootstrapTest.swift +++ b/Tests/NIOPosixTests/BootstrapTest.swift @@ -255,7 +255,7 @@ class BootstrapTest: XCTestCase { let serverAcceptedChannelPromise = group.next().makePromise(of: Channel.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in serverAcceptedChannelPromise.succeed(channel) return channel.eventLoop.makeSucceededFuture(()) @@ -313,9 +313,9 @@ class BootstrapTest: XCTestCase { var channel: Channel? = nil XCTAssertNoThrow( channel = try ServerBootstrap(group: self.group) - .serverChannelOption(ChannelOptions.autoRead, value: false) + .serverChannelOption(.autoRead, value: false) .serverChannelInitializer { channel in - channel.getOption(ChannelOptions.autoRead).whenComplete { result in + channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } @@ -336,9 +336,9 @@ class BootstrapTest: XCTestCase { var channel: Channel? = nil XCTAssertNoThrow( channel = try ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in - channel.getOption(ChannelOptions.autoRead).whenComplete { result in + channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } @@ -371,9 +371,9 @@ class BootstrapTest: XCTestCase { var channel: Channel? = nil XCTAssertNoThrow( channel = try ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in - channel.getOption(ChannelOptions.autoRead).whenComplete { result in + channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } @@ -394,9 +394,9 @@ class BootstrapTest: XCTestCase { var channel: Channel? = nil XCTAssertNoThrow( channel = try DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in - channel.getOption(ChannelOptions.autoRead).whenComplete { result in + channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } @@ -425,9 +425,9 @@ class BootstrapTest: XCTestCase { var channel: Channel? = nil XCTAssertNoThrow( channel = try NIOPipeBootstrap(group: self.group) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in - channel.getOption(ChannelOptions.autoRead).whenComplete { result in + channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } @@ -671,17 +671,17 @@ class BootstrapTest: XCTestCase { } try checkOptionEquivalence( - longOption: ChannelOptions.socketOption(.so_reuseaddr), + longOption: .socketOption(.so_reuseaddr), setValue: 1, shortOption: .allowLocalEndpointReuse ) try checkOptionEquivalence( - longOption: ChannelOptions.allowRemoteHalfClosure, + longOption: .allowRemoteHalfClosure, setValue: true, shortOption: .allowRemoteHalfClosure ) try checkOptionEquivalence( - longOption: ChannelOptions.autoRead, + longOption: .autoRead, setValue: false, shortOption: .disableAutoRead ) @@ -697,14 +697,14 @@ class BootstrapTest: XCTestCase { let clientLocalAddressWholeInterface = try? SocketAddress(ipAddress: localIP, port: 0), let server1 = (try? ServerBootstrap(group: self.group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .serverChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.maxMessagesPerRead, value: 1) .bind(to: serverLocalAddressChoice) .wait()), let server2 = (try? ServerBootstrap(group: self.group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .serverChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.maxMessagesPerRead, value: 1) .bind(to: serverLocalAddressChoice) .wait()), let server1LocalAddress = server1.localAddress, @@ -721,7 +721,7 @@ class BootstrapTest: XCTestCase { // Try 1: Directly connect to 127.0.0.1, this won't do Happy Eyeballs. XCTAssertNoThrow( try ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(to: clientLocalAddressWholeInterface) .connect(to: server1LocalAddress) .wait() @@ -744,7 +744,7 @@ class BootstrapTest: XCTestCase { XCTAssertNoThrow( maybeChannel1 = try ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(to: clientLocalAddressWholeInterface) .connect(host: localhost, port: server1LocalAddress.port!) .wait() @@ -757,7 +757,7 @@ class BootstrapTest: XCTestCase { // Try 3: Bind the client to the same address/port as in try 2 but to server 2. XCTAssertNoThrow( try ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .connectTimeout(.hours(2)) .bind(to: myChannel1Address) .connect(to: server2LocalAddress) @@ -822,7 +822,7 @@ private final class MakeSureAutoReadIsOffInChannelInitializer: ChannelInboundHan typealias InboundIn = Channel func channelActive(context: ChannelHandlerContext) { - context.channel.getOption(ChannelOptions.autoRead).whenComplete { result in + context.channel.getOption(.autoRead).whenComplete { result in func workaround() { XCTAssertNoThrow(XCTAssertFalse(try result.get())) } diff --git a/Tests/NIOPosixTests/ChannelNotificationTest.swift b/Tests/NIOPosixTests/ChannelNotificationTest.swift index b39470fe20..cf0b963d5d 100644 --- a/Tests/NIOPosixTests/ChannelNotificationTest.swift +++ b/Tests/NIOPosixTests/ChannelNotificationTest.swift @@ -406,11 +406,11 @@ class ChannelNotificationTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .serverChannelInitializer { channel in channel.pipeline.addHandler(ServerSocketChannelLifecycleVerificationHandler()) } - .childChannelOption(ChannelOptions.autoRead, value: false) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { channel in channel.pipeline.addHandler( AcceptedSocketChannelLifecycleVerificationHandler(acceptedChannelPromise) @@ -496,8 +496,8 @@ class ChannelNotificationTest: XCTestCase { let promise = group.next().makePromise(of: Void.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: true) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: true) .childChannelInitializer { channel in channel.pipeline.addHandler(OrderVerificationHandler(promise)) } diff --git a/Tests/NIOPosixTests/ChannelTests.swift b/Tests/NIOPosixTests/ChannelTests.swift index 8b86e834a4..71cc18cb3e 100644 --- a/Tests/NIOPosixTests/ChannelTests.swift +++ b/Tests/NIOPosixTests/ChannelTests.swift @@ -84,7 +84,7 @@ public final class ChannelTests: XCTestCase { let serverLifecycleHandler = ChannelLifecycleHandler() let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in serverAcceptedChannelPromise.succeed(channel) return channel.pipeline.addHandler(serverLifecycleHandler) @@ -138,7 +138,7 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -171,7 +171,7 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -208,7 +208,7 @@ public final class ChannelTests: XCTestCase { let childChannelPromise = group.next().makePromise(of: Channel.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in childChannelPromise.succeed(channel) return channel.eventLoop.makeSucceededFuture(()) @@ -1269,7 +1269,7 @@ public final class ChannelTests: XCTestCase { do { // This must throw as 198.51.100.254 is reserved for documentation only _ = try ClientBootstrap(group: group) - .channelOption(ChannelOptions.connectTimeout, value: .milliseconds(10)) + .channelOption(.connectTimeout, value: .milliseconds(10)) .connect(to: SocketAddress.makeAddressResolvingHost("198.51.100.254", port: 65535)).wait() XCTFail() } catch let err as ChannelError { @@ -1403,7 +1403,7 @@ public final class ChannelTests: XCTestCase { channel.pipeline.addHandler(verificationHandler) } } - .channelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + .channelOption(.allowRemoteHalfClosure, value: true) .connect(to: try! server.localAddress()) let accepted = try server.accept()! defer { @@ -1460,7 +1460,7 @@ public final class ChannelTests: XCTestCase { .channelInitializer { channel in channel.pipeline.addHandler(verificationHandler) } - .channelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + .channelOption(.allowRemoteHalfClosure, value: true) .connect(to: try! server.localAddress()) let accepted = try server.accept()! defer { @@ -1519,7 +1519,7 @@ public final class ChannelTests: XCTestCase { let serverChildChannelInitPromise: EventLoopPromise = group.next().makePromise() let serverChildChannelInactivePromise: EventLoopPromise = group.next().makePromise() let serverChannel: Channel = try ServerBootstrap(group: group) - .childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true) // Important! + .childChannelOption(.allowRemoteHalfClosure, value: true) // Important! .childChannelInitializer { channel in channel.pipeline.addHandlers( PromiseOnChildChannelInitHandler(promise: serverChildChannelInitPromise), @@ -1540,7 +1540,7 @@ public final class ChannelTests: XCTestCase { .connect(to: serverChannel.localAddress!) .wait() - XCTAssertNoThrow(try clientChannel.setOption(ChannelOptions.allowRemoteHalfClosure, value: true).wait()) + XCTAssertNoThrow(try clientChannel.setOption(.allowRemoteHalfClosure, value: true).wait()) // Ok, the connection is definitely up. // Now retrieve the client channel that our server opened for the connection to our client. @@ -1665,7 +1665,7 @@ public final class ChannelTests: XCTestCase { let serverChildChannelPromise = group.next().makePromise(of: Channel.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in serverChildChannelPromise.succeed(channel) channel.close(promise: nil) @@ -1731,7 +1731,7 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -1779,7 +1779,7 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { ch in ch.pipeline.addHandler(AddressVerificationHandler()) } @@ -1847,7 +1847,7 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { $0.pipeline.addHandler(readDelayer) } @@ -1909,8 +1909,8 @@ public final class ChannelTests: XCTestCase { let handler = VerifyNoReadBeforeEOFHandler() let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: false) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { ch in ch.pipeline.addHandler(handler) } @@ -1971,13 +1971,13 @@ public final class ChannelTests: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: false) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { ch in ch.pipeline.addHandler(VerifyEOFReadOrderingAndCloseInChannelReadHandler()) } - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) - .childChannelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 8)) + .childChannelOption(.maxMessagesPerRead, value: 1) + .childChannelOption(.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 8)) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -2033,16 +2033,16 @@ public final class ChannelTests: XCTestCase { let allDone = group.next().makePromise(of: Void.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: false) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { ch in ch.pipeline.addHandler(CloseWhenWeGetEOFHandler(allDone: allDone)) } // maxMessagesPerRead is large so that we definitely spin and seen the EOF - .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 10) - .childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + .childChannelOption(.maxMessagesPerRead, value: 10) + .childChannelOption(.allowRemoteHalfClosure, value: true) // that fits the message we prepared - .childChannelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 8)) + .childChannelOption(.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 8)) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -2095,8 +2095,8 @@ public final class ChannelTests: XCTestCase { let promise = group.next().makePromise(of: Void.self) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .childChannelOption(ChannelOptions.autoRead, value: false) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .childChannelOption(.autoRead, value: false) .childChannelInitializer { ch in ch.pipeline.addHandler(ChannelInactiveVerificationHandler(promise)) } @@ -2729,7 +2729,7 @@ public final class ChannelTests: XCTestCase { } let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "localhost", port: 0) .wait() ) @@ -2928,7 +2928,7 @@ public final class ChannelTests: XCTestCase { XCTAssertTrue(serverChannel.isActive) // we allow auto-read again to make sure that the socket buffer is drained on write error // (cf. https://github.com/apple/swift-nio/issues/593) - context.channel.setOption(ChannelOptions.autoRead, value: true).flatMap { + context.channel.setOption(.autoRead, value: true).flatMap { // let's trigger the write error var buffer = context.channel.allocator.buffer(capacity: 16) buffer.writeStaticString("THIS WILL FAIL ANYWAY") @@ -2974,7 +2974,7 @@ public final class ChannelTests: XCTestCase { let allDonePromise = singleThreadedELG.next().makePromise(of: Void.self) let server = try assertNoThrowWithValue( ServerBootstrap(group: singleThreadedELG) - .childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true) + .childChannelOption(.allowRemoteHalfClosure, value: true) .childChannelInitializer { channel in channel.pipeline.addHandler( WriteWhenActiveHandler(channelAvailablePromise: serverChannelAvailablePromise) @@ -2994,8 +2994,8 @@ public final class ChannelTests: XCTestCase { eventLoop: singleThreadedELG.next() as! SelectableEventLoop ) ) - XCTAssertNoThrow(try c.setOption(ChannelOptions.autoRead, value: false).wait()) - XCTAssertNoThrow(try c.setOption(ChannelOptions.allowRemoteHalfClosure, value: true).wait()) + XCTAssertNoThrow(try c.setOption(.autoRead, value: false).wait()) + XCTAssertNoThrow(try c.setOption(.allowRemoteHalfClosure, value: true).wait()) XCTAssertNoThrow( try c.pipeline.addHandler( MakeChannelInactiveInReadCausedByWriteErrorHandler( @@ -3024,10 +3024,10 @@ public final class ChannelTests: XCTestCase { ] let server = try assertNoThrowWithValue( ServerBootstrap(group: singleThreadedELG) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .serverChannelOption(ChannelOptions.socketOption(.so_timestamp), value: 1) - .childChannelOption(ChannelOptions.socketOption(.so_keepalive), value: 1) - .childChannelOption(ChannelOptions.tcpOption(.tcp_nodelay), value: 0) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_timestamp), value: 1) + .childChannelOption(.socketOption(.so_keepalive), value: 1) + .childChannelOption(.tcpOption(.tcp_nodelay), value: 0) .childChannelInitializer { channel in acceptedChannels[numberOfAcceptedChannel].succeed(channel) numberOfAcceptedChannel += 1 @@ -3044,8 +3044,8 @@ public final class ChannelTests: XCTestCase { let client1 = try assertNoThrowWithValue( ClientBootstrap(group: singleThreadedELG) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .channelOption(ChannelOptions.tcpOption(.tcp_nodelay), value: 0) + .channelOption(.socketOption(.so_reuseaddr), value: 1) + .channelOption(.tcpOption(.tcp_nodelay), value: 0) .connect(to: server.localAddress!) .wait() ) @@ -3055,7 +3055,7 @@ public final class ChannelTests: XCTestCase { } let client2 = try assertNoThrowWithValue( ClientBootstrap(group: singleThreadedELG) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .connect(to: server.localAddress!) .wait() ) @@ -3272,7 +3272,7 @@ public final class ChannelTests: XCTestCase { var maybeServer: Channel? = nil XCTAssertNoThrow( maybeServer = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -3307,7 +3307,7 @@ public final class ChannelTests: XCTestCase { ) let serverFuture = ServerBootstrap(group: group) - .childChannelOption(ChannelOptions.writeBufferWaterMark, value: handler.watermark) + .childChannelOption(.writeBufferWaterMark, value: handler.watermark) .childChannelInitializer { channel in channel.pipeline.addHandler(handler) } diff --git a/Tests/NIOPosixTests/DatagramChannelTests.swift b/Tests/NIOPosixTests/DatagramChannelTests.swift index 40e0b3dcd0..37f44337c1 100644 --- a/Tests/NIOPosixTests/DatagramChannelTests.swift +++ b/Tests/NIOPosixTests/DatagramChannelTests.swift @@ -44,10 +44,10 @@ extension Channel { let totalBufferSize = messageCount * 2048 try self.setOption( - ChannelOptions.recvAllocator, + .recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: totalBufferSize) ).flatMap { - self.setOption(ChannelOptions.datagramVectorReadMessageCount, value: messageCount) + self.setOption(.datagramVectorReadMessageCount, value: messageCount) }.wait() } } @@ -118,7 +118,7 @@ class DatagramChannelTests: XCTestCase { private func buildChannel(group: EventLoopGroup, host: String = "127.0.0.1") throws -> Channel { try DatagramBootstrap(group: group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHandler(DatagramReadRecorder(), name: "ByteReadRecorder") } @@ -198,7 +198,7 @@ class DatagramChannelTests: XCTestCase { func testDatagramChannelHasWatermark() throws { _ = try self.firstChannel.setOption( - ChannelOptions.writeBufferWaterMark, + .writeBufferWaterMark, value: ChannelOptions.Types.WriteBufferWaterMark(low: 1, high: 1024) ).wait() @@ -537,7 +537,7 @@ class DatagramChannelTests: XCTestCase { public func testSetGetOptionClosedDatagramChannel() throws { try assertSetGetOptionOnOpenAndClosed( channel: firstChannel, - option: ChannelOptions.maxMessagesPerRead, + option: .maxMessagesPerRead, value: 1 ) } @@ -568,8 +568,8 @@ class DatagramChannelTests: XCTestCase { func testSettingTwoDistinctChannelOptionsWorksForDatagramChannel() throws { let channel = try assertNoThrowWithValue( DatagramBootstrap(group: group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .channelOption(ChannelOptions.socketOption(.so_timestamp), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_timestamp), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -631,7 +631,7 @@ class DatagramChannelTests: XCTestCase { XCTAssertNoThrow(try self.secondChannel.configureForRecvMmsg(messageCount: 10)) XCTAssertNoThrow( try self.secondChannel.setOption( - ChannelOptions.recvAllocator, + .recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 30) ).wait() ) @@ -666,8 +666,8 @@ class DatagramChannelTests: XCTestCase { XCTAssertNoThrow(try self.secondChannel.configureForRecvMmsg(messageCount: 10)) // We now turn off autoread. - XCTAssertNoThrow(try self.secondChannel.setOption(ChannelOptions.autoRead, value: false).wait()) - XCTAssertNoThrow(try self.secondChannel.setOption(ChannelOptions.maxMessagesPerRead, value: 3).wait()) + XCTAssertNoThrow(try self.secondChannel.setOption(.autoRead, value: false).wait()) + XCTAssertNoThrow(try self.secondChannel.setOption(.maxMessagesPerRead, value: 3).wait()) var buffer = self.firstChannel.allocator.buffer(capacity: 256) buffer.writeStaticString("data") @@ -680,7 +680,7 @@ class DatagramChannelTests: XCTestCase { XCTAssertNoThrow(try self.firstChannel.writeAndFlush(NIOAny(writeData)).wait()) // Now we read. Rather than issue many read() calls, we'll turn autoread back on. - XCTAssertNoThrow(try self.secondChannel.setOption(ChannelOptions.autoRead, value: true).wait()) + XCTAssertNoThrow(try self.secondChannel.setOption(.autoRead, value: true).wait()) // Wait for all 30 datagrams to come through. There should be no loss here, as this is small datagrams on loopback. let reads = try self.secondChannel.waitForDatagrams(count: 30) @@ -702,11 +702,11 @@ class DatagramChannelTests: XCTestCase { XCTAssertNoThrow( try { // IPv4 - try self.firstChannel.setOption(ChannelOptions.explicitCongestionNotification, value: true).wait() - XCTAssertTrue(try self.firstChannel.getOption(ChannelOptions.explicitCongestionNotification).wait()) + try self.firstChannel.setOption(.explicitCongestionNotification, value: true).wait() + XCTAssertTrue(try self.firstChannel.getOption(.explicitCongestionNotification).wait()) - try self.secondChannel.setOption(ChannelOptions.explicitCongestionNotification, value: false).wait() - XCTAssertFalse(try self.secondChannel.getOption(ChannelOptions.explicitCongestionNotification).wait()) + try self.secondChannel.setOption(.explicitCongestionNotification, value: false).wait() + XCTAssertFalse(try self.secondChannel.getOption(.explicitCongestionNotification).wait()) // IPv6 guard self.supportsIPv6 else { @@ -716,12 +716,12 @@ class DatagramChannelTests: XCTestCase { do { let channel1 = try buildChannel(group: self.group, host: "::1") - try channel1.setOption(ChannelOptions.explicitCongestionNotification, value: true).wait() - XCTAssertTrue(try channel1.getOption(ChannelOptions.explicitCongestionNotification).wait()) + try channel1.setOption(.explicitCongestionNotification, value: true).wait() + XCTAssertTrue(try channel1.getOption(.explicitCongestionNotification).wait()) let channel2 = try buildChannel(group: self.group, host: "::1") - try channel2.setOption(ChannelOptions.explicitCongestionNotification, value: false).wait() - XCTAssertFalse(try channel2.getOption(ChannelOptions.explicitCongestionNotification).wait()) + try channel2.setOption(.explicitCongestionNotification, value: false).wait() + XCTAssertFalse(try channel2.getOption(.explicitCongestionNotification).wait()) } catch let error as SocketAddressError { switch error { case .unknown: @@ -748,15 +748,15 @@ class DatagramChannelTests: XCTestCase { let receiveBootstrap: DatagramBootstrap if vectorRead { receiveBootstrap = DatagramBootstrap(group: group) - .channelOption(ChannelOptions.datagramVectorReadMessageCount, value: 4) + .channelOption(.datagramVectorReadMessageCount, value: 4) } else { receiveBootstrap = DatagramBootstrap(group: group) } let receiveChannel = try receiveBootstrap - .channelOption(ChannelOptions.explicitCongestionNotification, value: true) - .channelOption(ChannelOptions.receivePacketInfo, value: receivePacketInfo) + .channelOption(.explicitCongestionNotification, value: true) + .channelOption(.receivePacketInfo, value: receivePacketInfo) .channelInitializer { channel in channel.pipeline.addHandler(DatagramReadRecorder(), name: "ByteReadRecorder") } @@ -882,7 +882,7 @@ class DatagramChannelTests: XCTestCase { } let channel2Future = DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.writeBufferWaterMark, value: handler.watermark) + .channelOption(.writeBufferWaterMark, value: handler.watermark) .channelInitializer { channel in channel.pipeline.addHandlers([EnvelopingHandler(), handler]) } @@ -901,11 +901,11 @@ class DatagramChannelTests: XCTestCase { XCTAssertNoThrow( try { // IPv4 - try self.firstChannel.setOption(ChannelOptions.receivePacketInfo, value: true).wait() - XCTAssertTrue(try self.firstChannel.getOption(ChannelOptions.receivePacketInfo).wait()) + try self.firstChannel.setOption(.receivePacketInfo, value: true).wait() + XCTAssertTrue(try self.firstChannel.getOption(.receivePacketInfo).wait()) - try self.secondChannel.setOption(ChannelOptions.receivePacketInfo, value: false).wait() - XCTAssertFalse(try self.secondChannel.getOption(ChannelOptions.receivePacketInfo).wait()) + try self.secondChannel.setOption(.receivePacketInfo, value: false).wait() + XCTAssertFalse(try self.secondChannel.getOption(.receivePacketInfo).wait()) // IPv6 guard self.supportsIPv6 else { @@ -915,12 +915,12 @@ class DatagramChannelTests: XCTestCase { do { let channel1 = try buildChannel(group: self.group, host: "::1") - try channel1.setOption(ChannelOptions.receivePacketInfo, value: true).wait() - XCTAssertTrue(try channel1.getOption(ChannelOptions.receivePacketInfo).wait()) + try channel1.setOption(.receivePacketInfo, value: true).wait() + XCTAssertTrue(try channel1.getOption(.receivePacketInfo).wait()) let channel2 = try buildChannel(group: self.group, host: "::1") - try channel2.setOption(ChannelOptions.receivePacketInfo, value: false).wait() - XCTAssertFalse(try channel2.getOption(ChannelOptions.receivePacketInfo).wait()) + try channel2.setOption(.receivePacketInfo, value: false).wait() + XCTAssertFalse(try channel2.getOption(.receivePacketInfo).wait()) } catch let error as SocketAddressError { switch error { case .unknown: @@ -939,7 +939,7 @@ class DatagramChannelTests: XCTestCase { let expectedPacketInfo = try constructNIOPacketInfo(address: address) let receiveChannel = try DatagramBootstrap(group: group) - .channelOption(ChannelOptions.receivePacketInfo, value: true) + .channelOption(.receivePacketInfo, value: true) .channelInitializer { channel in channel.pipeline.addHandler(DatagramReadRecorder(), name: "ByteReadRecorder") } @@ -1372,7 +1372,7 @@ class DatagramChannelTests: XCTestCase { } func testSetGSOOption() throws { - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: 1024) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: 1024) if System.supportsUDPSegmentationOffload { XCTAssertNoThrow(try didSet.wait()) } else { @@ -1383,7 +1383,7 @@ class DatagramChannelTests: XCTestCase { } func testGetGSOOption() throws { - let getOption = self.firstChannel.getOption(ChannelOptions.datagramSegmentSize) + let getOption = self.firstChannel.getOption(.datagramSegmentSize) if System.supportsUDPSegmentationOffload { XCTAssertEqual(try getOption.wait(), 0) // not-set } else { @@ -1404,7 +1404,7 @@ class DatagramChannelTests: XCTestCase { let segments = 10 // Enable GSO - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: segmentSize) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: segmentSize) XCTAssertNoThrow(try didSet.wait()) // Form a handful of segments @@ -1449,7 +1449,7 @@ class DatagramChannelTests: XCTestCase { let segments = 10 // Enable GSO - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: segmentSize) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: segmentSize) XCTAssertNoThrow(try didSet.wait()) // Form a handful of segments @@ -1497,7 +1497,7 @@ class DatagramChannelTests: XCTestCase { var segments = 64 let segmentSize = 10 - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: CInt(segmentSize)) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: CInt(segmentSize)) XCTAssertNoThrow(try didSet.wait()) func send(byteCount: Int) throws { @@ -1512,7 +1512,7 @@ class DatagramChannelTests: XCTestCase { // Some older kernel versions report EINVAL with 64 segments. Tolerate that // failure and try again with a lower limit. self.firstChannel = try self.buildChannel(group: self.group) - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: CInt(segmentSize)) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: CInt(segmentSize)) XCTAssertNoThrow(try didSet.wait()) segments = 61 try send(byteCount: segments * segmentSize) @@ -1526,7 +1526,7 @@ class DatagramChannelTests: XCTestCase { try XCTSkipUnless(System.supportsUDPSegmentationOffload, "UDP_SEGMENT (GSO) is not supported on this platform") let segmentSize = 10 - let didSet = self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: CInt(segmentSize)) + let didSet = self.firstChannel.setOption(.datagramSegmentSize, value: CInt(segmentSize)) XCTAssertNoThrow(try didSet.wait()) let buffer = self.firstChannel.allocator.buffer(repeating: 1, count: segmentSize * 65) @@ -1544,7 +1544,7 @@ class DatagramChannelTests: XCTestCase { } func testSetGROOption() throws { - let didSet = self.firstChannel.setOption(ChannelOptions.datagramReceiveOffload, value: true) + let didSet = self.firstChannel.setOption(.datagramReceiveOffload, value: true) if System.supportsUDPReceiveOffload { XCTAssertNoThrow(try didSet.wait()) } else { @@ -1555,13 +1555,13 @@ class DatagramChannelTests: XCTestCase { } func testGetGROOption() throws { - let getOption = self.firstChannel.getOption(ChannelOptions.datagramReceiveOffload) + let getOption = self.firstChannel.getOption(.datagramReceiveOffload) if System.supportsUDPReceiveOffload { XCTAssertEqual(try getOption.wait(), false) // not-set // Now set and check. - XCTAssertNoThrow(try self.firstChannel.setOption(ChannelOptions.datagramReceiveOffload, value: true).wait()) - XCTAssertTrue(try self.firstChannel.getOption(ChannelOptions.datagramReceiveOffload).wait()) + XCTAssertNoThrow(try self.firstChannel.setOption(.datagramReceiveOffload, value: true).wait()) + XCTAssertTrue(try self.firstChannel.getOption(.datagramReceiveOffload).wait()) } else { XCTAssertThrowsError(try getOption.wait()) { error in XCTAssertEqual(error as? ChannelError, .operationUnsupported) @@ -1576,24 +1576,24 @@ class DatagramChannelTests: XCTestCase { /// Set GSO on the first channel. XCTAssertNoThrow( - try self.firstChannel.setOption(ChannelOptions.datagramSegmentSize, value: CInt(segmentSize)).wait() + try self.firstChannel.setOption(.datagramSegmentSize, value: CInt(segmentSize)).wait() ) /// Set GRO on the second channel. - XCTAssertNoThrow(try self.secondChannel.setOption(ChannelOptions.datagramReceiveOffload, value: true).wait()) + XCTAssertNoThrow(try self.secondChannel.setOption(.datagramReceiveOffload, value: true).wait()) /// The third channel has neither set. // Enable on second channel if let vectorReads = vectorReads { XCTAssertNoThrow( - try self.secondChannel.setOption(ChannelOptions.datagramVectorReadMessageCount, value: vectorReads) + try self.secondChannel.setOption(.datagramVectorReadMessageCount, value: vectorReads) .wait() ) } /// Increase the size of the read buffer for the second and third channels. let fixed = FixedSizeRecvByteBufferAllocator(capacity: 1 << 16) - XCTAssertNoThrow(try self.secondChannel.setOption(ChannelOptions.recvAllocator, value: fixed).wait()) - XCTAssertNoThrow(try self.thirdChannel.setOption(ChannelOptions.recvAllocator, value: fixed).wait()) + XCTAssertNoThrow(try self.secondChannel.setOption(.recvAllocator, value: fixed).wait()) + XCTAssertNoThrow(try self.thirdChannel.setOption(.recvAllocator, value: fixed).wait()) // Write a large datagrams on the first channel. They should be split and then accumulated on the receive side. // Form a large buffer to write from the first channel. @@ -1672,10 +1672,10 @@ class DatagramChannelTests: XCTestCase { let segments = 2 let segmentSize = 1000 - XCTAssertNoThrow(try sender.setOption(ChannelOptions.datagramSegmentSize, value: CInt(segmentSize)).wait()) - XCTAssertNoThrow(try receiver.setOption(ChannelOptions.datagramReceiveOffload, value: true).wait()) + XCTAssertNoThrow(try sender.setOption(.datagramSegmentSize, value: CInt(segmentSize)).wait()) + XCTAssertNoThrow(try receiver.setOption(.datagramReceiveOffload, value: true).wait()) let allocator = FixedSizeRecvByteBufferAllocator(capacity: 1 << 16) - XCTAssertNoThrow(try receiver.setOption(ChannelOptions.recvAllocator, value: allocator).wait()) + XCTAssertNoThrow(try receiver.setOption(.recvAllocator, value: allocator).wait()) let buffer = self.firstChannel.allocator.buffer(repeating: 1, count: segmentSize * segments) let writeData = AddressedEnvelope(remoteAddress: receiver.localAddress!, data: buffer) diff --git a/Tests/NIOPosixTests/EchoServerClientTest.swift b/Tests/NIOPosixTests/EchoServerClientTest.swift index 16b74efc4c..e2bf385631 100644 --- a/Tests/NIOPosixTests/EchoServerClientTest.swift +++ b/Tests/NIOPosixTests/EchoServerClientTest.swift @@ -30,7 +30,7 @@ class EchoServerClientTest: XCTestCase { let countingHandler = ByteCountingHandler(numBytes: numBytes, promise: group.next().makePromise()) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(countingHandler) @@ -70,7 +70,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(WriteALotHandler()) }.bind(host: "127.0.0.1", port: 0).wait() @@ -110,7 +110,7 @@ class EchoServerClientTest: XCTestCase { let countingHandler = ByteCountingHandler(numBytes: numBytes, promise: group.next().makePromise()) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -156,7 +156,7 @@ class EchoServerClientTest: XCTestCase { let countingHandler = ByteCountingHandler(numBytes: numBytes, promise: group.next().makePromise()) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) // Set the handlers that are appled to the accepted Channels .childChannelInitializer { channel in @@ -245,7 +245,7 @@ class EchoServerClientTest: XCTestCase { let countingHandler = ByteCountingHandler(numBytes: numBytes, promise: group.next().makePromise()) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(countingHandler) } @@ -288,7 +288,7 @@ class EchoServerClientTest: XCTestCase { let handler = ChannelActiveHandler() let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -317,7 +317,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(EchoServer()) }.bind(host: "127.0.0.1", port: 0).wait() @@ -528,7 +528,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(handler) @@ -566,7 +566,7 @@ class EchoServerClientTest: XCTestCase { let byteCountingHandler = ByteCountingHandler(numBytes: writingBytes.utf8.count, promise: bytesReceivedPromise) let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in // When we've received all the bytes we know the connection is up. Remove the handler. _ = bytesReceivedPromise.futureResult.flatMap { (_: ByteBuffer) in @@ -613,7 +613,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(EchoServer()) }.bind(host: "127.0.0.1", port: 0).wait() @@ -653,7 +653,7 @@ class EchoServerClientTest: XCTestCase { let stringToWrite = "hello" let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(WriteOnConnectHandler(toWrite: stringToWrite)) }.bind(host: "127.0.0.1", port: 0).wait() @@ -692,7 +692,7 @@ class EchoServerClientTest: XCTestCase { dpGroup.enter() let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler( EchoAndEchoAgainAfterSomeTimeServer( @@ -791,7 +791,7 @@ class EchoServerClientTest: XCTestCase { } let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(WriteWhenActiveHandler(str, dpGroup)) }.bind(host: "127.0.0.1", port: 0).wait() @@ -804,8 +804,8 @@ class EchoServerClientTest: XCTestCase { let clientChannel = try assertNoThrowWithValue( ClientBootstrap(group: group) // We will only start reading once we wrote all data on the accepted channel. - //.channelOption(ChannelOptions.autoRead, value: false) - .channelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 2)) + //.channelOption(.autoRead, value: false) + .channelOption(.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 2)) .channelInitializer { channel in channel.pipeline.addHandler(WriteHandler()).flatMap { channel.pipeline.addHandler(countingHandler) @@ -857,7 +857,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(ErrorHandler(promise)) }.bind(host: "127.0.0.1", port: 0).wait() @@ -890,7 +890,7 @@ class EchoServerClientTest: XCTestCase { let serverChannel: Channel do { serverChannel = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in acceptedRemotePort.store(channel.remoteAddress?.port ?? -3, ordering: .relaxed) acceptedLocalPort.store(channel.localAddress?.port ?? -4, ordering: .relaxed) @@ -946,7 +946,7 @@ class EchoServerClientTest: XCTestCase { // we're binding to IPv4 only let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(countingHandler) } diff --git a/Tests/NIOPosixTests/EventLoopTest.swift b/Tests/NIOPosixTests/EventLoopTest.swift index a2c91dba29..de0c9ed051 100644 --- a/Tests/NIOPosixTests/EventLoopTest.swift +++ b/Tests/NIOPosixTests/EventLoopTest.swift @@ -74,7 +74,7 @@ public final class EventLoopTest: XCTestCase { // First, we create a server and client channel, but don't connect them. let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: eventLoopGroup) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) let clientBootstrap = ClientBootstrap(group: eventLoopGroup) @@ -482,7 +482,7 @@ public final class EventLoopTest: XCTestCase { // Create a server channel. let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0).wait() ) @@ -1274,9 +1274,9 @@ public final class EventLoopTest: XCTestCase { var maybeServer: Channel? XCTAssertNoThrow( maybeServer = try ServerBootstrap(group: elg2) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .serverChannelOption(ChannelOptions.autoRead, value: false) - .serverChannelOption(ChannelOptions.maxMessagesPerRead, value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.autoRead, value: false) + .serverChannelOption(.maxMessagesPerRead, value: 1) .childChannelInitializer { channel in channel.pipeline.addHandler(ExecuteSomethingOnEventLoop(groupToNotify: g)) } diff --git a/Tests/NIOPosixTests/FileRegionTest.swift b/Tests/NIOPosixTests/FileRegionTest.swift index 1f7a7a12e6..f7e422032a 100644 --- a/Tests/NIOPosixTests/FileRegionTest.swift +++ b/Tests/NIOPosixTests/FileRegionTest.swift @@ -37,7 +37,7 @@ class FileRegionTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { $0.pipeline.addHandler(countingHandler) } .bind(host: "127.0.0.1", port: 0) .wait() @@ -81,7 +81,7 @@ class FileRegionTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { $0.pipeline.addHandler(countingHandler) } .bind(host: "127.0.0.1", port: 0) .wait() @@ -138,7 +138,7 @@ class FileRegionTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { $0.pipeline.addHandler(countingHandler) } .bind(host: "127.0.0.1", port: 0) .wait() diff --git a/Tests/NIOPosixTests/IdleStateHandlerTest.swift b/Tests/NIOPosixTests/IdleStateHandlerTest.swift index 9896300800..2f9b153356 100644 --- a/Tests/NIOPosixTests/IdleStateHandlerTest.swift +++ b/Tests/NIOPosixTests/IdleStateHandlerTest.swift @@ -83,7 +83,7 @@ class IdleStateHandlerTest: XCTestCase { let serverChannel = try assertNoThrowWithValue( ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .childChannelInitializer { channel in channel.eventLoop.makeCompletedFuture { try channel.pipeline.syncOperations.addHandler(handler) diff --git a/Tests/NIOPosixTests/MulticastTest.swift b/Tests/NIOPosixTests/MulticastTest.swift index 9ef566f82b..22a3e4d0a8 100644 --- a/Tests/NIOPosixTests/MulticastTest.swift +++ b/Tests/NIOPosixTests/MulticastTest.swift @@ -73,7 +73,7 @@ final class MulticastTest: XCTestCase { interface: NIONetworkInterface ) -> EventLoopFuture { DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: host, port: port) .flatMap { channel in let channel = channel as! MulticastChannel @@ -108,7 +108,7 @@ final class MulticastTest: XCTestCase { device: NIONetworkDevice ) -> EventLoopFuture { DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: host, port: port) .flatMap { channel in let channel = channel as! MulticastChannel @@ -322,7 +322,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -397,7 +397,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "::1", port: 0) .wait() ) @@ -443,7 +443,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -508,7 +508,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "::1", port: 0) .wait() ) @@ -594,7 +594,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -668,7 +668,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "::1", port: 0) .wait() ) @@ -713,7 +713,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "127.0.0.1", port: 0) .wait() ) @@ -774,7 +774,7 @@ final class MulticastTest: XCTestCase { // Now that we've joined the group, let's send to it. let sender = try assertNoThrowWithValue( DatagramBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .bind(host: "::1", port: 0) .wait() ) diff --git a/Tests/NIOPosixTests/PipeChannelTest.swift b/Tests/NIOPosixTests/PipeChannelTest.swift index 3925561499..e2fd023b8c 100644 --- a/Tests/NIOPosixTests/PipeChannelTest.swift +++ b/Tests/NIOPosixTests/PipeChannelTest.swift @@ -98,7 +98,7 @@ final class PipeChannelTest: XCTestCase { } func testWriteErrorsCloseChannel() { - XCTAssertNoThrow(try self.channel.setOption(ChannelOptions.allowRemoteHalfClosure, value: true).wait()) + XCTAssertNoThrow(try self.channel.setOption(.allowRemoteHalfClosure, value: true).wait()) self.fromChannel.closeFile() var buffer = self.channel.allocator.buffer(capacity: 1) buffer.writeString("X") diff --git a/Tests/NIOPosixTests/RawSocketBootstrapTests.swift b/Tests/NIOPosixTests/RawSocketBootstrapTests.swift index e1ec825712..a65ad1ae91 100644 --- a/Tests/NIOPosixTests/RawSocketBootstrapTests.swift +++ b/Tests/NIOPosixTests/RawSocketBootstrapTests.swift @@ -146,7 +146,7 @@ final class RawSocketBootstrapTests: XCTestCase { let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try elg.syncShutdownGracefully()) } let channel = try NIORawSocketBootstrap(group: elg) - .channelOption(ChannelOptions.ipOption(.ip_hdrincl), value: 1) + .channelOption(.ipOption(.ip_hdrincl), value: 1) .channelInitializer { $0.pipeline.addHandler(DatagramReadRecorder(), name: "ByteReadRecorder") } diff --git a/Tests/NIOPosixTests/SALChannelTests.swift b/Tests/NIOPosixTests/SALChannelTests.swift index d4d5e45f5c..bb44435b33 100644 --- a/Tests/NIOPosixTests/SALChannelTests.swift +++ b/Tests/NIOPosixTests/SALChannelTests.swift @@ -207,8 +207,8 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertParkedRightNow() }) { () -> EventLoopFuture in - channel.setOption(ChannelOptions.writeSpin, value: 0).flatMap { - channel.setOption(ChannelOptions.writeBufferWaterMark, value: .init(low: 1, high: 1)) + channel.setOption(.writeSpin, value: 0).flatMap { + channel.setOption(.writeBufferWaterMark, value: .init(low: 1, high: 1)) }.flatMap { channel.pipeline.addHandler( DoWriteFromWritabilityChangedNotification( @@ -328,7 +328,7 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .testOnly_connect(injectedChannel: channel, to: serverAddress) .flatMap { channel in channel.close() @@ -373,8 +373,8 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.socketOption(.so_reuseaddr), value: 1) + .channelOption(.autoRead, value: false) .bind(to: localAddress) .testOnly_connect(injectedChannel: channel, to: serverAddress) .flatMap { channel in @@ -585,7 +585,7 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in channel.write(firstWrite, promise: nil) channel.write(secondWrite).whenComplete { _ in @@ -640,7 +640,7 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .channelInitializer { channel in channel.write(firstWrite, promise: nil) channel.write(secondWrite).whenComplete { _ in @@ -700,8 +700,8 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.autoRead, value: false) - .channelOption(ChannelOptions.writeSpin, value: 1) + .channelOption(.autoRead, value: false) + .channelOption(.writeSpin, value: 1) .channelInitializer { channel in channel.write(firstWrite).whenComplete { _ in // An extra EL spin here to ensure that the close doesn't @@ -760,8 +760,8 @@ final class SALChannelTest: XCTestCase, SALTest { try self.assertClose(expectedFD: .max) }) { ClientBootstrap(group: channel.eventLoop) - .channelOption(ChannelOptions.autoRead, value: false) - .channelOption(ChannelOptions.writeSpin, value: 1) + .channelOption(.autoRead, value: false) + .channelOption(.writeSpin, value: 1) .channelInitializer { channel in channel.write(firstWrite).whenComplete { _ in // No EL spin here so the close happens in the middle of the write spin. @@ -866,7 +866,7 @@ final class SALChannelTest: XCTestCase, SALTest { let firstWrite = ByteBuffer(string: "foo") let secondWrite = ByteBuffer(string: "bar") var childChannelOptions = ChannelOptions.Storage() - childChannelOptions.append(key: ChannelOptions.autoRead, value: false) + childChannelOptions.append(key: .autoRead, value: false) XCTAssertNoThrow( try channel.eventLoop.runSAL(syscallAssertions: { @@ -954,7 +954,7 @@ final class SALChannelTest: XCTestCase, SALTest { let firstWrite = ByteBuffer(string: "foo") let secondWrite = ByteBuffer(string: "bar") var childChannelOptions = ChannelOptions.Storage() - childChannelOptions.append(key: ChannelOptions.autoRead, value: false) + childChannelOptions.append(key: .autoRead, value: false) XCTAssertNoThrow( try channel.eventLoop.runSAL(syscallAssertions: { diff --git a/Tests/NIOPosixTests/SelectorTest.swift b/Tests/NIOPosixTests/SelectorTest.swift index 3b392cb5c1..e2560b64d3 100644 --- a/Tests/NIOPosixTests/SelectorTest.swift +++ b/Tests/NIOPosixTests/SelectorTest.swift @@ -232,7 +232,7 @@ class SelectorTest: XCTestCase { func channelActive(context: ChannelHandlerContext) { // collect all the channels - context.channel.getOption(ChannelOptions.allowRemoteHalfClosure).whenSuccess { halfClosureAllowed in + context.channel.getOption(.allowRemoteHalfClosure).whenSuccess { halfClosureAllowed in precondition( halfClosureAllowed, "the test configuration is bogus: half-closure is dis-allowed which breaks the setup of this test" @@ -394,7 +394,7 @@ class SelectorTest: XCTestCase { (0..( _ body: (Channel) throws -> R ) throws -> R { let server = try ServerBootstrap(group: group) - .serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) .bind(to: bindTarget ?? .init(ipAddress: "127.0.0.1", port: 0)) .wait() do { diff --git a/Tests/NIOPosixTests/UniversalBootstrapSupportTest.swift b/Tests/NIOPosixTests/UniversalBootstrapSupportTest.swift index 59e9ff2b3a..9b5c970d2f 100644 --- a/Tests/NIOPosixTests/UniversalBootstrapSupportTest.swift +++ b/Tests/NIOPosixTests/UniversalBootstrapSupportTest.swift @@ -85,7 +85,7 @@ class UniversalBootstrapSupportTest: XCTestCase { .channelInitializer { channel in channel.pipeline.addHandlers(counter1, DropChannelReadsHandler(), counter2) } - .channelOption(ChannelOptions.autoRead, value: false) + .channelOption(.autoRead, value: false) .connectTimeout(.hours(1)) .enableTLS() .connect(to: server.localAddress!) diff --git a/Tests/NIOPosixTests/VsockAddressTest.swift b/Tests/NIOPosixTests/VsockAddressTest.swift index 96e22d9438..c32924a8bb 100644 --- a/Tests/NIOPosixTests/VsockAddressTest.swift +++ b/Tests/NIOPosixTests/VsockAddressTest.swift @@ -78,6 +78,6 @@ class VsockAddressTest: XCTestCase { eventLoop: eventLoop as! SelectableEventLoop, group: singleThreadedELG ) - XCTAssertEqual(try channel.getOption(ChannelOptions.localVsockContextID).wait(), localCID) + XCTAssertEqual(try channel.getOption(.localVsockContextID).wait(), localCID) } } diff --git a/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift b/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift index 293fb624bc..a31f222e5f 100644 --- a/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift +++ b/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift @@ -33,7 +33,7 @@ class NIOHTTP1TestServerTest: XCTestCase { func connect(serverPort: Int, responsePromise: EventLoopPromise) throws -> EventLoopFuture { let bootstrap = ClientBootstrap(group: self.group) - .channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1) + .channelOption(.socketOption(.so_reuseaddr), value: 1) .channelInitializer { channel in channel.pipeline.addHTTPClientHandlers( position: .first, From 1fa1fe86118c8c33a9eac5ab6c096ff616fa3406 Mon Sep 17 00:00:00 2001 From: Ayush Garg Date: Mon, 29 Jul 2024 12:03:12 +0100 Subject: [PATCH 3/3] fix format --- Sources/NIOCore/ChannelOption.swift | 34 ++++++++++++++--------------- Sources/NIOPosix/VsockAddress.swift | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/NIOCore/ChannelOption.swift b/Sources/NIOCore/ChannelOption.swift index a6e6ebc1cf..066e1e5ce5 100644 --- a/Sources/NIOCore/ChannelOption.swift +++ b/Sources/NIOCore/ChannelOption.swift @@ -367,15 +367,15 @@ extension ChannelOption where Self == ChannelOptions.Types.SocketOption { .init(level: NIOBSDSocket.OptionLevel(rawValue: CInt(level)), name: NIOBSDSocket.Option(rawValue: CInt(name))) } #endif - + public static func socketOption(_ name: NIOBSDSocket.Option) -> Self { .init(level: .socket, name: name) } - + public static func ipOption(_ name: NIOBSDSocket.Option) -> Self { .init(level: .ip, name: name) } - + public static func tcpOption(_ name: NIOBSDSocket.Option) -> Self { .init(level: .tcp, name: name) } @@ -383,72 +383,72 @@ extension ChannelOption where Self == ChannelOptions.Types.SocketOption { /// - seealso: `AllocatorOption`. extension ChannelOption where Self == ChannelOptions.Types.AllocatorOption { - public static var allocator: Self {.init()} + public static var allocator: Self { .init() } } /// - seealso: `RecvAllocatorOption`. extension ChannelOption where Self == ChannelOptions.Types.RecvAllocatorOption { - public static var recvAllocator: Self {.init()} + public static var recvAllocator: Self { .init() } } /// - seealso: `AutoReadOption`. extension ChannelOption where Self == ChannelOptions.Types.AutoReadOption { - public static var autoRead: Self {.init()} + public static var autoRead: Self { .init() } } /// - seealso: `MaxMessagesPerReadOption`. extension ChannelOption where Self == ChannelOptions.Types.MaxMessagesPerReadOption { - public static var maxMessagesPerRead: Self {.init()} + public static var maxMessagesPerRead: Self { .init() } } /// - seealso: `BacklogOption`. extension ChannelOption where Self == ChannelOptions.Types.BacklogOption { - public static var backlog: Self {.init()} + public static var backlog: Self { .init() } } /// - seealso: `WriteSpinOption`. extension ChannelOption where Self == ChannelOptions.Types.WriteSpinOption { - public static var writeSpin: Self {.init()} + public static var writeSpin: Self { .init() } } /// - seealso: `WriteBufferWaterMarkOption`. extension ChannelOption where Self == ChannelOptions.Types.WriteBufferWaterMarkOption { - public static var writeBufferWaterMark: Self {.init()} + public static var writeBufferWaterMark: Self { .init() } } /// - seealso: `ConnectTimeoutOption`. extension ChannelOption where Self == ChannelOptions.Types.ConnectTimeoutOption { - public static var connectTimeout: Self {.init()} + public static var connectTimeout: Self { .init() } } /// - seealso: `AllowRemoteHalfClosureOption`. extension ChannelOption where Self == ChannelOptions.Types.AllowRemoteHalfClosureOption { - public static var allowRemoteHalfClosure: Self {.init()} + public static var allowRemoteHalfClosure: Self { .init() } } /// - seealso: `DatagramVectorReadMessageCountOption`. extension ChannelOption where Self == ChannelOptions.Types.DatagramVectorReadMessageCountOption { - public static var datagramVectorReadMessageCount: Self {.init()} + public static var datagramVectorReadMessageCount: Self { .init() } } /// - seealso: `DatagramSegmentSize`. extension ChannelOption where Self == ChannelOptions.Types.DatagramSegmentSize { - public static var datagramSegmentSize: Self {.init()} + public static var datagramSegmentSize: Self { .init() } } /// - seealso: `DatagramReceiveOffload`. extension ChannelOption where Self == ChannelOptions.Types.DatagramReceiveOffload { - public static var datagramReceiveOffload: Self {.init()} + public static var datagramReceiveOffload: Self { .init() } } /// - seealso: `ExplicitCongestionNotificationsOption`. extension ChannelOption where Self == ChannelOptions.Types.ExplicitCongestionNotificationsOption { - public static var explicitCongestionNotification: Self {.init()} + public static var explicitCongestionNotification: Self { .init() } } /// - seealso: `ReceivePacketInfo`. extension ChannelOption where Self == ChannelOptions.Types.ReceivePacketInfo { - public static var receivePacketInfo: Self {.init()} + public static var receivePacketInfo: Self { .init() } } extension ChannelOptions { diff --git a/Sources/NIOPosix/VsockAddress.swift b/Sources/NIOPosix/VsockAddress.swift index 0df25cf483..94d0f797d6 100644 --- a/Sources/NIOPosix/VsockAddress.swift +++ b/Sources/NIOPosix/VsockAddress.swift @@ -157,7 +157,7 @@ extension ChannelOptions { } extension ChannelOption where Self == ChannelOptions.Types.LocalVsockContextID { - public static var localVsockContextID: Self {.init()} + public static var localVsockContextID: Self { .init() } } extension ChannelOptions.Types {