Skip to content

Commit 994c319

Browse files
authored
namespace ChannelOptions & fix deprecations (#166)
1 parent 97e8bbb commit 994c319

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.library(name: "NIOHTTP2", targets: ["NIOHTTP2"]),
2424
],
2525
dependencies: [
26-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.3.0"),
26+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.9.0"),
2727
],
2828
targets: [
2929
.target(name: "NIOHTTP2Server",
@@ -35,7 +35,7 @@ let package = Package(
3535
.target(name: "NIOHPACK",
3636
dependencies: ["NIO", "NIOConcurrencyHelpers", "NIOHTTP1"]),
3737
.testTarget(name: "NIOHTTP2Tests",
38-
dependencies: ["NIO", "NIOHTTP1", "NIOHTTP2"]),
38+
dependencies: ["NIO", "NIOHTTP1", "NIOHTTP2", "NIOFoundationCompat"]),
3939
.testTarget(name: "NIOHPACKTests",
4040
dependencies: ["NIOHPACK"])
4141
]

Sources/NIOHTTP2/HTTP2StreamChannel.swift

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,35 @@
1515
import NIO
1616
import NIOConcurrencyHelpers
1717

18-
/// `StreamIDOption` allows users to query the stream ID for a given `HTTP2StreamChannel`.
19-
///
20-
/// On active `HTTP2StreamChannel`s, it is possible that a channel handler or user may need to know which
21-
/// stream ID the channel owns. This channel option allows that query. Please note that this channel option
22-
/// is *get-only*: that is, it cannot be used with `setOption`. The stream ID for a given `HTTP2StreamChannel`
23-
/// is immutable.
24-
public struct StreamIDOption: ChannelOption {
25-
public typealias Value = HTTP2StreamID
26-
27-
public init() { }
28-
}
2918

3019
/// The various channel options specific to `HTTP2StreamChannel`s.
3120
///
3221
/// Please note that some of NIO's regular `ChannelOptions` are valid on `HTTP2StreamChannel`s.
3322
public struct HTTP2StreamChannelOptions {
3423
/// - seealso: `StreamIDOption`.
35-
public static let streamID: StreamIDOption = StreamIDOption()
24+
public static let streamID: HTTP2StreamChannelOptions.Types.StreamIDOption = .init()
3625
}
3726

27+
extension HTTP2StreamChannelOptions {
28+
public enum Types {}
29+
}
30+
31+
@available(*, deprecated, renamed: "HTTP2StreamChannelOptions.Types.StreamIDOption")
32+
public typealias StreamIDOption = HTTP2StreamChannelOptions.Types.StreamIDOption
33+
34+
extension HTTP2StreamChannelOptions.Types {
35+
/// `StreamIDOption` allows users to query the stream ID for a given `HTTP2StreamChannel`.
36+
///
37+
/// On active `HTTP2StreamChannel`s, it is possible that a channel handler or user may need to know which
38+
/// stream ID the channel owns. This channel option allows that query. Please note that this channel option
39+
/// is *get-only*: that is, it cannot be used with `setOption`. The stream ID for a given `HTTP2StreamChannel`
40+
/// is immutable.
41+
public struct StreamIDOption: ChannelOption {
42+
public typealias Value = HTTP2StreamID
43+
44+
public init() { }
45+
}
46+
}
3847

3948
/// The current state of a stream channel.
4049
private enum StreamChannelState {
@@ -269,7 +278,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
269278
assert(eventLoop.inEventLoop)
270279

271280
switch option {
272-
case _ as AutoReadOption:
281+
case _ as ChannelOptions.Types.AutoReadOption:
273282
self.autoRead = value as! Bool
274283
default:
275284
fatalError("setting option \(option) on HTTP2StreamChannel not supported")
@@ -280,9 +289,9 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
280289
assert(eventLoop.inEventLoop)
281290

282291
switch option {
283-
case _ as StreamIDOption:
292+
case _ as HTTP2StreamChannelOptions.Types.StreamIDOption:
284293
return self.streamID as! Option.Value
285-
case _ as AutoReadOption:
294+
case _ as ChannelOptions.Types.AutoReadOption:
286295
return self.autoRead as! Option.Value
287296
default:
288297
fatalError("option \(option) not supported on HTTP2StreamChannel")

Tests/NIOHPACKTests/HuffmanCodingTests.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import XCTest
1616
import NIO
17+
import NIOFoundationCompat
1718
import Foundation
1819
@testable import NIOHPACK
1920

@@ -136,13 +137,10 @@ class HuffmanCodingTests: XCTestCase {
136137
}
137138

138139
var buffer = ByteBufferAllocator().buffer(capacity: data.count)
139-
buffer.writeWithUnsafeMutableBytes { ptr in
140-
let bytePtr = ptr.bindMemory(to: UInt8.self)
141-
return data.copyBytes(to: bytePtr)
142-
}
143-
140+
buffer.writeBytes(data)
141+
144142
// warm up the decoder
145-
_ = try! buffer.getHuffmanEncodedString(at: buffer.readerIndex, length: buffer.readableBytes)
143+
XCTAssertNoThrow(try buffer.getHuffmanEncodedString(at: buffer.readerIndex, length: buffer.readableBytes))
146144

147145
self.measureMetrics(HuffmanCodingTests.defaultPerformanceMetrics, automaticallyStartMeasuring: false) {
148146
startMeasuring()
@@ -183,13 +181,10 @@ class HuffmanCodingTests: XCTestCase {
183181
}
184182

185183
var buffer = ByteBufferAllocator().buffer(capacity: data.count)
186-
buffer.writeWithUnsafeMutableBytes { ptr in
187-
let bytePtr = ptr.bindMemory(to: UInt8.self)
188-
return data.copyBytes(to: bytePtr)
189-
}
184+
buffer.writeBytes(data)
190185

191186
// ensure the decoder table has been loaded
192-
_ = try! buffer.getHuffmanEncodedString(at: buffer.readerIndex, length: buffer.readableBytes)
187+
XCTAssertNoThrow(try buffer.getHuffmanEncodedString(at: buffer.readerIndex, length: buffer.readableBytes))
193188

194189
self.measureMetrics(HuffmanCodingTests.defaultPerformanceMetrics, automaticallyStartMeasuring: false) {
195190
startMeasuring()

Tests/NIOHTTP2Tests/TestUtilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ func openTemporaryFile() -> (CInt, String) {
588588
extension FileRegion {
589589
func asByteBuffer(allocator: ByteBufferAllocator) -> ByteBuffer {
590590
var fileBuffer = allocator.buffer(capacity: self.readableBytes)
591-
fileBuffer.writeWithUnsafeMutableBytes { ptr in
591+
fileBuffer.writeWithUnsafeMutableBytes(minimumWritableBytes: self.readableBytes) { ptr in
592592
let rc = try! self.fileHandle.withUnsafeFileDescriptor { fd -> Int in
593593
lseek(fd, off_t(self.readerIndex), SEEK_SET)
594594
return read(fd, ptr.baseAddress!, self.readableBytes)

docker/docker-compose.1804.50.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
environment:
1919
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=72010
2020
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
21-
- MAX_ALLOCS_ALLOWED_client_server_request_response=378000
21+
- MAX_ALLOCS_ALLOWED_client_server_request_response=384810
2222

2323
performance-test:
2424
image: swift-nio-http2:18.04-5.0
@@ -31,7 +31,7 @@ services:
3131
environment:
3232
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=72010
3333
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
34-
- MAX_ALLOCS_ALLOWED_client_server_request_response=378000
34+
- MAX_ALLOCS_ALLOWED_client_server_request_response=384810
3535

3636
shell:
3737
image: swift-nio-http2:18.04-5.0

0 commit comments

Comments
 (0)