mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-29 05:24:23 +00:00
Bring up-to-date with NIO latest
This commit is contained in:
1 parent
eb8339bda3
commit
044b978525
2 files changed
+28
-11
No files matched your search
@@ -53,7 +53,7 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
|
||||
public func handlerAdded(ctx: ChannelHandlerContext) {
|
||||
// If this channel is already active, immediately begin handshaking.
|
||||
if ctx.channel!.isActive {
|
||||
if ctx.channel.isActive {
|
||||
doHandshakeStep(ctx: ctx)
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
// We didn't deliver data. If this channel has got autoread turned off then we should
|
||||
// call read again, because otherwise the user will never see any result from their
|
||||
// read call.
|
||||
let autoRead = try! ctx.channel!.getOption(option: ChannelOptions.autoRead)
|
||||
let autoRead = try! ctx.channel.getOption(option: ChannelOptions.autoRead)
|
||||
if !autoRead {
|
||||
ctx.read(promise: nil)
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
/// no more available.
|
||||
private func doDecodeData(ctx: ChannelHandlerContext) {
|
||||
readLoop: while true {
|
||||
let result = connection.readDataFromNetwork(allocator: ctx.channel!.allocator)
|
||||
let result = connection.readDataFromNetwork(allocator: ctx.channel.allocator)
|
||||
|
||||
switch result {
|
||||
case .complete(let buf):
|
||||
@@ -276,11 +276,11 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
/// is intended.
|
||||
private func writeDataToNetwork(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
|
||||
// There may be no data to write, in which case we can just exit early.
|
||||
guard let dataToWrite = connection.getDataForNetwork(allocator: ctx.channel!.allocator) else {
|
||||
guard let dataToWrite = connection.getDataForNetwork(allocator: ctx.channel.allocator) else {
|
||||
if let promise = promise {
|
||||
// If we have a promise, we need to enforce ordering so we issue a zero-length write that
|
||||
// the event loop will have to handle.
|
||||
let buffer = ctx.channel!.allocator.buffer(capacity: 0)
|
||||
let buffer = ctx.channel.allocator.buffer(capacity: 0)
|
||||
ctx.writeAndFlush(data: wrapInboundOut(buffer), promise: promise)
|
||||
}
|
||||
return
|
||||
@@ -310,7 +310,7 @@ public class OpenSSLHandler : ChannelInboundHandler, ChannelOutboundHandler {
|
||||
|
||||
// If there is no remote address, something weird is happening here. We can't
|
||||
// validate a certificate without it, so bail.
|
||||
guard let ipAddress = ctx.channel?.remoteAddress else {
|
||||
guard let ipAddress = ctx.channel.remoteAddress else {
|
||||
throw NIOOpenSSLError.cannotFindPeerIP
|
||||
}
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
}
|
||||
|
||||
try clientChannel.flush().wait()
|
||||
let writeCount = try readPromise.futureResult.then { _ in
|
||||
let writeCount = try readPromise.futureResult.map { _ in
|
||||
// Here we're in the I/O loop, so we know that no further channel action will happen
|
||||
// while we dispatch this callback. This is the perfect time to check how many writes
|
||||
// happened.
|
||||
@@ -678,11 +678,11 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
var originalBuffer = clientChannel.allocator.buffer(capacity: 5)
|
||||
originalBuffer.write(string: "Hello")
|
||||
let writeFuture = clientChannel.writeAndFlush(data: NIOAny(originalBuffer))
|
||||
let errorsFuture: EventLoopFuture<[NIOOpenSSLError]> = writeFuture.thenIfError { _ in
|
||||
let errorsFuture: EventLoopFuture<[NIOOpenSSLError]> = writeFuture.mapIfError { _ in
|
||||
// We're swallowing errors here, on purpose, because we'll definitely
|
||||
// hit them.
|
||||
return ()
|
||||
}.then { _ in
|
||||
}.map { _ in
|
||||
return errorHandler.errors
|
||||
}
|
||||
let actualErrors = try errorsFuture.wait()
|
||||
@@ -730,6 +730,11 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
func testDontLoseClosePromises() throws {
|
||||
let serverChannel = EmbeddedChannel()
|
||||
let clientChannel = EmbeddedChannel()
|
||||
defer {
|
||||
// We know this will throw.
|
||||
_ = try? serverChannel.finish()
|
||||
_ = try? clientChannel.finish()
|
||||
}
|
||||
|
||||
let ctx = try configuredSSLContext()
|
||||
|
||||
@@ -763,6 +768,11 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
XCTFail("Unexpected result: \($0)")
|
||||
}
|
||||
}
|
||||
|
||||
// Now clean up the client channel. We need to also fire the channel inactive here as there is
|
||||
// no-one left for the client channel to hang up on.
|
||||
_ = clientChannel.close()
|
||||
clientChannel.pipeline.fireChannelInactive()
|
||||
}
|
||||
|
||||
func testTrustStoreOnDisk() throws {
|
||||
@@ -837,11 +847,11 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
var originalBuffer = clientChannel.allocator.buffer(capacity: 5)
|
||||
originalBuffer.write(string: "Hello")
|
||||
let writeFuture = clientChannel.writeAndFlush(data: NIOAny(originalBuffer))
|
||||
let errorsFuture: EventLoopFuture<[NIOOpenSSLError]> = writeFuture.thenIfError { _ in
|
||||
let errorsFuture: EventLoopFuture<[NIOOpenSSLError]> = writeFuture.mapIfError { _ in
|
||||
// We're swallowing errors here, on purpose, because we'll definitely
|
||||
// hit them.
|
||||
return ()
|
||||
}.then { _ in
|
||||
}.map { _ in
|
||||
return errorHandler.errors
|
||||
}
|
||||
let actualErrors = try errorsFuture.wait()
|
||||
@@ -938,6 +948,10 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
func testZeroLengthWritePromisesFireInOrder() throws {
|
||||
let serverChannel = EmbeddedChannel()
|
||||
let clientChannel = EmbeddedChannel()
|
||||
defer {
|
||||
_ = try? serverChannel.finish()
|
||||
_ = try? clientChannel.finish()
|
||||
}
|
||||
|
||||
let ctx = try configuredSSLContext()
|
||||
|
||||
@@ -979,5 +993,8 @@ class OpenSSLIntegrationTest: XCTestCase {
|
||||
XCTAssertEqual(writeCount, 0)
|
||||
writeDelayer.forceFlush()
|
||||
XCTAssertEqual(writeCount, 3)
|
||||
|
||||
serverChannel.pipeline.fireChannelInactive()
|
||||
clientChannel.pipeline.fireChannelInactive()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user