Skip to content

Commit 61f6aa4

Browse files
authored
Add explicit Sendable annotations (#505)
1 parent 0c020df commit 61f6aa4

8 files changed

+36
-22
lines changed

Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ extension InlineStreamMultiplexer {
197197
}
198198
}
199199

200+
@available(*, unavailable)
201+
extension InlineStreamMultiplexer: Sendable {}
202+
200203
extension NIOHTTP2Handler {
201204
/// A multiplexer that creates a child channel for each HTTP/2 stream.
202205
///

Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ internal class HTTP2CommonInboundStreamMultiplexer {
6565
}
6666
}
6767

68+
@available(*, unavailable)
69+
extension HTTP2CommonInboundStreamMultiplexer: Sendable {}
70+
6871
// MARK:- inbound multiplexer functions
6972
// note this is intentionally not bound to `HTTP2InboundStreamMultiplexer` to allow for freedom in modifying the shared driver function signatures
7073
extension HTTP2CommonInboundStreamMultiplexer {
@@ -222,7 +225,7 @@ extension HTTP2CommonInboundStreamMultiplexer {
222225
}
223226

224227
internal func selectivelyPropagateUserInboundEvent(context: ChannelHandlerContext, event: Any) {
225-
func propagateEvent(_ event: Any) {
228+
func propagateEvent(_ event: ChannelShouldQuiesceEvent) {
226229
for channel in self.streams.values {
227230
channel.baseChannel.pipeline.fireUserInboundEventTriggered(event)
228231
}
@@ -232,8 +235,8 @@ extension HTTP2CommonInboundStreamMultiplexer {
232235
}
233236

234237
switch event {
235-
case is ChannelShouldQuiesceEvent:
236-
propagateEvent(event)
238+
case let shouldQuiesceEvent as ChannelShouldQuiesceEvent:
239+
propagateEvent(shouldQuiesceEvent)
237240
default:
238241
()
239242
}

Sources/NIOHTTP2/HTTP2FrameParser.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,6 @@ struct FrameFlags: OptionSet, CustomStringConvertible {
15551555
/// on a new stream.
15561556
internal static let priority = FrameFlags(rawValue: 0x20)
15571557

1558-
// useful for test cases
1559-
internal static var allFlags: FrameFlags = [.endStream, .endHeaders, .padded, .priority]
1560-
15611558
internal var description: String {
15621559
var strings: [String] = []
15631560
for i in 0..<8 {

Sources/NIOHTTP2/HTTP2StreamChannel.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct HTTP2StreamChannelOptions: Sendable {
2626

2727
extension HTTP2StreamChannelOptions {
2828
/// A namespace for the types used to represent HTTP/2 stream channel options.
29-
public enum Types {}
29+
public enum Types: Sendable {}
3030
}
3131

3232
@available(*, deprecated, renamed: "HTTP2StreamChannelOptions.Types.StreamIDOption")
@@ -761,24 +761,21 @@ extension HTTP2StreamChannel {
761761
while self.pendingReads.count > 0 {
762762
let frame = self.pendingReads.removeFirst()
763763

764-
let anyStreamData: NIOAny
765764
let dataLength: Int?
766765

767-
switch self.streamDataType {
768-
case .frame:
769-
anyStreamData = NIOAny(frame)
770-
case .framePayload:
771-
anyStreamData = NIOAny(frame.payload)
772-
}
773-
774766
switch frame.payload {
775767
case .data(let data):
776768
dataLength = data.data.readableBytes
777769
default:
778770
dataLength = nil
779771
}
780772

781-
self.pipeline.fireChannelRead(anyStreamData)
773+
switch self.streamDataType {
774+
case .frame:
775+
self.pipeline.fireChannelRead(frame)
776+
case .framePayload:
777+
self.pipeline.fireChannelRead(frame.payload)
778+
}
782779

783780
if let size = dataLength, let increment = self.windowManager.bufferedFrameEmitted(size: size) {
784781
// To have a pending read, we must have a stream ID.

Sources/NIOHTTP2/HTTP2ToHTTP1Codec.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ public final class HTTP2ToHTTP1ClientCodec: ChannelInboundHandler, ChannelOutbou
212212
}
213213
}
214214

215+
@available(*, unavailable)
216+
extension HTTP2ToHTTP1ClientCodec: Sendable {}
217+
215218
/// A simple channel handler that translates HTTP/2 concepts into HTTP/1 data types,
216219
/// and vice versa, for use on the client side.
217220
///
@@ -230,7 +233,7 @@ public final class HTTP2FramePayloadToHTTP1ClientCodec: ChannelInboundHandler, C
230233
private var baseCodec: BaseClientCodec
231234

232235
/// The HTTP protocol scheme being used on this connection.
233-
public enum HTTPProtocol {
236+
public enum HTTPProtocol: Sendable, Hashable {
234237
case https
235238
case http
236239
}
@@ -279,6 +282,9 @@ public final class HTTP2FramePayloadToHTTP1ClientCodec: ChannelInboundHandler, C
279282
}
280283
}
281284

285+
@available(*, unavailable)
286+
extension HTTP2FramePayloadToHTTP1ClientCodec: Sendable {}
287+
282288
// MARK: - Server
283289

284290
private struct BaseServerCodec {
@@ -423,6 +429,9 @@ public final class HTTP2ToHTTP1ServerCodec: ChannelInboundHandler, ChannelOutbou
423429
}
424430
}
425431

432+
@available(*, unavailable)
433+
extension HTTP2ToHTTP1ServerCodec: Sendable {}
434+
426435
/// A simple channel handler that translates HTTP/2 concepts into HTTP/1 data types,
427436
/// and vice versa, for use on the server side.
428437
///
@@ -475,6 +484,9 @@ public final class HTTP2FramePayloadToHTTP1ServerCodec: ChannelInboundHandler, C
475484
}
476485
}
477486

487+
@available(*, unavailable)
488+
extension HTTP2FramePayloadToHTTP1ServerCodec: Sendable {}
489+
478490
extension HTTPMethod {
479491
/// Create a `HTTPMethod` from the string representation of that method.
480492
fileprivate init(methodString: String) {

Sources/NIOHTTP2/HTTP2UserEvents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension StreamClosedEvent: Hashable {}
4040
/// A ``NIOHTTP2WindowUpdatedEvent`` is fired whenever a flow control window is changed.
4141
/// This includes changes on the connection flow control window, which is signalled by
4242
/// this event having ``streamID`` set to ``HTTP2StreamID/rootStream``.
43-
public struct NIOHTTP2WindowUpdatedEvent {
43+
public struct NIOHTTP2WindowUpdatedEvent: Sendable {
4444
/// The stream ID of the window that has been changed. May be ``HTTP2StreamID/rootStream``, in which
4545
/// case the connection window has changed.
4646
public let streamID: HTTP2StreamID
@@ -85,7 +85,7 @@ public struct NIOHTTP2WindowUpdatedEvent {
8585
extension NIOHTTP2WindowUpdatedEvent: Hashable {}
8686

8787
/// A ``NIOHTTP2StreamCreatedEvent`` is fired whenever a HTTP/2 stream is created.
88-
public struct NIOHTTP2StreamCreatedEvent {
88+
public struct NIOHTTP2StreamCreatedEvent: Sendable {
8989
/// The ``HTTP2StreamID`` of the created stream.
9090
public let streamID: HTTP2StreamID
9191

@@ -114,7 +114,7 @@ extension NIOHTTP2StreamCreatedEvent: Hashable {}
114114
///
115115
/// This occurs when an `ACK` to a `SETTINGS` frame is received that changes the value of `SETTINGS_INITIAL_WINDOW_SIZE`. This is only fired
116116
/// when the local peer has changed its settings.
117-
public struct NIOHTTP2BulkStreamWindowChangeEvent {
117+
public struct NIOHTTP2BulkStreamWindowChangeEvent: Sendable {
118118
/// The change in the remote stream window sizes.
119119
public let delta: Int
120120

Sources/NIOHTTP2/StreamMap.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ struct StreamMap<Element: PerStreamData> {
160160
}
161161
}
162162

163+
extension StreamMap: Sendable where Element: Sendable {}
164+
163165
extension StreamMap where Element == HTTP2StreamStateMachine {
164166
// This function exists as a performance optimisation: we can keep track of the index and where we are, and
165167
// thereby avoid searching the array twice.

Sources/NIOHTTP2/StreamStateMachine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ import NIOHPACK
9797
///
9898
/// Operations on the state machine are performed by calling specific functions corresponding to
9999
/// the operation that is about to occur.
100-
struct HTTP2StreamStateMachine {
101-
fileprivate enum State {
100+
struct HTTP2StreamStateMachine: Sendable {
101+
fileprivate enum State: Sendable {
102102
// TODO(cory): Can we remove the idle state? Streams shouldn't sit in idle for long periods
103103
// of time, they should immediately transition out, so can we avoid it entirely?
104104
/// In the idle state, the stream has not been opened by either peer.

0 commit comments

Comments
 (0)