Skip to content

Commit

Permalink
Adopt Sendable for Types in NIOWebSocket (apple#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadoba authored Jul 5, 2022
1 parent 927b91a commit fbe7ef4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Sources/NIOWebSocket/NIOWebSocketClientUpgrader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public final class NIOWebSocketClientUpgrader: NIOHTTPClientProtocolUpgrader {
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension NIOWebSocketClientUpgrader: Sendable {}
#endif

extension NIOWebSocketClientUpgrader {
/// Generates a random WebSocket Request Key by generating 16 bytes randomly and encoding them as a base64 string as defined in RFC6455 https://tools.ietf.org/html/rfc6455#section-4.1
/// - Parameter generator: the `RandomNumberGenerator` used as a the source of randomness
Expand Down
5 changes: 5 additions & 0 deletions Sources/NIOWebSocket/NIOWebSocketFrameAggregator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ public final class NIOWebSocketFrameAggregator: ChannelInboundHandler {
self.accumulatedFrameSize = 0
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension NIOWebSocketFrameAggregator: Sendable {}
#endif
6 changes: 6 additions & 0 deletions Sources/NIOWebSocket/NIOWebSocketServerUpgrader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,9 @@ public final class NIOWebSocketServerUpgrader: HTTPServerProtocolUpgrader {
}
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension NIOWebSocketServerUpgrader: Sendable {}
#endif

2 changes: 1 addition & 1 deletion Sources/NIOWebSocket/WebSocketErrorCodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NIOCore
/// This enum provides names to all non-reserved code numbers,
/// to avoid users needing to remember the specific numerical values
/// of those codes.
public enum WebSocketErrorCode {
public enum WebSocketErrorCode: NIOSendable {
/// Indicates a normal closure, meaning that the purpose for
/// which the connection was established has been fulfilled.
/// Corresponds to code 1000.
Expand Down
11 changes: 10 additions & 1 deletion Sources/NIOWebSocket/WebSocketFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private extension UInt8 {
/// predictable binary sequences into websocket data streams. This structure provides
/// a more convenient method of interacting with a masking key than simply by passing
/// around a four-tuple.
public struct WebSocketMaskingKey {
public struct WebSocketMaskingKey: NIOSendable {
@usableFromInline internal let _key: (UInt8, UInt8, UInt8, UInt8)

public init?<T: Collection>(_ buffer: T) where T.Element == UInt8 {
Expand Down Expand Up @@ -323,6 +323,10 @@ public struct WebSocketFrame {
}
}

#if swift(>=5.5) && canImport(_Concurrency)
extension WebSocketFrame: @unchecked Sendable {}
#endif

extension WebSocketFrame: Equatable {}

extension WebSocketFrame {
Expand All @@ -342,6 +346,11 @@ extension WebSocketFrame {
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension WebSocketFrame._Storage: Sendable {}
#endif

extension WebSocketFrame._Storage: Equatable {
static func ==(lhs: WebSocketFrame._Storage, rhs: WebSocketFrame._Storage) -> Bool {
return lhs.data == rhs.data && lhs.extensionData == rhs.extensionData
Expand Down
5 changes: 5 additions & 0 deletions Sources/NIOWebSocket/WebSocketFrameDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,8 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
}
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension WebSocketFrameDecoder: Sendable {}
#endif
4 changes: 4 additions & 0 deletions Sources/NIOWebSocket/WebSocketFrameEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension WebSocketFrameEncoder: Sendable {}
#endif

extension ByteBuffer {
fileprivate mutating func prependFrameHeaderIfPossible(_ frameHeader: FrameHeader) -> Bool {
Expand Down
4 changes: 3 additions & 1 deletion Sources/NIOWebSocket/WebSocketOpcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
//
//===----------------------------------------------------------------------===//

import NIOCore

/// An operation code for a websocket frame.
public struct WebSocketOpcode {
public struct WebSocketOpcode: NIOSendable {
fileprivate let networkRepresentation: UInt8

public static let continuation = WebSocketOpcode(rawValue: 0x0)
Expand Down
5 changes: 5 additions & 0 deletions Sources/NIOWebSocket/WebSocketProtocolErrorHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ public final class WebSocketProtocolErrorHandler: ChannelInboundHandler {
context.fireErrorCaught(error)
}
}

#if swift(>=5.6)
@available(*, unavailable)
extension WebSocketProtocolErrorHandler: Sendable {}
#endif

0 comments on commit fbe7ef4

Please sign in to comment.