_channelCore
Embedded.swift:777var _channelCore: any ChannelCore { get }
see:
Channel._channelCore
var _channelCore: any ChannelCore { get }
s11NIOEmbedded15EmbeddedChannelC12_channelCore7NIOCore0cE0_pvp
What are these?23IE5
see: Channel._channelCore
import NIOEmbedded
final class EmbeddedChannel
EmbeddedChannel
is a Channel
implementation that does neither any actual IO nor has a proper eventing mechanism. The prime use-case for EmbeddedChannel
is in unit tests when you want to feed the inbound events and check the outbound events manually.
protocol ChannelCore : AnyObject
The core Channel
methods that are for internal use of the Channel
implementation only.
convenience init(handler: (any ChannelHandler)? = nil, loop: EmbeddedEventLoop = EmbeddedEventLoop())
Create a new instance.
init(handlers: [any ChannelHandler], loop: EmbeddedEventLoop = EmbeddedEventLoop())
Create a new instance.
var allocator: ByteBufferAllocator
var allowRemoteHalfClosure: Bool { get set }
var closeFuture: EventLoopFuture<Void> { get }
var embeddedEventLoop: EmbeddedEventLoop
Returns the EmbeddedEventLoop
that this EmbeddedChannel
uses. This will return the same instance as EmbeddedChannel.eventLoop
but as the concrete EmbeddedEventLoop
rather than as EventLoop
existential.
var eventLoop: any EventLoop { get }
var isActive: Bool { get }
Returns true
if the EmbeddedChannel
is ‘active’.
var isWritable: Bool
var localAddress: SocketAddress? { get set }
let parent: (any Channel)?
nil
because EmbeddedChannel
s don’t have parents.
var pipeline: ChannelPipeline { get }
var remoteAddress: SocketAddress? { get set }
final var syncOptions: (any NIOSynchronousChannelOptions)? { get }
func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) bind
event through the ChannelPipeline
. If the event hits the EmbeddedChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the EmbeddedChannel
’s localAddress
.
func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Fires the (outbound) connect
event through the ChannelPipeline
. If the event hits the EmbeddedChannel
which happens when it travels the ChannelPipeline
all the way to the front, this will also set the EmbeddedChannel
’s remoteAddress
.
func finish() throws -> EmbeddedChannel.LeftOverState
Synchronously closes the EmbeddedChannel
.
func finish(acceptAlreadyClosed: Bool) throws -> EmbeddedChannel.LeftOverState
Synchronously closes the EmbeddedChannel
.
func getOption<Option>(_ option: Option) -> EventLoopFuture<Option.Value> where Option : ChannelOption
func readInbound<T>(as type: T.Type = T.self) throws -> T?
If available, this method reads one element of type T
out of the EmbeddedChannel
’s inbound buffer. If the first element was of a different type than requested, EmbeddedChannel.WrongTypeError
will be thrown, if there are no elements in the outbound buffer, nil
will be returned.
func readOutbound<T>(as type: T.Type = T.self) throws -> T?
If available, this method reads one element of type T
out of the EmbeddedChannel
’s outbound buffer. If the first element was of a different type than requested, EmbeddedChannel.WrongTypeError
will be thrown, if there are no elements in the outbound buffer, nil
will be returned.
func setOption<Option>(_ option: Option, value: Option.Value) -> EventLoopFuture<Void> where Option : ChannelOption
func throwIfErrorCaught() throws
This method will throw the error that is stored in the EmbeddedChannel
if any.
func write<T>(_ data: T) -> EventLoopFuture<Void>
An overload of Channel.write
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func write<T>(_ data: T, promise: EventLoopPromise<Void>?)
An overload of Channel.write
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func writeAndFlush<T>(_ data: T) -> EventLoopFuture<Void>
An overload of Channel.writeAndFlush
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
func writeAndFlush<T>(_ data: T, promise: EventLoopPromise<Void>?)
An overload of Channel.writeAndFlush
that does not require a Sendable type, as EmbeddedEventLoop
is bound to a single thread.
@discardableResult func writeInbound<T>(_ data: T) throws -> EmbeddedChannel.BufferState
Sends an inbound channelRead
event followed by a channelReadComplete
event through the ChannelPipeline
.
@discardableResult func writeOutbound<T>(_ data: T) throws -> EmbeddedChannel.BufferState
Sends an outbound writeAndFlush
event through the ChannelPipeline
.
enum BufferState
BufferState
represents the state of either the inbound, or the outbound EmbeddedChannel
buffer. These buffers contain data that travelled the ChannelPipeline
all the way.
enum LeftOverState
LeftOverState
represents any left-over inbound, outbound, and pending outbound events that hit the EmbeddedChannel
and were not consumed when finish
was called on the EmbeddedChannel
.
struct SynchronousOptions
struct WrongTypeError
WrongTypeError
is throws if you use readInbound
or readOutbound
and request a certain type but the first item in the respective buffer is of a different type.