Backport: Use Swift 6.0 docs pipeline (#2966) (#2991)

Documentation checking catches more issues in Swift 6.0.

Adopt the Swift 6.0 image and fix the errors.

More accurate docs.

(cherry picked from commit adfd61adc5)

Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
This commit is contained in:
Cory BenfieldandRick Newton-Rogers authored and GitHub committed 2024-11-22 09:24:33 +00:00
1 parent 4d5eb6bb15
commit 653da4d987
100 files changed
+2092 -2061

No files matched your search

@@ -83,16 +83,16 @@ public final class NIOWebSocketServerUpgrader: HTTPServerProtocolUpgrader, @unch
/// Create a new `NIOWebSocketServerUpgrader`.
///
/// - parameters:
/// - automaticErrorHandling: Whether the pipeline should automatically handle protocol
/// - Parameters:
/// - automaticErrorHandling: Whether the pipeline should automatically handle protocol
/// errors by sending error responses and closing the connection. Defaults to `true`,
/// may be set to `false` if the user wishes to handle their own errors.
/// - shouldUpgrade: A callback that determines whether the websocket request should be
/// - shouldUpgrade: A callback that determines whether the websocket request should be
/// upgraded. This callback is responsible for creating a `HTTPHeaders` object with
/// any headers that it needs on the response *except for* the `Upgrade`, `Connection`,
/// and `Sec-WebSocket-Accept` headers, which this upgrader will handle. Should return
/// an `EventLoopFuture` containing `nil` if the upgrade should be refused.
/// - upgradePipelineHandler: A function that will be called once the upgrade response is
/// - upgradePipelineHandler: A function that will be called once the upgrade response is
/// flushed, and that is expected to mutate the `Channel` appropriately to handle the
/// websocket protocol. This only needs to add the user handlers: the
/// `WebSocketFrameEncoder` and `WebSocketFrameDecoder` will have been added to the
@@ -113,20 +113,20 @@ public final class NIOWebSocketServerUpgrader: HTTPServerProtocolUpgrader, @unch
/// Create a new `NIOWebSocketServerUpgrader`.
///
/// - parameters:
/// - maxFrameSize: The maximum frame size the decoder is willing to tolerate from the
/// - Parameters:
/// - maxFrameSize: The maximum frame size the decoder is willing to tolerate from the
/// remote peer. WebSockets in principle allows frame sizes up to `2**64` bytes, but
/// this is an objectively unreasonable maximum value (on AMD64 systems it is not
/// possible to even. Users may set this to any value up to `UInt32.max`.
/// - automaticErrorHandling: Whether the pipeline should automatically handle protocol
/// - automaticErrorHandling: Whether the pipeline should automatically handle protocol
/// errors by sending error responses and closing the connection. Defaults to `true`,
/// may be set to `false` if the user wishes to handle their own errors.
/// - shouldUpgrade: A callback that determines whether the websocket request should be
/// - shouldUpgrade: A callback that determines whether the websocket request should be
/// upgraded. This callback is responsible for creating a `HTTPHeaders` object with
/// any headers that it needs on the response *except for* the `Upgrade`, `Connection`,
/// and `Sec-WebSocket-Accept` headers, which this upgrader will handle. Should return
/// an `EventLoopFuture` containing `nil` if the upgrade should be refused.
/// - upgradePipelineHandler: A function that will be called once the upgrade response is
/// - upgradePipelineHandler: A function that will be called once the upgrade response is
/// flushed, and that is expected to mutate the `Channel` appropriately to handle the
/// websocket protocol. This only needs to add the user handlers: the
/// `WebSocketFrameEncoder` and `WebSocketFrameDecoder` will have been added to the
@@ -220,7 +220,7 @@ public final class NIOTypedWebSocketServerUpgrader<UpgradeResult: Sendable>: NIO
/// remote peer. WebSockets in principle allows frame sizes up to `2**64` bytes, but
/// this is an objectively unreasonable maximum value (on AMD64 systems it is not
/// possible to even. Users may set this to any value up to `UInt32.max`.
/// - automaticErrorHandling: Whether the pipeline should automatically handle protocol
/// - enableAutomaticErrorHandling: Whether the pipeline should automatically handle protocol
/// errors by sending error responses and closing the connection. Defaults to `true`,
/// may be set to `false` if the user wishes to handle their own errors.
/// - shouldUpgrade: A callback that determines whether the websocket request should be
@@ -228,11 +228,9 @@ public final class NIOTypedWebSocketServerUpgrader<UpgradeResult: Sendable>: NIO
/// any headers that it needs on the response *except for* the `Upgrade`, `Connection`,
/// and `Sec-WebSocket-Accept` headers, which this upgrader will handle. Should return
/// an `EventLoopFuture` containing `nil` if the upgrade should be refused.
/// - enableAutomaticErrorHandling: A function that will be called once the upgrade response is
/// flushed, and that is expected to mutate the `Channel` appropriately to handle the
/// websocket protocol. This only needs to add the user handlers: the
/// `WebSocketFrameEncoder` and `WebSocketFrameDecoder` will have been added to the
/// pipeline automatically.
/// pipeline automatically.to WebSocket protocol errors. Default is true.
/// - upgradePipelineHandler: called once the upgrade was successful.
public init(
maxFrameSize: Int = 1 << 14,
enableAutomaticErrorHandling: Bool = true,
+5 -5
View File
@@ -42,8 +42,8 @@ internal struct SHA1 {
/// Feed the given string into the hash context as a sequence of UTF-8 bytes.
///
/// - parameters:
/// - string: The string that will be UTF-8 encoded and fed into the
/// - Parameters:
/// - string: The string that will be UTF-8 encoded and fed into the
/// hash context.
mutating func update(string: String) {
let isAvailable: ()? = string.utf8.withContiguousStorageIfAvailable {
@@ -60,15 +60,15 @@ internal struct SHA1 {
/// Feed the bytes into the hash context.
///
/// - parameters:
/// - bytes: The bytes to feed into the hash context.
/// - Parameters:
/// - bytes: The bytes to feed into the hash context.
mutating func update(_ bytes: UnsafeBufferPointer<UInt8>) {
c_nio_sha1_loop(&self.sha1Ctx, bytes.baseAddress!, bytes.count)
}
/// Complete the hashing.
///
/// - returns: A 20-byte array of bytes.
/// - Returns: A 20-byte array of bytes.
mutating func finish() -> [UInt8] {
var hashResult: [UInt8] = Array(repeating: 0, count: 20)
hashResult.withUnsafeMutableBufferPointer {
+11 -11
View File
@@ -85,7 +85,7 @@ public enum WebSocketErrorCode: Sendable {
/// Create an error code from a raw 16-bit integer as sent on the
/// network.
///
/// - parameters:
/// - Parameters:
/// integer: The integer form of the status code.
internal init(networkInteger integer: UInt16) {
switch integer {
@@ -116,8 +116,8 @@ public enum WebSocketErrorCode: Sendable {
///
/// Will trap if the error code is not in the valid range.
///
/// - parameters:
/// - codeNumber: The integer form of the status code.
/// - Parameters:
/// - codeNumber: The integer form of the status code.
public init(codeNumber: Int) {
self.init(networkInteger: UInt16(codeNumber))
}
@@ -130,7 +130,7 @@ extension ByteBuffer {
///
/// This method increments the reader index.
///
/// - returns: The error code, or `nil` if there were not enough readable bytes.
/// - Returns: The error code, or `nil` if there were not enough readable bytes.
public mutating func readWebSocketErrorCode() -> WebSocketErrorCode? {
self.readInteger(as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) }
}
@@ -140,17 +140,17 @@ extension ByteBuffer {
/// This method does not increment the reader index, and may be used to read an error
/// code from outside the readable range of bytes.
///
/// - parameters:
/// - index: The index into the buffer to read the error code from.
/// - returns: The error code, or `nil` if there were not enough bytes at that index.
/// - Parameters:
/// - index: The index into the buffer to read the error code from.
/// - Returns: The error code, or `nil` if there were not enough bytes at that index.
public func getWebSocketErrorCode(at index: Int) -> WebSocketErrorCode? {
self.getInteger(at: index, as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) }
}
/// Write the given error code to the buffer.
///
/// - parameters:
/// - code: The code to write into the buffer.
/// - Parameters:
/// - code: The code to write into the buffer.
public mutating func write(webSocketErrorCode code: WebSocketErrorCode) {
self.writeInteger(UInt16(webSocketErrorCode: code))
}
@@ -159,8 +159,8 @@ extension ByteBuffer {
extension UInt16 {
/// Create a UInt16 corresponding to a given `WebSocketErrorCode`.
///
/// - parameters:
/// - code: The `WebSocketErrorCode`.
/// - Parameters:
/// - code: The `WebSocketErrorCode`.
public init(webSocketErrorCode code: WebSocketErrorCode) {
switch code {
case .normalClosure:
+14 -14
View File
@@ -53,8 +53,8 @@ public struct WebSocketMaskingKey: Sendable {
/// Creates a websocket masking key from the network-encoded
/// representation.
///
/// - parameters:
/// - integer: The encoded network representation of the
/// - Parameters:
/// - integer: The encoded network representation of the
/// masking key.
@usableFromInline
internal init(networkRepresentation integer: UInt32) {
@@ -290,23 +290,23 @@ public struct WebSocketFrame {
/// Creates an empty `WebSocketFrame`.
///
/// - parameters:
/// - allocator: The `ByteBufferAllocator` to use when editing the empty buffers.
/// - Parameters:
/// - allocator: The `ByteBufferAllocator` to use when editing the empty buffers.
public init(allocator: ByteBufferAllocator) {
self._storage = .init(data: allocator.buffer(capacity: 0), extensionData: nil)
}
/// Create a `WebSocketFrame` with the given properties.
///
/// - parameters:
/// - fin: The value of the `fin` bit. Defaults to `false`.
/// - rsv1: The value of the first reserved bit. Defaults to `false`.
/// - rsv2: The value of the second reserved bit. Defaults to `false`.
/// - rsv3: The value of the third reserved bit. Defaults to `false`.
/// - opcode: The opcode for the frame. Defaults to `.continuation`.
/// - maskKey: The masking key for the frame, if any. Defaults to `nil`.
/// - data: The application data for the frame.
/// - extensionData: The extension data for the frame.
/// - Parameters:
/// - fin: The value of the `fin` bit. Defaults to `false`.
/// - rsv1: The value of the first reserved bit. Defaults to `false`.
/// - rsv2: The value of the second reserved bit. Defaults to `false`.
/// - rsv3: The value of the third reserved bit. Defaults to `false`.
/// - opcode: The opcode for the frame. Defaults to `.continuation`.
/// - maskKey: The masking key for the frame, if any. Defaults to `nil`.
/// - data: The application data for the frame.
/// - extensionData: The extension data for the frame.
public init(
fin: Bool = false,
rsv1: Bool = false,
@@ -383,7 +383,7 @@ extension WebSocketFrame: CustomStringConvertible {
///
/// The format of the description is not API.
///
/// - returns: A description of this `WebSocketFrame`.
/// - Returns: A description of this `WebSocketFrame`.
public var description: String {
"""
maskKey: \(String(describing: self.maskKey)), \
@@ -42,8 +42,12 @@ extension WebSocketErrorCode {
extension ByteBuffer {
/// Applies the WebSocket unmasking operation.
///
/// - parameters:
/// - maskingKey: The masking key.
/// - Parameters:
/// - maskingKey: The masking key.
/// - indexOffset: An integer offset to apply to the index into the masking key.
/// This is used when masking multiple "contiguous" byte buffers, to ensure that
/// the masking key is applied uniformly to the collection rather than from the
/// start each time.
public mutating func webSocketUnmask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) {
/// Shhhh: secretly unmasking and masking are the same operation!
webSocketMask(maskingKey, indexOffset: indexOffset)
@@ -51,9 +55,9 @@ extension ByteBuffer {
/// Applies the websocket masking operation.
///
/// - parameters:
/// - maskingKey: The masking key.
/// - indexOffset: An integer offset to apply to the index into the masking key.
/// - Parameters:
/// - maskingKey: The masking key.
/// - indexOffset: An integer offset to apply to the index into the masking key.
/// This is used when masking multiple "contiguous" byte buffers, to ensure that
/// the masking key is applied uniformly to the collection rather than from the
/// start each time.
@@ -237,8 +241,8 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
/// Construct a new `WebSocketFrameDecoder`
///
/// - parameters:
/// - maxFrameSize: The maximum frame size the decoder is willing to tolerate from the
/// - Parameters:
/// - maxFrameSize: The maximum frame size the decoder is willing to tolerate from the
/// remote peer. WebSockets in principle allows frame sizes up to `2**64` bytes, but
/// this is an objectively unreasonable maximum value (on AMD64 systems it is not
/// possible to even allocate a buffer large enough to handle this size), so we
@@ -247,9 +251,6 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
/// Users are strongly encouraged not to increase this value unless they absolutely
/// must, as the decoder will not produce partial frames, meaning that it will hold
/// on to data until the *entire* body is received.
/// - automaticErrorHandling: Whether this `ChannelHandler` should automatically handle
/// protocol errors in frame serialization, or whether it should allow the pipeline
/// to handle them.
public init(maxFrameSize: Int = 1 << 14) {
precondition(maxFrameSize <= UInt32.max, "invalid overlarge max frame size")
self.maxFrameSize = maxFrameSize
+6 -6
View File
@@ -27,8 +27,8 @@ public struct WebSocketOpcode: Sendable {
/// Create an opcode from the encoded representation.
///
/// - parameters
/// - encoded: The encoded representation of the opcode as an 8-bit integer.
/// - Parameters
/// - encoded: The encoded representation of the opcode as an 8-bit integer.
/// Must be no more than 4 bits large.
public init?(encodedWebSocketOpcode encoded: UInt8) {
guard encoded < 0x10 else {
@@ -89,8 +89,8 @@ extension UInt8 {
/// This places the opcode in the four least-significant bits, in
/// a form suitable for sending on the wire.
///
/// - parameters:
/// - opcode: The `WebSocketOpcode`.
/// - Parameters:
/// - opcode: The `WebSocketOpcode`.
public init(webSocketOpcode opcode: WebSocketOpcode) {
precondition(opcode.networkRepresentation < 0x10)
self = opcode.networkRepresentation
@@ -100,8 +100,8 @@ extension UInt8 {
extension Int {
/// Create a UInt8 corresponding to the integer value for a given `WebSocketOpcode`.
///
/// - parameters:
/// - opcode: The `WebSocketOpcode`.
/// - Parameters:
/// - opcode: The `WebSocketOpcode`.
public init(webSocketOpcode opcode: WebSocketOpcode) {
precondition(opcode.networkRepresentation < 0x10)
self = Int(opcode.networkRepresentation)