mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
Let writeInbound and writeOutbound signal if something was put in the buffer to consume and update the tests
This commit is contained in:
1 parent
2d235020d0
commit
9d535bad22
2 files changed
+9
-9
No files matched your search
@@ -175,21 +175,23 @@ public class EmbeddedChannel : Channel {
|
||||
public var remoteAddress: SocketAddress? = nil
|
||||
|
||||
public func readOutbound<T>() -> T? {
|
||||
return readFromBuffer(buffer: &(_unsafe as! EmbeddedChannelCore).outboundBuffer)
|
||||
return readFromBuffer(buffer: &channelcore.outboundBuffer)
|
||||
}
|
||||
|
||||
public func readInbound<T>() -> T? {
|
||||
return readFromBuffer(buffer: &(_unsafe as! EmbeddedChannelCore).inboundBuffer)
|
||||
return readFromBuffer(buffer: &channelcore.inboundBuffer)
|
||||
}
|
||||
|
||||
public func writeInbound<T>(data: T) throws {
|
||||
@discardableResult public func writeInbound<T>(data: T) throws -> Bool {
|
||||
pipeline.fireChannelRead(data: IOData(data))
|
||||
pipeline.fireChannelReadComplete()
|
||||
try throwIfErrorCaught()
|
||||
return !channelcore.inboundBuffer.isEmpty
|
||||
}
|
||||
|
||||
public func writeOutbound<T>(data: T) throws {
|
||||
@discardableResult public func writeOutbound<T>(data: T) throws -> Bool {
|
||||
try writeAndFlush(data: IOData(data)).wait()
|
||||
return !channelcore.outboundBuffer.isEmpty
|
||||
}
|
||||
|
||||
private func throwIfErrorCaught() throws {
|
||||
|
||||
@@ -21,7 +21,7 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
var buf = channel.allocator.buffer(capacity: 1024)
|
||||
buf.write(string: "hello")
|
||||
|
||||
try channel.writeOutbound(data: buf)
|
||||
XCTAssertTrue(try channel.writeOutbound(data: buf))
|
||||
XCTAssertTrue(try channel.finish())
|
||||
XCTAssertEqual(buf, channel.readOutbound())
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
@@ -33,7 +33,7 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
var buf = channel.allocator.buffer(capacity: 1024)
|
||||
buf.write(string: "hello")
|
||||
|
||||
try channel.writeInbound(data: buf)
|
||||
XCTAssertTrue(try channel.writeInbound(data: buf))
|
||||
XCTAssertTrue(try channel.finish())
|
||||
XCTAssertEqual(buf, channel.readInbound())
|
||||
XCTAssertNil(channel.readInbound())
|
||||
@@ -44,13 +44,12 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
let channel = EmbeddedChannel()
|
||||
_ = try channel.pipeline.add(handler: ExceptionThrowingInboundHandler()).wait()
|
||||
do {
|
||||
try channel.writeInbound(data: "msg")
|
||||
try channel.writeInbound(data: "msg")
|
||||
XCTFail()
|
||||
} catch let err {
|
||||
XCTAssertEqual(ChannelError.messageUnsupported, err as! ChannelError)
|
||||
}
|
||||
XCTAssertFalse(try channel.finish())
|
||||
|
||||
}
|
||||
|
||||
func testWriteOutboundByteBufferReThrow() throws {
|
||||
@@ -63,7 +62,6 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
XCTAssertEqual(ChannelError.messageUnsupported, err as! ChannelError)
|
||||
}
|
||||
XCTAssertFalse(try channel.finish())
|
||||
|
||||
}
|
||||
|
||||
private final class ExceptionThrowingInboundHandler : ChannelInboundHandler {
|
||||
|
||||
Reference in new issue
Block a user