mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-05-14 17:02:43 +08:00
Sendability warnings
This commit is contained in:
parent
3a47b8e1e7
commit
c198c58dc7
@ -31,8 +31,9 @@ private final class HTTPHandler: ChannelInboundHandler {
|
||||
self.wrapOutboundOut(.head(HTTPResponseHead(version: head.version, status: .badRequest))),
|
||||
promise: nil
|
||||
)
|
||||
let loopBoundContext = NIOLoopBound.init(context, eventLoop: context.eventLoop)
|
||||
context.writeAndFlush(self.wrapOutboundOut(.end(nil))).whenComplete { (_: Result<(), Error>) in
|
||||
context.close(promise: nil)
|
||||
loopBoundContext.value.close(promise: nil)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -59,10 +60,10 @@ private final class HTTPHandler: ChannelInboundHandler {
|
||||
context.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
|
||||
buffer.clear()
|
||||
buffer.writeStaticString("done with the request now\n")
|
||||
let loopBoundContext = NIOLoopBound.init(context, eventLoop: context.eventLoop)
|
||||
_ = context.eventLoop.scheduleTask(in: .seconds(30)) { [buffer] in
|
||||
context.write(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
|
||||
context.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
|
||||
|
||||
loopBoundContext.value.write(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
|
||||
loopBoundContext.value.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,13 +162,14 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
|
||||
return
|
||||
}
|
||||
|
||||
let loopBoundContext = NIOLoopBound.init(context, eventLoop: context.eventLoop)
|
||||
let timeout = context.eventLoop.scheduleTask(deadline: self.deadline) {
|
||||
switch self.state {
|
||||
case .initialized:
|
||||
preconditionFailure("How can we have a scheduled timeout, if the connection is not even up?")
|
||||
|
||||
case .connectSent, .headReceived:
|
||||
self.failWithError(Error.httpProxyHandshakeTimeout(), context: context)
|
||||
self.failWithError(Error.httpProxyHandshakeTimeout(), context: loopBoundContext.value)
|
||||
|
||||
case .failed, .completed:
|
||||
break
|
||||
|
@ -130,21 +130,22 @@ let allDonePromise = group.next().makePromise(of: Void.self)
|
||||
let maximumFragments = 4
|
||||
let connection = try ClientBootstrap(group: group.next())
|
||||
.channelInitializer { channel in
|
||||
let pcapRingBuffer = NIOPCAPRingBuffer(
|
||||
maximumFragments: maximumFragments,
|
||||
maximumBytes: 1_000_000
|
||||
)
|
||||
return channel.pipeline.addHandler(
|
||||
NIOWritePCAPHandler(
|
||||
mode: .client,
|
||||
fileSink: pcapRingBuffer.addFragment
|
||||
channel.eventLoop.makeCompletedFuture {
|
||||
let pcapRingBuffer = NIOPCAPRingBuffer(
|
||||
maximumFragments: maximumFragments,
|
||||
maximumBytes: 1_000_000
|
||||
)
|
||||
).flatMap {
|
||||
channel.pipeline.addHTTPClientHandlers()
|
||||
}.flatMap {
|
||||
channel.pipeline.addHandler(TriggerPCAPHandler(pcapRingBuffer: pcapRingBuffer, sink: fileSink.write))
|
||||
}.flatMap {
|
||||
channel.pipeline.addHandler(SendSimpleSequenceRequestHandler(allDonePromise: allDonePromise))
|
||||
try channel.pipeline.syncOperations.addHandler(
|
||||
NIOWritePCAPHandler(
|
||||
mode: .client,
|
||||
fileSink: pcapRingBuffer.addFragment
|
||||
)
|
||||
)
|
||||
try channel.pipeline.syncOperations.addHTTPClientHandlers()
|
||||
try channel.pipeline.syncOperations.addHandlers([
|
||||
TriggerPCAPHandler(pcapRingBuffer: pcapRingBuffer, sink: fileSink.write),
|
||||
SendSimpleSequenceRequestHandler(allDonePromise: allDonePromise),
|
||||
])
|
||||
}
|
||||
}
|
||||
.connect(host: "httpbin.org", port: 80)
|
||||
|
@ -204,7 +204,6 @@ class PCAPRingBufferTest: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
let channel = EmbeddedChannel()
|
||||
let trigger = self.dataForTests()[0..<triggerEndIndex]
|
||||
.compactMap { t in t.readableBytes }.reduce(0, +)
|
||||
|
||||
@ -213,20 +212,14 @@ class PCAPRingBufferTest: XCTestCase {
|
||||
maximumBytes: 1_000_000
|
||||
)
|
||||
|
||||
let addHandlers =
|
||||
channel.pipeline.addHandler(
|
||||
NIOWritePCAPHandler(mode: .client, fileSink: pcapRingBuffer.addFragment),
|
||||
name: "capture"
|
||||
)
|
||||
.flatMap { () -> EventLoopFuture<Void> in
|
||||
let triggerHandler = TriggerOnCumulativeSizeHandler(
|
||||
triggerBytes: trigger,
|
||||
pcapRingBuffer: pcapRingBuffer,
|
||||
sink: testRecordedBytes
|
||||
)
|
||||
return channel.pipeline.addHandler(triggerHandler, name: "trigger")
|
||||
}
|
||||
XCTAssertNoThrow(try addHandlers.wait())
|
||||
let channel = EmbeddedChannel(handlers: [
|
||||
NIOWritePCAPHandler(mode: .client, fileSink: pcapRingBuffer.addFragment),
|
||||
TriggerOnCumulativeSizeHandler(
|
||||
triggerBytes: trigger,
|
||||
pcapRingBuffer: pcapRingBuffer,
|
||||
sink: testRecordedBytes
|
||||
),
|
||||
])
|
||||
|
||||
channel.localAddress = try! SocketAddress(ipAddress: "255.255.255.254", port: Int(UInt16.max) - 1)
|
||||
XCTAssertNoThrow(try channel.connect(to: .init(ipAddress: "1.2.3.4", port: 5678)).wait())
|
||||
|
@ -67,7 +67,7 @@ private func withTemporaryFile<T>(
|
||||
_ body: (NIOCore.NIOFileHandle, String) throws -> T
|
||||
) throws -> T {
|
||||
let temporaryFilePath = "\(temporaryDirectory)/nio_extras_\(UUID())"
|
||||
FileManager.default.createFile(atPath: temporaryFilePath, contents: content?.data(using: .utf8))
|
||||
XCTAssertTrue(FileManager.default.createFile(atPath: temporaryFilePath, contents: content?.data(using: .utf8)))
|
||||
defer {
|
||||
XCTAssertNoThrow(try FileManager.default.removeItem(atPath: temporaryFilePath))
|
||||
}
|
||||
@ -86,7 +86,7 @@ private func withTemporaryFile<T>(
|
||||
_ body: (NIOCore.NIOFileHandle, String) async throws -> T
|
||||
) async throws -> T {
|
||||
let temporaryFilePath = "\(temporaryDirectory)/nio_extras_\(UUID())"
|
||||
FileManager.default.createFile(atPath: temporaryFilePath, contents: content?.data(using: .utf8))
|
||||
XCTAssertTrue(FileManager.default.createFile(atPath: temporaryFilePath, contents: content?.data(using: .utf8)))
|
||||
defer {
|
||||
XCTAssertNoThrow(try FileManager.default.removeItem(atPath: temporaryFilePath))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user