Skip to content

Commit

Permalink
Sendability warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Oct 28, 2024
1 parent 3a47b8e commit 2357f9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
9 changes: 5 additions & 4 deletions Sources/HTTPServerWithQuiescingDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/NIOExtras/HTTP1ProxyConnectHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions Sources/NIOWritePartialPCAPDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2357f9e

Please sign in to comment.