mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-05-14 08:52:42 +08:00
Strict concurrency for HTTPServerWithQuiescingDemo
This commit is contained in:
parent
c92af9d4ef
commit
c07bf58fda
@ -60,7 +60,8 @@ var targets: [PackageDescription.Target] = [
|
||||
.product(name: "NIOCore", package: "swift-nio"),
|
||||
.product(name: "NIOPosix", package: "swift-nio"),
|
||||
.product(name: "NIOHTTP1", package: "swift-nio"),
|
||||
]
|
||||
],
|
||||
swiftSettings: strictConcurrencySettings
|
||||
),
|
||||
.executableTarget(
|
||||
name: "NIOWritePCAPDemo",
|
||||
|
@ -60,10 +60,9 @@ 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
|
||||
loopBoundContext.value.write(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
|
||||
loopBoundContext.value.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
|
||||
_ = context.eventLoop.assumeIsolated().scheduleTask(in: .seconds(30)) { [buffer] in
|
||||
context.write(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
|
||||
context.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,17 +97,21 @@ private func runServer() throws {
|
||||
.serverChannelOption(ChannelOptions.backlog, value: 256)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.serverChannelInitializer { channel in
|
||||
channel.pipeline.addHandler(quiesce.makeServerChannelHandler(channel: channel))
|
||||
channel.eventLoop.makeCompletedFuture {
|
||||
try channel.pipeline.syncOperations.addHandler(quiesce.makeServerChannelHandler(channel: channel))
|
||||
}
|
||||
}
|
||||
.childChannelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
.childChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.maxMessagesPerRead, value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(
|
||||
channel.eventLoop.makeCompletedFuture {
|
||||
let sync = channel.pipeline.syncOperations
|
||||
try sync.configureHTTPServerPipeline(
|
||||
withPipeliningAssistance: true,
|
||||
withErrorHandling: true
|
||||
).flatMap {
|
||||
channel.pipeline.addHandler(HTTPHandler())
|
||||
)
|
||||
try sync.addHandler(HTTPHandler())
|
||||
}
|
||||
}
|
||||
.bind(host: "localhost", port: 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user