Skip to content

Commit

Permalink
Merge branch 'main' into fb-formatting
Browse files Browse the repository at this point in the history
# Conflicts:
#	IntegrationTests/tests_04_performance/test_01_resources/shared.swift
#	IntegrationTests/tests_04_performance/test_01_resources/test_ping_pong_1000_reqs_1_conn.swift
#	Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift
#	Sources/NIOCore/AsyncSequences/NIOThrowingAsyncSequenceProducer.swift
#	Sources/NIOCore/Codec.swift
#	Sources/NIOCrashTester/OutputGrepper.swift
#	Sources/NIOHTTP1/HTTPEncoder.swift
#	Sources/NIOHTTP1/HTTPServerPipelineHandler.swift
#	Sources/NIOHTTP1/NIOHTTPClientUpgradeHandler.swift
#	Sources/NIOHTTP1Client/main.swift
#	Sources/NIOHTTP1Server/main.swift
#	Sources/NIOMulticastChat/main.swift
#	Sources/NIOPerformanceTester/UDPBenchmark.swift
#	Sources/NIOUDPEchoClient/main.swift
#	Sources/NIOWebSocket/NIOWebSocketFrameAggregator.swift
#	Sources/NIOWebSocket/WebSocketProtocolErrorHandler.swift
#	Tests/NIOCoreTests/AsyncSequences/NIOThrowingAsyncSequenceTests.swift
#	Tests/NIOHTTP1Tests/HTTPClientUpgradeTests.swift
#	Tests/NIOHTTP1Tests/HTTPServerClientTest.swift
#	Tests/NIOHTTP1Tests/HTTPServerPipelineHandlerTest.swift
#	Tests/NIOHTTP1Tests/HTTPServerProtocolErrorHandlerTest.swift
#	Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift
#	Tests/NIOPosixTests/ChannelTests.swift
#	Tests/NIOPosixTests/CodecTest.swift
#	Tests/NIOPosixTests/DatagramChannelTests.swift
#	Tests/NIOPosixTests/SALChannelTests.swift
#	Tests/NIOPosixTests/SocketChannelTest.swift
#	Tests/NIOPosixTests/StreamChannelsTest.swift
#	Tests/NIOWebSocketTests/WebSocketClientEndToEndTests.swift
  • Loading branch information
FranzBusch committed Jul 18, 2024
2 parents 972ea60 + 980bd3e commit bed069f
Show file tree
Hide file tree
Showing 85 changed files with 642 additions and 515 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Pull Request

on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
types: [opened, reopened, synchronize]

jobs:
call-pull-request-soundness-workflow:
name: Soundness
Expand All @@ -17,6 +17,9 @@ jobs:
with:
name: "Unit tests"
matrix_linux_command: "swift test -Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
# Disable warnings as errors: Swift 6 emits sendability warnings that haven't been dealt with yet.
matrix_linux_nightly_main_command_override: "swift test --explicit-target-dependency-import-check error"
matrix_linux_nightly_6_0_command_override: "swift test --explicit-target-dependency-import-check error"

call-pull-request-benchmark-workflow:
name: Benchmarks
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks/NIOPosixBenchmarks/TCPEcho.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private final class EchoRequestChannelHandler: ChannelInboundHandler {
}

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let buffer = self.unwrapInboundIn(data)
let buffer = Self.unwrapInboundIn(data)
self.receivedData += buffer.readableBytes

if self.receivedData == self.numberOfWrites * self.messageSize {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 10
"mallocCountTotal" : 8
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 10
"mallocCountTotal" : 8
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 10
"mallocCountTotal" : 8
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 10
"mallocCountTotal" : 8
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 10
"mallocCountTotal" : 8
}
23 changes: 11 additions & 12 deletions IntegrationTests/tests_04_performance/Thresholds/nightly-6.0.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"10000000_asyncsequenceproducer": 21,
"10000000_asyncsequenceproducer": 19,
"1000000_asyncwriter": 1000050,
"1000_addHandlers": 45050,
"1000_addHandlers_sync": 38050,
"1000_addHandlers": 44050,
"1000_addHandlers_sync": 37050,
"1000_addRemoveHandlers_handlercontext": 8050,
"1000_addRemoveHandlers_handlername": 8050,
"1000_addRemoveHandlers_handlertype": 8050,
Expand All @@ -11,15 +11,15 @@
"1000_copying_bytebufferview_to_array": 1050,
"1000_copying_circularbuffer_to_array": 1050,
"1000_getHandlers": 8050,
"1000_getHandlers_sync": 36,
"1000_getHandlers_sync": 35,
"1000_reqs_1_conn": 26400,
"1000_rst_connections": 147000,
"1000_rst_connections": 145050,
"1000_tcpbootstraps": 3050,
"1000_tcpconnections": 155050,
"1000_tcpconnections": 152050,
"1000_udp_reqs": 6050,
"1000_udpbootstraps": 2050,
"1000_udpconnections": 76050,
"1_reqs_1000_conn": 393000,
"1000_udpconnections": 75050,
"1_reqs_1000_conn": 389050,
"bytebuffer_lots_of_rw": 2050,
"creating_10000_headers": 0,
"decode_1000_ws_frames": 2050,
Expand All @@ -42,10 +42,9 @@
"modifying_byte_buffer_view": 6050,
"ping_pong_1000_reqs_1_conn": 343,
"read_10000_chunks_from_file": 110200,
"schedule_10000_tasks": 50100,
"schedule_10000_tasks": 40100,
"schedule_and_run_10000_tasks": 50050,
"scheduling_10000_executions": 89,
"udp_1000_reqs_1_conn": 6200,
"udp_1_reqs_1000_conn": 165050
}

