Skip to content

Commit 724baf8

Browse files
authored
Merge branch 'main' into jw-more-pcap
2 parents 6b265ef + 54def83 commit 724baf8

File tree

77 files changed

+1082
-363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1082
-363
lines changed

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [NIOExtras, NIOHTTPCompression, NIOSOCKS]

Package.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.6
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftNIO open source project
55
//
6-
// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors
6+
// Copyright (c) 2017-2022 Apple Inc. and the SwiftNIO project authors
77
// Licensed under Apache License v2.0
88
//
99
// See LICENSE.txt for license information
@@ -31,31 +31,31 @@ var targets: [PackageDescription.Target] = [
3131
.product(name: "NIOCore", package: "swift-nio"),
3232
.product(name: "NIOHTTP1", package: "swift-nio"),
3333
]),
34-
.target(
34+
.executableTarget(
3535
name: "HTTPServerWithQuiescingDemo",
3636
dependencies: [
3737
"NIOExtras",
3838
.product(name: "NIOCore", package: "swift-nio"),
3939
.product(name: "NIOPosix", package: "swift-nio"),
4040
.product(name: "NIOHTTP1", package: "swift-nio"),
4141
]),
42-
.target(
42+
.executableTarget(
4343
name: "NIOWritePCAPDemo",
4444
dependencies: [
4545
"NIOExtras",
4646
.product(name: "NIOCore", package: "swift-nio"),
4747
.product(name: "NIOPosix", package: "swift-nio"),
4848
.product(name: "NIOHTTP1", package: "swift-nio"),
4949
]),
50-
.target(
50+
.executableTarget(
5151
name: "NIOWritePartialPCAPDemo",
5252
dependencies: [
5353
"NIOExtras",
5454
.product(name: "NIOCore", package: "swift-nio"),
5555
.product(name: "NIOPosix", package: "swift-nio"),
5656
.product(name: "NIOHTTP1", package: "swift-nio"),
5757
]),
58-
.target(
58+
.executableTarget(
5959
name: "NIOExtrasPerformanceTester",
6060
dependencies: [
6161
"NIOExtras",
@@ -70,7 +70,7 @@ var targets: [PackageDescription.Target] = [
7070
.product(name: "NIO", package: "swift-nio"),
7171
.product(name: "NIOCore", package: "swift-nio"),
7272
]),
73-
.target(
73+
.executableTarget(
7474
name: "NIOSOCKSClient",
7575
dependencies: [
7676
.product(name: "NIOCore", package: "swift-nio"),
@@ -125,7 +125,8 @@ let package = Package(
125125
.library(name: "NIOHTTPCompression", targets: ["NIOHTTPCompression"]),
126126
],
127127
dependencies: [
128-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
128+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
129+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
129130
],
130131
targets: targets
131132
)

[email protected]

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// swift-tools-version:5.5
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftNIO open source project
5+
//
6+
// Copyright (c) 2017-2022 Apple Inc. and the SwiftNIO project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
var targets: [PackageDescription.Target] = [
19+
.target(
20+
name: "NIOExtras",
21+
dependencies: [
22+
.product(name: "NIO", package: "swift-nio"),
23+
.product(name: "NIOCore", package: "swift-nio"),
24+
]),
25+
.target(
26+
name: "NIOHTTPCompression",
27+
dependencies: [
28+
"CNIOExtrasZlib",
29+
.product(name: "NIO", package: "swift-nio"),
30+
.product(name: "NIOCore", package: "swift-nio"),
31+
.product(name: "NIOHTTP1", package: "swift-nio"),
32+
]),
33+
.executableTarget(
34+
name: "HTTPServerWithQuiescingDemo",
35+
dependencies: [
36+
"NIOExtras",
37+
.product(name: "NIOCore", package: "swift-nio"),
38+
.product(name: "NIOPosix", package: "swift-nio"),
39+
.product(name: "NIOHTTP1", package: "swift-nio"),
40+
]),
41+
.executableTarget(
42+
name: "NIOWritePCAPDemo",
43+
dependencies: [
44+
"NIOExtras",
45+
.product(name: "NIOCore", package: "swift-nio"),
46+
.product(name: "NIOPosix", package: "swift-nio"),
47+
.product(name: "NIOHTTP1", package: "swift-nio"),
48+
]),
49+
.executableTarget(
50+
name: "NIOWritePartialPCAPDemo",
51+
dependencies: [
52+
"NIOExtras",
53+
.product(name: "NIOCore", package: "swift-nio"),
54+
.product(name: "NIOPosix", package: "swift-nio"),
55+
.product(name: "NIOHTTP1", package: "swift-nio"),
56+
]),
57+
.executableTarget(
58+
name: "NIOExtrasPerformanceTester",
59+
dependencies: [
60+
"NIOExtras",
61+
.product(name: "NIOCore", package: "swift-nio"),
62+
.product(name: "NIOPosix", package: "swift-nio"),
63+
.product(name: "NIOEmbedded", package: "swift-nio"),
64+
.product(name: "NIOHTTP1", package: "swift-nio"),
65+
]),
66+
.target(
67+
name: "NIOSOCKS",
68+
dependencies: [
69+
.product(name: "NIO", package: "swift-nio"),
70+
.product(name: "NIOCore", package: "swift-nio"),
71+
]),
72+
.executableTarget(
73+
name: "NIOSOCKSClient",
74+
dependencies: [
75+
.product(name: "NIOCore", package: "swift-nio"),
76+
.product(name: "NIOPosix", package: "swift-nio"),
77+
"NIOSOCKS"
78+
]),
79+
.target(
80+
name: "CNIOExtrasZlib",
81+
dependencies: [],
82+
linkerSettings: [
83+
.linkedLibrary("z")
84+
]),
85+
.testTarget(
86+
name: "NIOExtrasTests",
87+
dependencies: [
88+
"NIOExtras",
89+
.product(name: "NIOCore", package: "swift-nio"),
90+
.product(name: "NIOEmbedded", package: "swift-nio"),
91+
.product(name: "NIOPosix", package: "swift-nio"),
92+
.product(name: "NIOTestUtils", package: "swift-nio"),
93+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
94+
]),
95+
.testTarget(
96+
name: "NIOHTTPCompressionTests",
97+
dependencies: [
98+
"CNIOExtrasZlib",
99+
"NIOHTTPCompression",
100+
.product(name: "NIOCore", package: "swift-nio"),
101+
.product(name: "NIOEmbedded", package: "swift-nio"),
102+
.product(name: "NIOHTTP1", package: "swift-nio"),
103+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
104+
]),
105+
.testTarget(
106+
name: "NIOSOCKSTests",
107+
dependencies: [
108+
"NIOSOCKS",
109+
.product(name: "NIOCore", package: "swift-nio"),
110+
.product(name: "NIOEmbedded", package: "swift-nio"),
111+
])
112+
]
113+
114+
let package = Package(
115+
name: "swift-nio-extras",
116+
products: [
117+
.library(name: "NIOExtras", targets: ["NIOExtras"]),
118+
.library(name: "NIOSOCKS", targets: ["NIOSOCKS"]),
119+
.library(name: "NIOHTTPCompression", targets: ["NIOHTTPCompression"]),
120+
],
121+
dependencies: [
122+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.34.0"),
123+
],
124+
targets: targets
125+
)

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ All code will go through code review like in the other repositories related to t
1414
`swift-nio-extras` part of the SwiftNIO 2 family of repositories and depends on the following:
1515

1616
- [`swift-nio`](https://github.com/apple/swift-nio), version 2.30.0 or better.
17-
- Swift 5.4.
17+
- Swift 5.5.2
1818
- `zlib` and its development headers installed on the system. But don't worry, you'll find `zlib` on pretty much any UNIX system that can compile any sort of code.
1919

2020
To depend on `swift-nio-extras`, put the following in the `dependencies` of your `Package.swift`:
@@ -25,7 +25,14 @@ To depend on `swift-nio-extras`, put the following in the `dependencies` of your
2525

2626
### Support for older Swift versions
2727

28-
Earlier versions of SwiftNIO (2.39.x and lower) and SwiftNIOExtras (1.10.x and lower) supported Swift 5.2 and 5.3, SwiftNIO (2.29.x and lower) and SwiftNIOExtras (1.9.x and lower) supported Swift 5.0 and 5.1.
28+
The most recent versions of SwiftNIO Extras support Swift 5.5.2 and newer. The minimum Swift version supported by SwiftNIO Extras releases are detailed below:
29+
30+
SwiftNIO Extras | Minimum Swift Version
31+
--------------------|----------------------
32+
`1.0.0 ..< 1.10.0` | 5.0
33+
`1.10.0 ..< 1.11.0` | 5.2
34+
`1.11.0 ..< 1.14.0` | 5.4
35+
`1.14.0 ...` | 5.5.2
2936

3037
On the [`nio-extras-0.1`](https://github.com/apple/swift-nio-extras/tree/nio-extras-0.1) branch, you can find the `swift-nio-extras` version for the SwiftNIO 1 family. It requires Swift 4.1 or better.
3138

Sources/NIOExtras/DebugInboundEventsHandler.swift

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,135 @@ import Glibc
1919

2020
import NIOCore
2121

22-
/// ChannelInboundHandler that prints all inbound events that pass through the pipeline by default,
23-
/// overridable by providing your own closure for custom logging. See DebugOutboundEventsHandler for outbound events.
22+
/// `ChannelInboundHandler` that prints all inbound events that pass through the pipeline by default,
23+
/// overridable by providing your own closure for custom logging. See ``DebugOutboundEventsHandler`` for outbound events.
2424
public class DebugInboundEventsHandler: ChannelInboundHandler {
25-
25+
/// The type of the inbound data which is wrapped in `NIOAny`.
2626
public typealias InboundIn = Any
27+
/// The type of the inbound data which will be forwarded to the next `ChannelInboundHandler` in the `ChannelPipeline`.
2728
public typealias InboudOut = Any
28-
29+
30+
/// Enumeration of possible `ChannelHandler` events which can occur.
2931
public enum Event {
32+
/// Channel was registered.
3033
case registered
34+
/// Channel was unregistered.
3135
case unregistered
36+
/// Channel became active.
3237
case active
38+
/// Channel became inactive.
3339
case inactive
40+
/// Data was received.
3441
case read(data: NIOAny)
42+
/// Current read loop finished.
3543
case readComplete
44+
/// Writability state of the channel changed.
3645
case writabilityChanged(isWritable: Bool)
46+
/// A user inbound event was received.
3747
case userInboundEventTriggered(event: Any)
48+
/// An error was caught.
3849
case errorCaught(Error)
3950
}
4051

4152
var logger: (Event, ChannelHandlerContext) -> ()
42-
53+
54+
/// Initialiser.
55+
/// - Parameter logger: Method for logging events which occur.
4356
public init(logger: @escaping (Event, ChannelHandlerContext) -> () = DebugInboundEventsHandler.defaultPrint) {
4457
self.logger = logger
4558
}
46-
59+
60+
/// Logs ``Event.registered`` to ``logger``
61+
/// Called when the `Channel` has successfully registered with its `EventLoop` to handle I/O.
62+
/// - parameters:
63+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
4764
public func channelRegistered(context: ChannelHandlerContext) {
4865
logger(.registered, context)
4966
context.fireChannelRegistered()
5067
}
51-
68+
69+
/// Logs ``Event.unregistered`` to ``logger``
70+
/// Called when the `Channel` has unregistered from its `EventLoop`, and so will no longer be receiving I/O events.
71+
/// - parameters:
72+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
5273
public func channelUnregistered(context: ChannelHandlerContext) {
5374
logger(.unregistered, context)
5475
context.fireChannelUnregistered()
5576
}
56-
77+
78+
/// Logs ``Event.active`` to ``logger``
79+
/// Called when the `Channel` has become active, and is able to send and receive data.
80+
/// - parameters:
81+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
5782
public func channelActive(context: ChannelHandlerContext) {
5883
logger(.active, context)
5984
context.fireChannelActive()
6085
}
61-
86+
87+
/// Logs ``Event.inactive`` to ``logger``
88+
/// Called when the `Channel` has become inactive and is no longer able to send and receive data`.
89+
/// - parameters:
90+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
6291
public func channelInactive(context: ChannelHandlerContext) {
6392
logger(.inactive, context)
6493
context.fireChannelInactive()
6594
}
66-
95+
96+
/// Logs ``Event.read`` to ``logger``
97+
/// Called when some data has been read from the remote peer.
98+
/// - parameters:
99+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
100+
/// - data: The data read from the remote peer, wrapped in a `NIOAny`.
67101
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
68102
logger(.read(data: data), context)
69103
context.fireChannelRead(data)
70104
}
71-
105+
106+
/// Logs ``Event.readComplete`` to ``logger``
107+
/// Called when the `Channel` has completed its current read loop, either because no more data is available
108+
/// to read from the transport at this time, or because the `Channel` needs to yield to the event loop to process
109+
/// other I/O events for other `Channel`s.
110+
/// - parameters:
111+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
72112
public func channelReadComplete(context: ChannelHandlerContext) {
73113
logger(.readComplete, context)
74114
context.fireChannelReadComplete()
75115
}
76-
116+
117+
/// Logs ``Event.writabilityChanged`` to ``logger``
118+
/// The writability state of the `Channel` has changed, either because it has buffered more data than the writability
119+
/// high water mark, or because the amount of buffered data has dropped below the writability low water mark.
120+
/// - parameters:
121+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
77122
public func channelWritabilityChanged(context: ChannelHandlerContext) {
78123
logger(.writabilityChanged(isWritable: context.channel.isWritable), context)
79124
context.fireChannelWritabilityChanged()
80125
}
81-
126+
127+
/// Logs ``Event.userInboundEventTriggered`` to ``logger``
128+
/// Called when a user inbound event has been triggered.
129+
/// - parameters:
130+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
131+
/// - event: The event.
82132
public func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
83133
logger(.userInboundEventTriggered(event: event), context)
84134
context.fireUserInboundEventTriggered(event)
85135
}
86-
136+
137+
/// Logs ``Event.errorCaught`` to ``logger``
138+
/// An error was encountered earlier in the inbound `ChannelPipeline`.
139+
/// - parameters:
140+
/// - context: The `ChannelHandlerContext` which this `ChannelHandler` belongs to.
141+
/// - error: The `Error` that was encountered.
87142
public func errorCaught(context: ChannelHandlerContext, error: Error) {
88143
logger(.errorCaught(error), context)
89144
context.fireErrorCaught(error)
90145
}
91-
146+
147+
/// Print and flush a textual description of an ``Event``.
148+
/// - parameters:
149+
/// - event: The ``Event`` to print.
150+
/// - context: The context `event` was received in.
92151
public static func defaultPrint(event: Event, in context: ChannelHandlerContext) {
93152
let message: String
94153
switch event {
@@ -114,5 +173,9 @@ public class DebugInboundEventsHandler: ChannelInboundHandler {
114173
print(message + " in \(context.name)")
115174
fflush(stdout)
116175
}
117-
118176
}
177+
178+
#if swift(>=5.6)
179+
@available(*, unavailable)
180+
extension DebugInboundEventsHandler: Sendable {}
181+
#endif

0 commit comments

Comments
 (0)