flush
Send a flush
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the flush
event reaches the HeadChannelHandler
the data previously enqueued will be attempted to be written to the socket.
func flush()
Send a flush
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the flush
event reaches the HeadChannelHandler
the data previously enqueued will be attempted to be written to the socket.
func flush()
import NIOCore
The core abstractions that make up SwiftNIO.
final class ChannelHandlerContext
Every ChannelHandler
has – when added to a ChannelPipeline
– a corresponding ChannelHandlerContext
which is the way ChannelHandler
s can interact with other ChannelHandler
s in the pipeline.
var channel: Channel { get }
var eventLoop: EventLoop { get }
var handler: ChannelHandler { get }
var localAddress: SocketAddress? { get }
var loopBound: NIOLoopBound<ChannelHandlerContext> { get }
Returns this ChannelHandlerContext
as a NIOLoopBound
, bound to self.eventLoop
.
let name: String
let pipeline: ChannelPipeline
var remoteAddress: SocketAddress? { get }
func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Send a bind
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the bind
event reaches the HeadChannelHandler
a ServerSocketChannel
will be bound.
func close(mode: CloseMode = .all, promise: EventLoopPromise<Void>?)
Send a close
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the close
event reaches the HeadChannelHandler
the socket will be closed.
func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)
Send a connect
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the connect
event reaches the HeadChannelHandler
a SocketChannel
will be connected.
func fireChannelActive()
Send a channelActive
event to the next (inbound) ChannelHandler
in the ChannelPipeline
.
func fireChannelInactive()
Send a channelInactive
event to the next (inbound) ChannelHandler
in the ChannelPipeline
.
func fireChannelRead(_ data: NIOAny)
Send data to the next inbound ChannelHandler
. The data should be of type ChannelInboundHandler.InboundOut
.
func fireChannelReadComplete()
Signal to the next ChannelHandler
that a read burst has finished.
func fireChannelRegistered()
Send a channelRegistered
event to the next (inbound) ChannelHandler
in the ChannelPipeline
.
func fireChannelUnregistered()
Send a channelUnregistered
event to the next (inbound) ChannelHandler
in the ChannelPipeline
.
func fireChannelWritabilityChanged()
Send a writabilityChanged
event to the next (inbound) ChannelHandler
in the ChannelPipeline
.
func fireErrorCaught(_ error: Error)
Send an error to the next inbound ChannelHandler
.
func fireUserInboundEventTriggered(_ event: Any)
Send a user event to the next inbound ChannelHandler
from on the event loop.
func leavePipeline(removalToken: RemovalToken)
Synchronously remove the ChannelHandler
with the given ChannelHandlerContext
.
func read()
Send a read
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the read
event reaches the HeadChannelHandler
the interest to read data will be signalled to the Selector
. This will subsequently – when data becomes readable – cause channelRead
events containing the data being sent through the ChannelPipeline
.
func register(promise: EventLoopPromise<Void>?)
Send a register
event to the next (outbound) ChannelHandler
in the ChannelPipeline
.
func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?)
Send a user event to the next outbound ChannelHandler
in the ChannelPipeline
.
func write(_ data: NIOAny, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Void>
Write data to the remote peer.
func write(_ data: NIOAny, promise: EventLoopPromise<Void>?)
Send a write
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the write
event reaches the HeadChannelHandler
the data will be enqueued to be written on the next flush
event.
func writeAndFlush(_ data: NIOAny, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Void>
Shortcut for calling write
and flush
.
func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?)
Send a write
event followed by a flush
event to the next outbound ChannelHandler
in the ChannelPipeline
. When the write
event reaches the HeadChannelHandler
the data will be enqueued to be written when the flush
also reaches the HeadChannelHandler
.
struct RemovalToken
A RemovalToken
is handed to a RemovableChannelHandler
when its removeHandler
function is invoked. A RemovableChannelHandler
is then required to remove itself from the ChannelPipeline
. The removal process is finalized by handing the RemovalToken
to the ChannelHandlerContext.leavePipeline
function.
func fireUserInboundEventTriggered(_ event: Sendable)
Send a user event to the next inbound ChannelHandler
.
func triggerUserOutboundEvent(_ event: Sendable, promise: EventLoopPromise<Void>?)
Send a user event to the next outbound ChannelHandler
in the ChannelPipeline
.