Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new compress-nio non-copyable types #83

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.22.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.5.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.20.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.2.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", branch: "zlib-non-copyable"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
],
targets: [
Expand Down Expand Up @@ -66,5 +66,6 @@ let package = Package(
.product(name: "HummingbirdTesting", package: "hummingbird"),
.product(name: "HummingbirdTLS", package: "hummingbird"),
]),
]
],
swiftLanguageVersions: [.v5, .version("6")]
)
68 changes: 0 additions & 68 deletions Package@swift-6.0.swift

This file was deleted.

34 changes: 15 additions & 19 deletions Sources/HummingbirdWSCompression/PerMessageDeflateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ struct PerMessageDeflateExtension: WebSocketExtension {
case decompressingMessage
}

fileprivate let decompressor: any NIODecompressor
fileprivate var decompressor: ZlibDecompressor
var state: ReceiveState

init(_ algorithm: CompressionAlgorithm) throws {
init(algorithm: ZlibAlgorithm, windowSize: Int32) throws {
self.state = .idle
self.decompressor = algorithm.decompressor
self.decompressor = ZlibDecompressor(algorithm: algorithm, windowSize: windowSize)
try self.decompressor.startStream()
}

Expand All @@ -197,7 +197,7 @@ struct PerMessageDeflateExtension: WebSocketExtension {
self.state = .idle
}
frame.data = try unmaskedData.decompressStream(
with: self.decompressor,
with: &self.decompressor,
maxSize: maxSize,
allocator: ByteBufferAllocator()
)
Expand All @@ -224,12 +224,12 @@ struct PerMessageDeflateExtension: WebSocketExtension {
case sendingMessage
}

fileprivate let compressor: any NIOCompressor
fileprivate var compressor: ZlibCompressor
var sendState: SendState
let minFrameSizeToCompress: Int

init(_ algorithm: CompressionAlgorithm, minFrameSizeToCompress: Int) throws {
self.compressor = algorithm.compressor
init(algorithm: ZlibAlgorithm, configuration: ZlibConfiguration, minFrameSizeToCompress: Int) throws {
self.compressor = ZlibCompressor(algorithm: algorithm, configuration: configuration)
self.minFrameSizeToCompress = minFrameSizeToCompress
self.sendState = .idle
try self.compressor.startStream()
Expand All @@ -245,7 +245,7 @@ struct PerMessageDeflateExtension: WebSocketExtension {
newFrame.rsv1 = true
self.sendState = .sendingMessage
}
newFrame.data = try newFrame.data.compressStream(with: self.compressor, flush: .sync, allocator: ByteBufferAllocator())
newFrame.data = try newFrame.data.compressStream(with: &self.compressor, flush: .sync, allocator: ByteBufferAllocator())
// if final frame then remove last four bytes 0x00 0x00 0xff 0xff
// (see https://datatracker.ietf.org/doc/html/rfc7692#section-7.2.1)
if newFrame.fin {
Expand Down Expand Up @@ -273,19 +273,15 @@ struct PerMessageDeflateExtension: WebSocketExtension {
init(configuration: Configuration) throws {
self.configuration = configuration
self.decompressor = try .init(
CompressionAlgorithm.deflate(
configuration: .init(
windowSize: numericCast(configuration.receiveMaxWindow ?? 15)
)
)
algorithm: .deflate,
windowSize: numericCast(configuration.receiveMaxWindow ?? 15)
)
self.compressor = try .init(
CompressionAlgorithm.deflate(
configuration: .init(
windowSize: numericCast(configuration.sendMaxWindow ?? 15),
compressionLevel: configuration.compressionLevel.map { numericCast($0) } ?? -1,
memoryLevel: configuration.memoryLevel.map { numericCast($0) } ?? 8
)
algorithm: .deflate,
configuration: .init(
windowSize: numericCast(configuration.sendMaxWindow ?? 15),
compressionLevel: configuration.compressionLevel.map { numericCast($0) } ?? -1,
memoryLevel: configuration.memoryLevel.map { numericCast($0) } ?? 8
),
minFrameSizeToCompress: self.configuration.minFrameSizeToCompress
)
Expand Down
Loading