NIOPipeBootstrap
public final class NIOPipeBootstrap
A NIOPipeBootstrap
is an easy way to bootstrap a PipeChannel
which uses two (uni-directional) UNIX pipes
and makes a Channel
out of them.
Example bootstrapping a Channel
using stdin
and stdout
:
let channel = try NIOPipeBootstrap(group: group)
.channelInitializer { channel in
channel.pipeline.addHandler(MyChannelHandler())
}
.withPipes(inputDescriptor: STDIN_FILENO, outputDescriptor: STDOUT_FILENO)
-
Create a
NIOPipeBootstrap
on theEventLoopGroup
group
.The
EventLoopGroup
group
must be compatible, otherwise the program will crash.NIOPipeBootstrap
is compatible only withMultiThreadedEventLoopGroup
as well as theEventLoop
s returned byMultiThreadedEventLoopGroup.next
. Seeinit(validatingGroup:)
for a fallible initializer for situations where it’s impossible to tell ahead of time if theEventLoopGroup
s are compatible or not.Declaration
Swift
public convenience init(group: EventLoopGroup)
Parameters
group
The
EventLoopGroup
to use. -
Create a
NIOPipeBootstrap
on theEventLoopGroup
group
, validating thatgroup
is compatible.Declaration
Swift
public init?(validatingGroup group: EventLoopGroup)
Parameters
group
The
EventLoopGroup
to use. -
Initialize the connected
PipeChannel
withinitializer
. The most common task in initializer is to addChannelHandler
s to theChannelPipeline
.The connected
Channel
will operate onByteBuffer
as inbound and outbound messages. Please note thatIOData.fileRegion
is not supported forPipeChannel
s becausesendfile
only works on sockets.Declaration
Swift
public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<Void>) -> Self
Parameters
handler
A closure that initializes the provided
Channel
. -
Specifies a
ChannelOption
to be applied to thePipeChannel
.Declaration
Swift
@inlinable public func channelOption<Option>(_ option: Option, value: Option.Value) -> Self where Option : ChannelOption
Parameters
option
The option to be applied.
value
The value for the option.
-
Create the
PipeChannel
with the provided file descriptor which is used for both input & output.This method is useful for specialilsed use-cases where you want to use
NIOPipeBootstrap
for say a serial line.Note
If this method returns a succeeded future, SwiftNIO will close
fileDescriptor
when theChannel
becomes inactive. You must not do any further operations withfileDescriptor
, includingclose
. If this method returns a failed future, you still own the file descriptor and are responsible for closing it.Declaration
Swift
public func withInputOutputDescriptor(_ fileDescriptor: CInt) -> EventLoopFuture<Channel>
Parameters
fileDescriptor
The Unix file descriptor for the input & output.
Return Value
an
EventLoopFuture<Channel>
to deliver theChannel
. -
Create the
PipeChannel
with the provided input and output file descriptors.The input and output file descriptors must be distinct. If you have a single file descriptor, consider using
ClientBootstrap.withConnectedSocket(descriptor:)
if it’s a socket orNIOPipeBootstrap.withInputOutputDescriptor
if it is not a socket.Note
If this method returns a succeeded future, SwiftNIO will close
inputDescriptor
andoutputDescriptor
when theChannel
becomes inactive. You must not do any further operationsinputDescriptor
oroutputDescriptor
, includingclose
. If this method returns a failed future, you still own the file descriptors and are responsible for closing them.Declaration
Swift
public func withPipes(inputDescriptor: CInt, outputDescriptor: CInt) -> EventLoopFuture<Channel>
Parameters
inputDescriptor
The Unix file descriptor for the input (ie. the read side).
outputDescriptor
The Unix file descriptor for the output (ie. the write side).
Return Value
an
EventLoopFuture<Channel>
to deliver theChannel
.