Skip to content

Commit 0e2808c

Browse files
authored
Merge pull request #11 from tanner0101/nio2-ctx-fixes
nio 2 ctx fixes
2 parents 4d9afa5 + 5a831fa commit 0e2808c

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

Sources/NIORedis/ChannelHandlers/RESPDecoder+ByteToMessage.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ extension RESPDecoder: ByteToMessageDecoder {
44
/// `ByteToMessageDecoder.InboundOut`
55
public typealias InboundOut = RESPValue
66

7-
/// See `ByteToMessageDecoder.decode(ctx:buffer:)`
8-
public func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
7+
/// See `ByteToMessageDecoder.decode(context:buffer:)`
8+
public func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
99
var position = 0
1010

1111
switch try parse(at: &position, from: &buffer) {
1212
case .notYetParsed:
1313
return .needMoreData
1414

1515
case .parsed(let RESPValue):
16-
ctx.fireChannelRead(wrapInboundOut(RESPValue))
16+
context.fireChannelRead(wrapInboundOut(RESPValue))
1717
buffer.moveReaderIndex(forwardBy: position)
1818
return .continue
1919
}
2020
}
21+
22+
/// See `ByteToMessageDecoder.decodeLast(context:buffer:seenEOF)`
23+
public func decodeLast(context: ChannelHandlerContext, buffer: inout ByteBuffer, seenEOF: Bool) throws -> DecodingState {
24+
return .needMoreData
25+
}
2126
}

