Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
guoye-zhang committed Nov 13, 2024
1 parent 48e0b2b commit 9cf9206
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Sources/NIOResumableUpload/HTTPResumableUploadHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class HTTPResumableUploadHandler: ChannelDuplexHandler {
let createUpload: () -> HTTPResumableUpload
var shouldReset: Bool = false

private var context: ChannelHandlerContext!
private var context: ChannelHandlerContext?
private var eventLoop: EventLoop!

/// Create an `HTTPResumableUploadHandler` within a given `HTTPResumableUploadContext`.
Expand Down Expand Up @@ -136,31 +136,31 @@ extension HTTPResumableUploadHandler {

func write(_ part: HTTPResponsePart, promise: EventLoopPromise<Void>?) {
self.runInEventLoop {
self.context.write(self.wrapOutboundOut(part), promise: promise)
self.context?.write(self.wrapOutboundOut(part), promise: promise)
}
}

func flush() {
self.runInEventLoop {
self.context.flush()
self.context?.flush()
}
}

func writeAndFlush(_ part: HTTPResponsePart, promise: EventLoopPromise<Void>?) {
self.runInEventLoop {
self.context.writeAndFlush(self.wrapOutboundOut(part), promise: promise)
self.context?.writeAndFlush(self.wrapOutboundOut(part), promise: promise)
}
}

func read() {
self.runInEventLoop {
self.context.read()
self.context?.read()
}
}

func close(mode: CloseMode, promise: EventLoopPromise<Void>?) {
self.runInEventLoop {
self.context.close(mode: mode, promise: promise)
self.context?.close(mode: mode, promise: promise)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOResumableUploadDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ guard let outputFile = CommandLine.arguments.dropFirst().first else {
}

if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
let uploadContext = HTTPResumableUploadContext(origin: "http://localhost:8081")
let uploadContext = HTTPResumableUploadContext(origin: "http://localhost:8080")

let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
let server = try ServerBootstrap(group: group).childChannelInitializer { channel in
Expand Down

0 comments on commit 9cf9206

Please sign in to comment.