ChannelHandlerContext.connect shouldn't bind

This commit is contained in:
Cory Benfield committed 2017-09-15 09:29:59 +01:00
1 parent 5289094a36
commit bcdbe4bc46
3 files changed
+32 -1

No files matched your search

+1 -1
View File
@@ -712,7 +712,7 @@ public final class ChannelHandlerContext : ChannelInvoker {
}
public func connect(to address: SocketAddress, promise: Promise<Void>?) {
outboundNext!.invokeBind(to: address, promise: promise)
outboundNext!.invokeConnect(to: address, promise: promise)
}
public func write(data: IOData, promise: Promise<Void>?) {
@@ -28,6 +28,7 @@ extension ChannelPipelineTest {
return [
("testAddAfterClose", testAddAfterClose),
("testOutboundOrdering", testOutboundOrdering),
("testConnectingDoesntCallBind", testConnectingDoesntCallBind),
]
}
}
+30
View File
@@ -76,6 +76,23 @@ class ChannelPipelineTest: XCTestCase {
}
func testConnectingDoesntCallBind() throws {
let channel = EmbeddedChannel()
var ipv4SocketAddress = sockaddr_in()
ipv4SocketAddress.sin_port = (12345 as UInt16).bigEndian
let sa = SocketAddress(IPv4Address: ipv4SocketAddress, host: "foobar.com")
_ = try channel.pipeline.add(handler: NoBindAllowed()).wait()
_ = try channel.pipeline.add(handler: TestChannelOutboundHandler<ByteBuffer, ByteBuffer>({ data in
return data
})).wait()
_ = try channel.connect(to: sa).wait()
_ = try channel.close().wait()
return
}
private final class TestChannelOutboundHandler<In, Out>: ChannelOutboundHandler {
typealias OutboundIn = In
typealias OutboundOut = Out
@@ -94,4 +111,17 @@ class ChannelPipelineTest: XCTestCase {
}
}
}
private final class NoBindAllowed: ChannelOutboundHandler {
typealias OutboundIn = ByteBuffer
typealias OutboundOut = ByteBuffer
enum TestFailureError: Error {
case CalledBind
}
public func bind(ctx: ChannelHandlerContext, to address: SocketAddress, promise: Promise<Void>?) {
promise!.fail(error: TestFailureError.CalledBind)
}
}
}