//===----------------------------------------------------------------------===// // // This source file is part of the SwiftNIO open source project // // Copyright (c) 2023-2024 Apple Inc. and the SwiftNIO project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information // See CONTRIBUTORS.txt for the list of SwiftNIO project authors // // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// import Atomics import NIOCore import NIOHTTPTypes /// The child channel that persists across upload resumption attempts, delivering data as if it is /// a single HTTP upload. final class HTTPResumableUploadChannel: Channel, ChannelCore { let upload: HTTPResumableUpload let allocator: ByteBufferAllocator private let closePromise: EventLoopPromise var closeFuture: EventLoopFuture { self.closePromise.futureResult } private var _pipeline: ChannelPipeline! var pipeline: ChannelPipeline { self._pipeline } var localAddress: SocketAddress? { self.parent?.localAddress } var remoteAddress: SocketAddress? { self.parent?.remoteAddress } var parent: Channel? { self.upload.parentChannel } var isWritable: Bool { self.parent?.isWritable ?? false } private let _isActiveAtomic: ManagedAtomic = .init(true) var isActive: Bool { self._isActiveAtomic.load(ordering: .relaxed) } var _channelCore: ChannelCore { self } let eventLoop: EventLoop private var autoRead: Bool init( upload: HTTPResumableUpload, parent: Channel, channelConfigurator: (Channel) -> Void ) { self.upload = upload self.allocator = parent.allocator self.closePromise = parent.eventLoop.makePromise() self.eventLoop = parent.eventLoop // Only support Channels that implement sync options self.autoRead = try! parent.syncOptions!.getOption(ChannelOptions.autoRead) self._pipeline = ChannelPipeline(channel: self) channelConfigurator(self) } func setOption