Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
glbrntt authored Jan 14, 2025
2 parents a670838 + 74a143a commit e221bf4
Show file tree
Hide file tree
Showing 31 changed files with 195 additions and 178 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let package = Package(
.library(name: "NIOResumableUpload", targets: ["NIOResumableUpload"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.67.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.78.0"),
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.27.0"),
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-http-structured-headers.git", from: "1.1.0"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOExtras/HTTP1ProxyConnectHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
}

// Ok, we've set up the proxy connection. We can now remove ourselves, which should happen synchronously.
context.pipeline.removeHandler(context: context, promise: nil)
context.pipeline.syncOperations.removeHandler(context: context, promise: nil)

self.promise?.succeed(())
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOExtras/WritePCAPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ extension NIOWritePCAPHandler {
}
}
return SynchronizedFileSink(
fileHandle: NIOFileHandle(descriptor: fd),
fileHandle: NIOFileHandle(_deprecatedTakingOwnershipOfDescriptor: fd),
errorHandler: errorHandler
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ class HTTP1ThreadedPCapPerformanceTest: HTTP1ThreadedPerformanceTest {
init() {
let sinkHolder = SinkHolder()
func addPCap(channel: Channel) -> EventLoopFuture<Void> {
let pcapHandler = NIOWritePCAPHandler(
mode: .client,
fileSink: sinkHolder.fileSink.write
)
return channel.pipeline.addHandler(pcapHandler, position: .first)
channel.eventLoop.submit {
let pcapHandler = NIOWritePCAPHandler(
mode: .client,
fileSink: sinkHolder.fileSink.write
)
return try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first)
}
}

self.sinkHolder = sinkHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class HTTP1ThreadedPerformanceTest: Benchmark {

var writeFutures: [EventLoopFuture<Void>] = []
for clientChannel in clientChannels {
clientChannel.write(NIOAny(HTTPClientRequestPart.head(self.head)), promise: nil)
writeFutures.append(clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))))
clientChannel.write(HTTPClientRequestPart.head(self.head), promise: nil)
writeFutures.append(clientChannel.writeAndFlush(HTTPClientRequestPart.end(nil)))
}
let allWrites = EventLoopFuture<Void>.andAllComplete(writeFutures, on: writeFutures.first!.eventLoop)
try! allWrites.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import NIOExtras
class HTTP1ThreadedRollingPCapPerformanceTest: HTTP1ThreadedPerformanceTest {
init() {
func addRollingPCap(channel: Channel) -> EventLoopFuture<Void> {
let pcapRingBuffer = NIOPCAPRingBuffer(
maximumFragments: 25,
maximumBytes: 1_000_000
)
let pcapHandler = NIOWritePCAPHandler(
mode: .client,
fileSink: pcapRingBuffer.addFragment
)
return channel.pipeline.addHandler(pcapHandler, position: .first)
channel.eventLoop.submit {
let pcapRingBuffer = NIOPCAPRingBuffer(
maximumFragments: 25,
maximumBytes: 1_000_000
)
let pcapHandler = NIOWritePCAPHandler(
mode: .client,
fileSink: pcapRingBuffer.addFragment
)
try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first)
}
}

super.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class PCAPPerformanceTest: Benchmark {
mode: .client,
fileSink: fileSink.write
)
try channel.pipeline.addHandler(pcapHandler, position: .first).wait()
try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first)

for _ in 0..<self.numberOfRepeats {
channel.writeAndFlush(self.byteBuffer, promise: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class RollingPCAPPerformanceTest: Benchmark {
mode: .client,
fileSink: pcapRingBuffer.addFragment
)
try channel.pipeline.addHandler(pcapHandler, position: .first).wait()
try channel.pipeline.syncOperations.addHandler(pcapHandler, position: .first)

for _ in 0..<self.numberOfRepeats {
channel.writeAndFlush(self.byteBuffer, promise: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ extension HTTPResumableUploadChannel {

func receive(_ part: HTTPRequestPart) {
self.eventLoop.preconditionInEventLoop()
self.pipeline.fireChannelRead(NIOAny(part))
self.pipeline.fireChannelRead(part)
}

func receiveComplete() {
Expand Down
9 changes: 5 additions & 4 deletions Sources/NIOSOCKSClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ let targetAddress = SOCKSAddress.address(try SocketAddress(ipAddress: targetIPAd
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let bootstrap = ClientBootstrap(group: elg)
.channelInitializer { channel in
channel.pipeline.addHandlers([
SOCKSClientHandler(targetAddress: targetAddress),
EchoHandler(),
])
channel.eventLoop.makeCompletedFuture {
let sync = channel.pipeline.syncOperations
try sync.addHandler(SOCKSClientHandler(targetAddress: targetAddress))
try sync.addHandler(EchoHandler())
}
}
let channel = try bootstrap.connect(host: "127.0.0.1", port: 1080).wait()

Expand Down
9 changes: 5 additions & 4 deletions Sources/NIOWritePCAPDemo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ defer {
let allDonePromise = group.next().makePromise(of: ByteBuffer.self)
let connection = try ClientBootstrap(group: group.next())
.channelInitializer { channel in
channel.pipeline.addHandler(NIOWritePCAPHandler(mode: .client, fileSink: fileSink.write)).flatMap {
channel.pipeline.addHTTPClientHandlers()
}.flatMap {
channel.pipeline.addHandler(SendSimpleRequestHandler(allDonePromise: allDonePromise))
channel.eventLoop.makeCompletedFuture {
let sync = channel.pipeline.syncOperations
try sync.addHandler(NIOWritePCAPHandler(mode: .client, fileSink: fileSink.write))
try sync.addHTTPClientHandlers()
try sync.addHandlers(SendSimpleRequestHandler(allDonePromise: allDonePromise))
}
}
.connect(host: "httpbin.org", port: 80)
Expand Down
7 changes: 3 additions & 4 deletions Tests/NIOExtrasTests/DebugInboundEventsHandlerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DebugInboundEventsHandlerTest: XCTestCase {
handlerUnderTest = DebugInboundEventsHandler { event, _ in
self.lastEvent = event
}
try? channel.pipeline.addHandler(handlerUnderTest).wait()
try? channel.pipeline.syncOperations.addHandlers(handlerUnderTest)
}

override func tearDown() {
Expand Down Expand Up @@ -90,9 +90,8 @@ class DebugInboundEventsHandlerTest: XCTestCase {
let messageString = "message"
var expectedBuffer = ByteBufferAllocator().buffer(capacity: messageString.count)
expectedBuffer.setString(messageString, at: 0)
let nioAny = NIOAny(expectedBuffer)
channel.pipeline.fireChannelRead(nioAny)
XCTAssertEqual(lastEvent, .read(data: nioAny))
channel.pipeline.fireChannelRead(expectedBuffer)
XCTAssertEqual(lastEvent, .read(data: NIOAny(expectedBuffer)))
}

}
Expand Down
8 changes: 4 additions & 4 deletions Tests/NIOExtrasTests/DebugOutboundEventsHandlerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DebugOutboundEventsHandlerTest: XCTestCase {
handlerUnderTest = DebugOutboundEventsHandler { event, _ in
self.lastEvent = event
}
try? channel.pipeline.addHandler(handlerUnderTest).wait()
try? channel.pipeline.syncOperations.addHandler(handlerUnderTest)
}

override func tearDown() {
Expand Down Expand Up @@ -57,9 +57,9 @@ class DebugOutboundEventsHandlerTest: XCTestCase {
}

func testWrite() {
let data = NIOAny(" 1 2 3 ")
channel.write(data, promise: nil)
XCTAssertEqual(lastEvent, .write(data: data))
let data = " 1 2 3 "
channel.write(" 1 2 3 ", promise: nil)
XCTAssertEqual(lastEvent, .write(data: NIOAny(data)))
}

func testFlush() {
Expand Down
16 changes: 10 additions & 6 deletions Tests/NIOExtrasTests/FixedLengthFrameDecoderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class FixedLengthFrameDecoderTest: XCTestCase {
let channel = EmbeddedChannel()

let frameLength = 8
try channel.pipeline.addHandler(ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))).wait()
try channel.pipeline.syncOperations.addHandler(
ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))
)

var buffer = channel.allocator.buffer(capacity: frameLength)
buffer.writeString("xxxx")
Expand All @@ -43,7 +45,9 @@ class FixedLengthFrameDecoderTest: XCTestCase {
let channel = EmbeddedChannel()

let frameLength = 8
try channel.pipeline.addHandler(ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))).wait()
try channel.pipeline.syncOperations.addHandler(
ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))
)

var buffer = channel.allocator.buffer(capacity: 19)
buffer.writeString("xxxxxxxxaaaaaaaabbb")
Expand Down Expand Up @@ -78,7 +82,7 @@ class FixedLengthFrameDecoderTest: XCTestCase {

let frameLength = 8
let handler = ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))
try channel.pipeline.addHandler(handler).wait()
try channel.pipeline.syncOperations.addHandler(handler)

var buffer = channel.allocator.buffer(capacity: 15)
buffer.writeString("xxxxxxxxxxxxxxx")
Expand All @@ -91,7 +95,7 @@ class FixedLengthFrameDecoderTest: XCTestCase {
}
)

let removeFuture = channel.pipeline.removeHandler(handler)
let removeFuture = channel.pipeline.syncOperations.removeHandler(handler)
(channel.eventLoop as! EmbeddedEventLoop).run()
XCTAssertNoThrow(try removeFuture.wait())
XCTAssertThrowsError(try channel.throwIfErrorCaught()) { error in
Expand All @@ -112,7 +116,7 @@ class FixedLengthFrameDecoderTest: XCTestCase {

let frameLength = 8
let handler = ByteToMessageHandler(FixedLengthFrameDecoder(frameLength: frameLength))
try channel.pipeline.addHandler(handler).wait()
try channel.pipeline.syncOperations.addHandler(handler)

var buffer = channel.allocator.buffer(capacity: 6)
buffer.writeString("xxxxxxxx")
Expand All @@ -125,7 +129,7 @@ class FixedLengthFrameDecoderTest: XCTestCase {
}
)

let removeFuture = channel.pipeline.removeHandler(handler)
let removeFuture = channel.pipeline.syncOperations.removeHandler(handler)
(channel.eventLoop as! EmbeddedEventLoop).run()
XCTAssertNoThrow(try removeFuture.wait())
XCTAssertNoThrow(try channel.throwIfErrorCaught())
Expand Down
12 changes: 6 additions & 6 deletions Tests/NIOExtrasTests/HTTP1ProxyConnectHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {
)
var promises: [EventLoopPromise<Void>] = []
promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promises.last)
embedded.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promises.last)

promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(
NIOAny(HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test")))),
HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test"))),
promise: promises.last
)

promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promises.last)
embedded.pipeline.write(HTTPClientRequestPart.end(nil), promise: promises.last)
embedded.pipeline.flush()

// read the connect header back
Expand Down Expand Up @@ -291,16 +291,16 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {
let requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "apple.com")
var promises: [EventLoopPromise<Void>] = []
promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: promises.last)
embedded.pipeline.write(HTTPClientRequestPart.head(requestHead), promise: promises.last)

promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(
NIOAny(HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test")))),
HTTPClientRequestPart.body(.byteBuffer(ByteBuffer(string: "Test"))),
promise: promises.last
)

promises.append(embedded.eventLoop.makePromise())
embedded.pipeline.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: promises.last)
embedded.pipeline.write(HTTPClientRequestPart.end(nil), promise: promises.last)
embedded.pipeline.flush()

// read the connect header back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ final class JSONRPCFramingContentLengthHeaderDecoderTests: XCTestCase {

// let's add the framing handler to the pipeline as that's what we're testing here.
XCTAssertNoThrow(
try self.channel.pipeline.addHandler(
try self.channel.pipeline.syncOperations.addHandler(
ByteToMessageHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameDecoder())
).wait()
)
)
// this pretends to connect the channel to this IP address.
XCTAssertNoThrow(self.channel.connect(to: try .init(ipAddress: "1.2.3.4", port: 5678)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ final class JSONRPCFramingContentLengthHeaderEncoderTests: XCTestCase {

// let's add the framing handler to the pipeline as that's what we're testing here.
XCTAssertNoThrow(
try self.channel.pipeline.addHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameEncoder()).wait()
try self.channel.pipeline.syncOperations.addHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameEncoder())
)
// let's also add the decoder so we can round-trip
XCTAssertNoThrow(
try self.channel.pipeline.addHandler(
try self.channel.pipeline.syncOperations.addHandler(
ByteToMessageHandler(NIOJSONRPCFraming.ContentLengthHeaderFrameDecoder())
).wait()
)
)
// this pretends to connect the channel to this IP address.
XCTAssertNoThrow(self.channel.connect(to: try .init(ipAddress: "1.2.3.4", port: 5678)))
Expand Down
Loading

0 comments on commit e221bf4

Please sign in to comment.