"udp_1_reqs_1000_conn": 162050
}
96 changes: 48 additions & 48 deletions IntegrationTests/tests_04_performance/Thresholds/nightly-main.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"10000000_asyncsequenceproducer": 21,
"1000000_asyncwriter": 1000050,
"1000_addHandlers": 45050,
"1000_addHandlers_sync": 38050,
"1000_addRemoveHandlers_handlercontext": 8050,
"1000_addRemoveHandlers_handlername": 8050,
"1000_addRemoveHandlers_handlertype": 8050,
"1000_autoReadGetAndSet": 18050,
"1000_autoReadGetAndSet_sync": 0,
"1000_copying_bytebufferview_to_array": 1050,
"1000_copying_circularbuffer_to_array": 1050,
"1000_getHandlers": 8050,
"1000_getHandlers_sync": 36,
"1000_reqs_1_conn": 26400,
"1000_rst_connections": 147000,
"1000_tcpbootstraps": 3050,
"1000_tcpconnections": 155050,
"1000_udp_reqs": 6050,
"1000_udpbootstraps": 2050,
"1000_udpconnections": 76050,
"1_reqs_1000_conn": 393000,
"bytebuffer_lots_of_rw": 2050,
"creating_10000_headers": 0,
"decode_1000_ws_frames": 2050,
"encode_1000_ws_frames_holding_buffer": 3,
"encode_1000_ws_frames_holding_buffer_with_mask": 2050,
"encode_1000_ws_frames_holding_buffer_with_space": 3,
"encode_1000_ws_frames_holding_buffer_with_space_with_mask": 2050,
"encode_1000_ws_frames_new_buffer": 3050,
"encode_1000_ws_frames_new_buffer_with_mask": 5050,
"encode_1000_ws_frames_new_buffer_with_space": 3050,
"encode_1000_ws_frames_new_buffer_with_space_with_mask": 5050,
"execute_hop_10000_tasks": 0,
"future_erase_result": 4050,
"future_lots_of_callbacks": 53050,
"get_100000_headers_canonical_form": 700050,
"get_100000_headers_canonical_form_trimming_whitespace": 700050,
"get_100000_headers_canonical_form_trimming_whitespace_from_long_string": 700050,
"get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050,
"modifying_1000_circular_buffer_elements": 0,
"modifying_byte_buffer_view": 6050,
"ping_pong_1000_reqs_1_conn": 343,
"read_10000_chunks_from_file": 110200,
"schedule_10000_tasks": 50100,
"schedule_and_run_10000_tasks": 50050,
"scheduling_10000_executions": 89,
"udp_1000_reqs_1_conn": 6200,
"udp_1_reqs_1000_conn": 165050
"10000000_asyncsequenceproducer": 19,
"1000000_asyncwriter": 1000050,
"1000_addHandlers": 44050,
"1000_addHandlers_sync": 37050,
"1000_addRemoveHandlers_handlercontext": 8050,
"1000_addRemoveHandlers_handlername": 8050,
"1000_addRemoveHandlers_handlertype": 8050,
"1000_autoReadGetAndSet": 18050,
"1000_autoReadGetAndSet_sync": 0,
"1000_copying_bytebufferview_to_array": 1050,
"1000_copying_circularbuffer_to_array": 1050,
"1000_getHandlers": 8050,
"1000_getHandlers_sync": 35,
"1000_reqs_1_conn": 26400,
"1000_rst_connections": 145050,
"1000_tcpbootstraps": 3050,
"1000_tcpconnections": 152050,
"1000_udp_reqs": 6050,
"1000_udpbootstraps": 2050,
"1000_udpconnections": 75050,
"1_reqs_1000_conn": 389050,
"bytebuffer_lots_of_rw": 2050,
"creating_10000_headers": 0,
"decode_1000_ws_frames": 2050,
"encode_1000_ws_frames_holding_buffer": 3,
"encode_1000_ws_frames_holding_buffer_with_mask": 2050,
"encode_1000_ws_frames_holding_buffer_with_space": 3,
"encode_1000_ws_frames_holding_buffer_with_space_with_mask": 2050,
"encode_1000_ws_frames_new_buffer": 3050,
"encode_1000_ws_frames_new_buffer_with_mask": 5050,
"encode_1000_ws_frames_new_buffer_with_space": 3050,
"encode_1000_ws_frames_new_buffer_with_space_with_mask": 5050,
"execute_hop_10000_tasks": 0,
"future_erase_result": 4050,
"future_lots_of_callbacks": 53050,
"get_100000_headers_canonical_form": 700050,
"get_100000_headers_canonical_form_trimming_whitespace": 700050,
"get_100000_headers_canonical_form_trimming_whitespace_from_long_string": 700050,
"get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050,
"modifying_1000_circular_buffer_elements": 0,
"modifying_byte_buffer_view": 6050,
"ping_pong_1000_reqs_1_conn": 343,
"read_10000_chunks_from_file": 110200,
"schedule_10000_tasks": 40100,
"schedule_and_run_10000_tasks": 50050,
"scheduling_10000_executions": 89,
"udp_1000_reqs_1_conn": 6200,
"udp_1_reqs_1000_conn": 162050
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private final class ReceiveAndCloseHandler: ChannelInboundHandler {
public typealias OutboundOut = ByteBuffer

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let byteBuffer = self.unwrapInboundIn(data)
let byteBuffer = Self.unwrapInboundIn(data)
precondition(byteBuffer.readableBytes == 1)
context.channel.close(promise: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private final class ClientHandler: ChannelInboundHandler {
// Send the data with ECN
let metadata = AddressedEnvelope<ByteBuffer>.Metadata(ecnState: .transportCapableFlag1)
let envelope = AddressedEnvelope<ByteBuffer>(remoteAddress: remoteAddress, data: buffer, metadata: metadata)
clientChannel.writeAndFlush(self.wrapOutboundOut(envelope), promise: nil)
clientChannel.writeAndFlush(Self.wrapOutboundOut(envelope), promise: nil)
}

func sendBytesAndWaitForReply(clientChannel: Channel) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class UnboxingChannelHandler: ChannelInboundHandler {
typealias InboundOut = WebSocketFrame

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let data = self.unwrapInboundIn(data)
context.fireChannelRead(self.wrapInboundOut(data))
let data = Self.unwrapInboundIn(data)
context.fireChannelRead(Self.wrapInboundOut(data))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private final class PongDecoder: ByteToMessageDecoder {

public func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) -> DecodingState {
if let ping = buffer.readInteger(as: UInt8.self) {
context.fireChannelRead(self.wrapInboundOut(ping))
context.fireChannelRead(Self.wrapInboundOut(ping))
return .continue
} else {
return .needMoreData
Expand Down Expand Up @@ -69,15 +69,15 @@ private final class PingHandler: ChannelInboundHandler {
self.pingBuffer = context.channel.allocator.buffer(capacity: 1)
self.pingBuffer.writeInteger(PingHandler.pingCode)

context.writeAndFlush(self.wrapOutboundOut(self.pingBuffer), promise: nil)
context.writeAndFlush(Self.wrapOutboundOut(self.pingBuffer), promise: nil)
}

public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
var buf = self.unwrapInboundIn(data)
if buf.readableBytes == 1 && buf.readInteger(as: UInt8.self) == PongHandler.pongCode {
if self.remainingNumberOfRequests > 0 {
self.remainingNumberOfRequests -= 1
context.writeAndFlush(self.wrapOutboundOut(self.pingBuffer), promise: nil)
context.writeAndFlush(Self.wrapOutboundOut(self.pingBuffer), promise: nil)
} else {
context.close(promise: self.allDone)
}
Expand Down Expand Up @@ -105,7 +105,7 @@ private final class PongHandler: ChannelInboundHandler {
}

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let data = self.unwrapInboundIn(data)
let data = Self.unwrapInboundIn(data)
if data == PingHandler.pingCode {
context.writeAndFlush(NIOAny(self.pongBuffer), promise: nil)
} else {
Expand Down
12 changes: 6 additions & 6 deletions Sources/NIOAsyncAwaitDemo/FullRequestResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public final class MakeFullRequestHandler: ChannelOutboundHandler {
public typealias OutboundIn = HTTPRequestHead

public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
let req = self.unwrapOutboundIn(data)
let req = Self.unwrapOutboundIn(data)

context.write(self.wrapOutboundOut(.head(req)), promise: nil)
context.write(self.wrapOutboundOut(.end(nil)), promise: promise)
context.write(Self.wrapOutboundOut(.head(req)), promise: nil)
context.write(Self.wrapOutboundOut(.end(nil)), promise: promise)
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ public final class RequestResponseHandler<Request, Response>: ChannelDuplexHandl
return
}

let response = self.unwrapInboundIn(data)
let response = Self.unwrapInboundIn(data)
let promise = self.promiseBuffer.removeFirst()

promise.succeed(response)
Expand All @@ -117,15 +117,15 @@ public final class RequestResponseHandler<Request, Response>: ChannelDuplexHandl
}

public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
let (request, responsePromise) = self.unwrapOutboundIn(data)
let (request, responsePromise) = Self.unwrapOutboundIn(data)
switch self.state {
case .error(let error):
assert(self.promiseBuffer.count == 0)
responsePromise.fail(error)
promise?.fail(error)
case .operational:
self.promiseBuffer.append(responsePromise)
context.write(self.wrapOutboundOut(request), promise: promise)
context.write(Self.wrapOutboundOut(request), promise: promise)
}
}
}
2 changes: 1 addition & 1 deletion Sources/NIOChatClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private final class ChatHandler: ChannelInboundHandler {
}

public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
var buffer = self.unwrapInboundIn(data)
var buffer = Self.unwrapInboundIn(data)
while let byte: UInt8 = buffer.readInteger() {
printByte(byte)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIOChatServer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class LineDelimiterCodec: ByteToMessageDecoder {
public func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
let readable = buffer.withUnsafeReadableBytes { $0.firstIndex(of: newLine) }
if let r = readable {
context.fireChannelRead(self.wrapInboundOut(buffer.readSlice(length: r + 1)!))
context.fireChannelRead(Self.wrapInboundOut(buffer.readSlice(length: r + 1)!))
return .continue
}
return .needMoreData
Expand Down Expand Up @@ -69,7 +69,7 @@ final class ChatHandler: ChannelInboundHandler {

var buffer = channel.allocator.buffer(capacity: 64)
buffer.writeString("(ChatServer) - Welcome to: \(context.localAddress!)\n")
context.writeAndFlush(self.wrapOutboundOut(buffer), promise: nil)
context.writeAndFlush(Self.wrapOutboundOut(buffer), promise: nil)
}

public func channelInactive(context: ChannelHandlerContext) {
Expand All @@ -88,7 +88,7 @@ final class ChatHandler: ChannelInboundHandler {

public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let id = ObjectIdentifier(context.channel)
var read = self.unwrapInboundIn(data)
var read = Self.unwrapInboundIn(data)

// 64 should be good enough for the ipaddress
var buffer = context.channel.allocator.buffer(capacity: read.readableBytes + 64)
Expand Down
40 changes: 40 additions & 0 deletions Sources/NIOConcurrencyHelpers/NIOLockedValueBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,46 @@ public struct NIOLockedValueBox<Value> {
public func withLockedValue<T>(_ mutate: (inout Value) throws -> T) rethrows -> T {
try self._storage.withLockedValue(mutate)
}

/// Provides an unsafe view over the lock and its value.
///
/// This can be beneficial when you require fine grained control over the lock in some
/// situations but don't want lose the benefits of ``withLockedValue(_:)`` in others by
/// switching to ``NIOLock``.
public var unsafe: Unsafe {
Unsafe(_storage: self._storage)
}

/// Provides an unsafe view over the lock and its value.
public struct Unsafe {
@usableFromInline
let _storage: LockStorage<Value>

/// Manually acquire the lock.
@inlinable
public func lock() {
self._storage.lock()
}

/// Manually release the lock.
@inlinable
public func unlock() {
self._storage.unlock()
}

/// Mutate the value, assuming the lock has been acquired manually.
///
/// - Parameter mutate: A closure with scoped access to the value.
/// - Returns: The result of the `mutate` closure.
@inlinable
public func withValueAssumingLockIsAcquired<Result>(
_ mutate: (_ value: inout Value) throws -> Result
) rethrows -> Result {
try self._storage.withUnsafeMutablePointerToHeader { value in
try mutate(&value.pointee)
}
}
}
}

extension NIOLockedValueBox: Sendable where Value: Sendable {}
Loading

0 comments on commit bed069f

Please sign in to comment.