Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new warnings #3026

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/NIOAsyncAwaitDemo/AsyncChannelIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ struct AsyncChannelIO<Request, Response> {
}

func start() async throws -> AsyncChannelIO<Request, Response> {
try await channel.pipeline.addHandler(RequestResponseHandler<HTTPRequestHead, NIOHTTPClientResponseFull>())
.get()
try await channel.eventLoop.submit {
try channel.pipeline.syncOperations.addHandler(
RequestResponseHandler<HTTPRequestHead, NIOHTTPClientResponseFull>()
)
}.get()
return self
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/NIOPosix/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,8 @@ extension NIOPipeBootstrap {
let channel: PipeChannel
let pipeChannelInput: SelectablePipeHandle?
let pipeChannelOutput: SelectablePipeHandle?
let hasNoInputPipe: Bool
let hasNoOutputPipe: Bool
do {
if let input = input {
try self.validateFileDescriptorIsNotAFile(input)
Expand All @@ -2430,6 +2432,8 @@ extension NIOPipeBootstrap {

pipeChannelInput = input.flatMap { SelectablePipeHandle(takingOwnershipOfDescriptor: $0) }
pipeChannelOutput = output.flatMap { SelectablePipeHandle(takingOwnershipOfDescriptor: $0) }
hasNoInputPipe = pipeChannelInput == nil
hasNoOutputPipe = pipeChannelOutput == nil
do {
channel = try self.hooks.makePipeChannel(
eventLoop: eventLoop as! SelectableEventLoop,
Expand Down Expand Up @@ -2458,10 +2462,10 @@ extension NIOPipeBootstrap {
channel.registerAlreadyConfigured0(promise: promise)
return promise.futureResult.map { result }
}.flatMap { result -> EventLoopFuture<ChannelInitializerResult> in
if pipeChannelInput == nil {
if hasNoInputPipe {
return channel.close(mode: .input).map { result }
}
if pipeChannelOutput == nil {
if hasNoOutputPipe {
return channel.close(mode: .output).map { result }
}
return channel.selectableEventLoop.makeSucceededFuture(result)
Expand Down
16 changes: 8 additions & 8 deletions Tests/NIOEmbeddedTests/AsyncTestingChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import XCTest
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
class AsyncTestingChannelTests: XCTestCase {
func testSingleHandlerInit() async throws {
class Handler: ChannelInboundHandler {
final class Handler: ChannelInboundHandler, Sendable {
typealias InboundIn = Never
}

Expand All @@ -43,7 +43,7 @@ class AsyncTestingChannelTests: XCTestCase {
}

func testMultipleHandlerInit() async throws {
class Handler: ChannelInboundHandler, RemovableChannelHandler {
final class Handler: ChannelInboundHandler, RemovableChannelHandler, Sendable {
typealias InboundIn = Never
let identifier: String

Expand Down Expand Up @@ -334,7 +334,7 @@ class AsyncTestingChannelTests: XCTestCase {
try await XCTAsyncAssertTrue(await channel.finish().isClean)

// channelInactive should fire only once.
XCTAssertEqual(inactiveHandler.inactiveNotifications, 1)
XCTAssertEqual(inactiveHandler.inactiveNotifications.load(ordering: .sequentiallyConsistent), 1)
}

func testEmbeddedLifecycle() async throws {
Expand All @@ -355,15 +355,15 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertFalse(channel.isActive)
}

private final class ExceptionThrowingInboundHandler: ChannelInboundHandler {
private final class ExceptionThrowingInboundHandler: ChannelInboundHandler, Sendable {
typealias InboundIn = String

public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
context.fireErrorCaught(ChannelError.operationUnsupported)
}
}

private final class ExceptionThrowingOutboundHandler: ChannelOutboundHandler {
private final class ExceptionThrowingOutboundHandler: ChannelOutboundHandler, Sendable {
typealias OutboundIn = String
typealias OutboundOut = Never

Expand All @@ -372,12 +372,12 @@ class AsyncTestingChannelTests: XCTestCase {
}
}

private final class CloseInChannelInactiveHandler: ChannelInboundHandler {
private final class CloseInChannelInactiveHandler: ChannelInboundHandler, Sendable {
typealias InboundIn = ByteBuffer
public var inactiveNotifications = 0
public let inactiveNotifications = ManagedAtomic(0)

public func channelInactive(context: ChannelHandlerContext) {
inactiveNotifications += 1
inactiveNotifications.wrappingIncrement(by: 1, ordering: .sequentiallyConsistent)
context.close(promise: nil)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHTTP1Tests/HTTPClientUpgradeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private func assertPipelineContainsUpgradeHandler(channel: Channel) {
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
class HTTPClientUpgradeTestCase: XCTestCase {
func setUpClientChannel(
clientHTTPHandler: RemovableChannelHandler,
clientHTTPHandler: RemovableChannelHandler & Sendable,
clientUpgraders: [any TypedAndUntypedHTTPClientProtocolUpgrader],
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void
) throws -> EmbeddedChannel {
Expand Down Expand Up @@ -1063,7 +1063,7 @@ class HTTPClientUpgradeTestCase: XCTestCase {
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
final class TypedHTTPClientUpgradeTestCase: HTTPClientUpgradeTestCase {
override func setUpClientChannel(
clientHTTPHandler: RemovableChannelHandler,
clientHTTPHandler: RemovableChannelHandler & Sendable,
clientUpgraders: [any TypedAndUntypedHTTPClientProtocolUpgrader],
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void
) throws -> EmbeddedChannel {
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ class HTTPServerUpgradeTestCase: XCTestCase {
XCTAssertNil(upgradeRequest.wrappedValue)
upgradeHandlerCbFired.wrappedValue = true

_ = context.channel.pipeline.addHandler(
try! context.channel.pipeline.syncOperations.addHandler(
CheckWeReadInlineAndExtraData(
firstByteDonePromise: firstByteDonePromise,
secondByteDonePromise: secondByteDonePromise,
Expand Down Expand Up @@ -2145,7 +2145,7 @@ final class TypedHTTPServerUpgradeTestCase: HTTPServerUpgradeTestCase {
XCTAssertNotNil(upgradeRequest.wrappedValue)
upgradeHandlerCbFired.wrappedValue = true

_ = context.channel.pipeline.addHandler(
try! context.channel.pipeline.syncOperations.addHandler(
CheckWeReadInlineAndExtraData(
firstByteDonePromise: firstByteDonePromise,
secondByteDonePromise: secondByteDonePromise,
Expand Down
30 changes: 15 additions & 15 deletions Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
port: 0
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureProtocolNegotiationHandlers(channel: channel)
try Self.configureProtocolNegotiationHandlers(channel: channel)
}
}

Expand Down Expand Up @@ -366,7 +366,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
port: 0
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureNestedProtocolNegotiationHandlers(channel: channel)
try Self.configureNestedProtocolNegotiationHandlers(channel: channel)
}
}

Expand Down Expand Up @@ -508,7 +508,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
port: 0
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureProtocolNegotiationHandlers(channel: channel)
try Self.configureProtocolNegotiationHandlers(channel: channel)
}
}

Expand Down Expand Up @@ -958,7 +958,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
output: pipe2WriteFD
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureProtocolNegotiationHandlers(channel: channel)
try Self.configureProtocolNegotiationHandlers(channel: channel)
}
}
} catch {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(
AddressedEnvelopingHandler(remoteAddress: SocketAddress(ipAddress: "127.0.0.1", port: 0))
)
return try self.configureProtocolNegotiationHandlers(
return try Self.configureProtocolNegotiationHandlers(
channel: channel,
proposedALPN: nil,
inboundID: 1,
Expand All @@ -1275,7 +1275,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(
AddressedEnvelopingHandler(remoteAddress: SocketAddress(ipAddress: "127.0.0.1", port: 0))
)
return try self.configureProtocolNegotiationHandlers(
return try Self.configureProtocolNegotiationHandlers(
channel: channel,
proposedALPN: proposedALPN,
inboundID: 2,
Expand Down Expand Up @@ -1329,7 +1329,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
to: .init(ipAddress: "127.0.0.1", port: port)
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
try Self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
}
}
}
Expand All @@ -1345,7 +1345,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
to: .init(ipAddress: "127.0.0.1", port: port)
) { channel in
channel.eventLoop.makeCompletedFuture {
try self.configureNestedProtocolNegotiationHandlers(
try Self.configureNestedProtocolNegotiationHandlers(
channel: channel,
proposedOuterALPN: proposedOuterALPN,
proposedInnerALPN: proposedInnerALPN
Expand Down Expand Up @@ -1382,7 +1382,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
) { channel in
channel.eventLoop.makeCompletedFuture {
try channel.pipeline.syncOperations.addHandler(AddressedEnvelopingHandler())
return try self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
return try Self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
}
}
}
Expand Down Expand Up @@ -1418,13 +1418,13 @@ final class AsyncChannelBootstrapTests: XCTestCase {
) { channel in
channel.eventLoop.makeCompletedFuture {
try channel.pipeline.syncOperations.addHandler(AddressedEnvelopingHandler())
return try self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
return try Self.configureProtocolNegotiationHandlers(channel: channel, proposedALPN: proposedALPN)
}
}
}

@discardableResult
private func configureProtocolNegotiationHandlers(
private static func configureProtocolNegotiationHandlers(
channel: Channel,
proposedALPN: TLSUserEventHandler.ALPN? = nil,
inboundID: UInt8? = nil,
Expand All @@ -1437,7 +1437,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}

@discardableResult
private func configureNestedProtocolNegotiationHandlers(
private static func configureNestedProtocolNegotiationHandlers(
channel: Channel,
proposedOuterALPN: TLSUserEventHandler.ALPN? = nil,
proposedInnerALPN: TLSUserEventHandler.ALPN? = nil
Expand All @@ -1456,7 +1456,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(
TLSUserEventHandler(proposedALPN: proposedInnerALPN)
)
let negotiationFuture = try self.addTypedApplicationProtocolNegotiationHandler(to: channel)
let negotiationFuture = try Self.addTypedApplicationProtocolNegotiationHandler(to: channel)

return negotiationFuture
}
Expand All @@ -1465,7 +1465,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
try channel.pipeline.syncOperations.addHandler(
TLSUserEventHandler(proposedALPN: proposedInnerALPN)
)
let negotiationHandler = try self.addTypedApplicationProtocolNegotiationHandler(to: channel)
let negotiationHandler = try Self.addTypedApplicationProtocolNegotiationHandler(to: channel)

return negotiationHandler
}
Expand All @@ -1481,7 +1481,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}

@discardableResult
private func addTypedApplicationProtocolNegotiationHandler(
private static func addTypedApplicationProtocolNegotiationHandler(
to channel: Channel
) throws -> EventLoopFuture<NegotiationResult> {
let negotiationHandler = NIOTypedApplicationProtocolNegotiationHandler<NegotiationResult> {
Expand Down
Loading
Loading