mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Adopt Sendable for CircularBuffer, MarkedCircularBuffer and types in NIOBSDSocket namespace (#2097)
* Adopt `Sendable` for types in `BSDSocket` namespace * Adopt `Sendable` for `CircularBuffer` and `MarkedCircularBuffer` and also `Endianness` * move `NIOSendable` into its own file and copy it over to syscall integration tests
This commit is contained in:
1 parent
788ade1cc3
commit
4fb6bf135b
8 files changed
+31
-12
No files matched your search
@@ -48,6 +48,7 @@ EOF
|
||||
"$here/../../Sources/NIOPosix/BSDSocketAPIPosix.swift" \
|
||||
"$here/../../Sources/NIOPosix/System.swift" \
|
||||
"$here/../../Sources/NIOCore/IO.swift" \
|
||||
"$here/../../Sources/NIOCore/NIOSendable.swift" \
|
||||
"$tmpdir/syscallwrapper/Sources/syscallwrapper"
|
||||
cp "$here/../../Sources/NIOPosix/IO.swift" "$tmpdir/syscallwrapper/Sources/syscallwrapper/NIOPosixIO.swift"
|
||||
ln -s "$here/../../Sources/CNIOLinux" "$tmpdir/syscallwrapper/Sources"
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.5) && canImport(_Concurrency)
|
||||
public typealias NIOSendable = Swift.Sendable
|
||||
#else
|
||||
public typealias NIOSendable = Any
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5.2) && canImport(_Concurrency)
|
||||
|
||||
extension EventLoopFuture {
|
||||
|
||||
@@ -91,7 +91,7 @@ public enum NIOBSDSocket {
|
||||
|
||||
extension NIOBSDSocket {
|
||||
/// Specifies the addressing scheme that the socket can use.
|
||||
public struct AddressFamily: RawRepresentable {
|
||||
public struct AddressFamily: RawRepresentable, NIOSendable {
|
||||
public typealias RawValue = CInt
|
||||
public var rawValue: RawValue
|
||||
public init(rawValue: RawValue) {
|
||||
@@ -108,7 +108,7 @@ extension NIOBSDSocket.AddressFamily: Hashable {
|
||||
|
||||
extension NIOBSDSocket {
|
||||
/// Specifies the type of protocol that the socket can use.
|
||||
public struct ProtocolFamily: RawRepresentable {
|
||||
public struct ProtocolFamily: RawRepresentable, NIOSendable {
|
||||
public typealias RawValue = CInt
|
||||
public var rawValue: RawValue
|
||||
public init(rawValue: RawValue) {
|
||||
@@ -125,7 +125,7 @@ extension NIOBSDSocket.ProtocolFamily: Hashable {
|
||||
|
||||
extension NIOBSDSocket {
|
||||
/// Defines socket option levels.
|
||||
public struct OptionLevel: RawRepresentable {
|
||||
public struct OptionLevel: RawRepresentable, NIOSendable {
|
||||
public typealias RawValue = CInt
|
||||
public var rawValue: RawValue
|
||||
public init(rawValue: RawValue) {
|
||||
@@ -142,7 +142,7 @@ extension NIOBSDSocket.OptionLevel: Hashable {
|
||||
|
||||
extension NIOBSDSocket {
|
||||
/// Defines configuration option names.
|
||||
public struct Option: RawRepresentable {
|
||||
public struct Option: RawRepresentable, NIOSendable {
|
||||
public typealias RawValue = CInt
|
||||
public var rawValue: RawValue
|
||||
public init(rawValue: RawValue) {
|
||||
|
||||
@@ -230,6 +230,7 @@ public struct ByteBuffer {
|
||||
@usableFromInline var _slice: Slice
|
||||
|
||||
// MARK: Internal _Storage for CoW
|
||||
/// Note: This class is **not** thread-safe
|
||||
@usableFromInline final class _Storage {
|
||||
@usableFromInline private(set) var capacity: _Capacity
|
||||
@usableFromInline private(set) var bytes: UnsafeMutableRawPointer
|
||||
|
||||
@@ -159,7 +159,7 @@ extension UInt32 {
|
||||
|
||||
/// Endianness refers to the sequential order in which bytes are arranged into larger numerical values when stored in
|
||||
/// memory or when transmitted over digital links.
|
||||
public enum Endianness {
|
||||
public enum Endianness: NIOSendable {
|
||||
/// The endianness of the machine running this program.
|
||||
public static let host: Endianness = hostEndianness0()
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public struct CircularBuffer<Element>: CustomStringConvertible {
|
||||
///
|
||||
/// - note: Every index is invalidated as soon as you perform a length-changing operating on the `CircularBuffer`
|
||||
/// but remains valid when you replace one item by another using the subscript.
|
||||
public struct Index: Comparable {
|
||||
public struct Index: Comparable, NIOSendable {
|
||||
@usableFromInline private(set) var _backingIndex: UInt32
|
||||
@usableFromInline private(set) var _backingCheck: _UInt24
|
||||
@usableFromInline private(set) var isIndexGEQHeadIndex: Bool
|
||||
@@ -815,6 +815,8 @@ extension CircularBuffer: Hashable where Element: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension CircularBuffer: NIOSendable where Element: NIOSendable {}
|
||||
|
||||
extension CircularBuffer: ExpressibleByArrayLiteral {
|
||||
public init(arrayLiteral elements: Element...) {
|
||||
self.init(elements)
|
||||
|
||||
@@ -190,3 +190,5 @@ extension MarkedCircularBuffer: RandomAccessCollection {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MarkedCircularBuffer: NIOSendable where Element: NIOSendable {}
|
||||
@@ -0,0 +1,19 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2021-2022 Apple Inc. and the SwiftNIO project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.5) && canImport(_Concurrency)
|
||||
public typealias NIOSendable = Swift.Sendable
|
||||
#else
|
||||
public typealias NIOSendable = Any
|
||||
#endif
|
||||
Reference in new issue
Block a user