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 the EventLoopGroup group.

    The EventLoopGroup group must be compatible, otherwise the program will crash. NIOPipeBootstrap is compatible only with MultiThreadedEventLoopGroup as well as the EventLoops returned by MultiThreadedEventLoopGroup.next. See init(validatingGroup:) for a fallible initializer for situations where it’s impossible to tell ahead of time if the EventLoopGroups are compatible or not.

    Declaration

    Swift

    public convenience init(group: EventLoopGroup)

    Parameters

    group

    The EventLoopGroup to use.

  • Create a NIOPipeBootstrap on the EventLoopGroup group, validating that group is compatible.

    Declaration

    Swift

    public init?(validatingGroup group: EventLoopGroup)

    Parameters

    group

    The EventLoopGroup to use.

  • Initialize the connected PipeChannel with initializer. The most common task in initializer is to add ChannelHandlers to the ChannelPipeline.

    The connected Channel will operate on ByteBuffer as inbound and outbound messages. Please note that IOData.fileRegion is not supported for PipeChannels because sendfile 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 the PipeChannel.

    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 the Channel becomes inactive. You must not do any further operations with fileDescriptor, including close. 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 the Channel.

  • 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 or NIOPipeBootstrap.withInputOutputDescriptor if it is not a socket.

    Note

    If this method returns a succeeded future, SwiftNIO will close inputDescriptor and outputDescriptor when the Channel becomes inactive. You must not do any further operations inputDescriptor or outputDescriptor, including close. 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 the Channel.