Sources/NIORedis/ChannelHandlers/RESPEncoder+MessageToByte.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ extension RESPEncoder: MessageToByteEncoder {
44
/// See `MessageToByteEncoder.OutboundIn`
55
public typealias OutboundIn = RESPValue
66

7-
/// See `RESPEncoder.encode(ctx:data:out:)`
8-
public func encode(ctx: ChannelHandlerContext, data: RESPValue, out: inout ByteBuffer) throws {
7+
/// See `RESPEncoder.encode(context:data:out:)`
8+
public func encode(context: ChannelHandlerContext, data: RESPValue, out: inout ByteBuffer) throws {
99
out.writeBytes(encode(data))
1010
}
1111
}

Sources/NIORedis/ChannelHandlers/RedisCommandHandler.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ extension RedisCommandHandler: ChannelInboundHandler {
3333
/// Invoked by NIO when an error has been thrown. The command response promise at the front of the queue will be
3434
/// failed with the error.
3535
///
36-
/// See `ChannelInboundHandler.errorCaught(ctx:error:)`
37-
public func errorCaught(ctx: ChannelHandlerContext, error: Error) {
36+
/// See `ChannelInboundHandler.errorCaught(context:error:)`
37+
public func errorCaught(context: ChannelHandlerContext, error: Error) {
3838
guard let leadPromise = commandResponseQueue.last else {
3939
return assertionFailure("Received unexpected error while idle: \(error.localizedDescription)")
4040
}
@@ -44,8 +44,8 @@ extension RedisCommandHandler: ChannelInboundHandler {
4444
/// Invoked by NIO when a read has been fired from earlier in the response chain. This forwards the unwrapped
4545
/// `RESPValue` to the promise awaiting a response at the front of the queue.
4646
///
47-
/// See `ChannelInboundHandler.channelRead(ctx:data:)`
48-
public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
47+
/// See `ChannelInboundHandler.channelRead(context:data:)`
48+
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
4949
let value = unwrapInboundIn(data)
5050

5151
guard let leadPromise = commandResponseQueue.last else {
@@ -74,10 +74,10 @@ extension RedisCommandHandler: ChannelOutboundHandler {
7474
/// This unwraps a `RedisCommandContext`, retaining a callback to forward a response to later, and forwards
7575
/// the underlying command data further into the pipeline.
7676
///
77-
/// See `ChannelOutboundHandler.write(ctx:data:promise:)`
78-
public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
79-
let context = unwrapOutboundIn(data)
80-
commandResponseQueue.insert(context.responsePromise, at: 0)
81-
ctx.write(wrapOutboundOut(context.command), promise: promise)
77+
/// See `ChannelOutboundHandler.write(context:data:promise:)`
78+
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
79+
let commandContext = unwrapOutboundIn(data)
80+
commandResponseQueue.insert(commandContext.responsePromise, at: 0)
81+
context.write(wrapOutboundOut(commandContext.command), promise: promise)
8282
}
8383
}

Sources/NIORedis/Extensions/NIO/ClientBootstrap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension ClientBootstrap {
1717
ByteToMessageHandler(RESPDecoder()),
1818
RedisCommandHandler()
1919
]
20-
return .andAllSucceed(handlers.map { channel.pipeline.add(handler: $0) }, on: group.next())
20+
return .andAllSucceed(handlers.map { channel.pipeline.addHandler($0) }, on: group.next())
2121
}
2222
}
2323
}

Sources/NIORedis/RedisDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public final class RedisDriver {
6868

6969
private extension ChannelPipeline {
7070
func addHandlers(_ handlers: ChannelHandler...) -> EventLoopFuture<Void> {
71-
return .andAllSucceed(handlers.map { add(handler: $0) }, on: eventLoop)
71+
return .andAllSucceed(handlers.map { addHandler($0) }, on: eventLoop)
7272
}
7373
}

Tests/NIORedisTests/ChannelHandlers/RESPDecoder+ByteToMessageDecoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ final class RESPDecoderByteToMessageDecoderTests: XCTestCase {
5858
let embeddedChannel = EmbeddedChannel()
5959
defer { _ = try? embeddedChannel.finish() }
6060
let handler = ByteToMessageHandler(decoder)
61-
try embeddedChannel.pipeline.add(handler: handler).wait()
61+
try embeddedChannel.pipeline.addHandler(handler).wait()
6262
let context = try embeddedChannel.pipeline.context(handler: handler).wait()
6363

6464
buffer.writeString(input)
6565

66-
return try decoder.decode(ctx: context, buffer: &buffer)
66+
return try decoder.decode(context: context, buffer: &buffer)
6767
}
6868
}
6969

Tests/NIORedisTests/ChannelHandlers/RESPDecoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ final class RESPDecoderTests: XCTestCase {
110110
let embeddedChannel = EmbeddedChannel()
111111
defer { _ = try? embeddedChannel.finish() }
112112
let handler = ByteToMessageHandler(decoder)
113-
try embeddedChannel.pipeline.add(handler: handler).wait()
113+
try embeddedChannel.pipeline.addHandler(handler).wait()
114114
var buffer = allocator.buffer(capacity: 256)
115115
buffer.writeBytes(input)
116116
try embeddedChannel.writeInbound(buffer)
@@ -172,7 +172,7 @@ extension RESPDecoderTests {
172172
let embeddedChannel = EmbeddedChannel()
173173
defer { _ = try? embeddedChannel.finish() }
174174
let handler = ByteToMessageHandler(decoder)
175-
try embeddedChannel.pipeline.add(handler: handler).wait()
175+
try embeddedChannel.pipeline.addHandler(handler).wait()
176176

177177
var buffer = allocator.buffer(capacity: 256)
178178
for message in AllData.messages {

Tests/NIORedisTests/ChannelHandlers/RESPEncoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class RESPEncoderTests: XCTestCase {
1313
encoder = RESPEncoder()
1414
allocator = ByteBufferAllocator()
1515
channel = EmbeddedChannel()
16-
_ = try? channel.pipeline.add(handler: encoder).wait()
16+
_ = try? channel.pipeline.addHandler(encoder).wait()
1717
}
1818

1919
override func tearDown() {
@@ -93,7 +93,7 @@ final class RESPEncoderTests: XCTestCase {
9393
let context = try channel.pipeline.context(handler: encoder).wait()
9494

9595
var buffer = allocator.buffer(capacity: 256)
96-
try encoder.encode(ctx: context, data: input, out: &buffer)
96+
try encoder.encode(context: context, data: input, out: &buffer)
9797
validation(buffer)
9898
}
9999
}

0 commit comments

Comments
 (0)