From 3c8caab5b60d8fdeb5e4d045b0721557f2d44384 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 21 Mar 2018 15:44:32 +0100 Subject: [PATCH] Add some docs to note on which message types a bootstrapped Channel will operate. (#207) Motivation: It's not clear to a user which inbound / outbound messages is expected for the different Channel implementations. This can result into wrong code and confused users. Modifications: Add some docs to explain which messages are supported / expected by the different Channels that can be bootstrapped. Result: More clear docs. --- Sources/NIO/Bootstrap.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/NIO/Bootstrap.swift b/Sources/NIO/Bootstrap.swift index 0ffcc7824..2c758a1c5 100644 --- a/Sources/NIO/Bootstrap.swift +++ b/Sources/NIO/Bootstrap.swift @@ -45,6 +45,12 @@ /// try! channel.closeFuture.wait() // wait forever as we never close the Channel /// ``` /// +/// The `EventLoopFuture` returned by `bind` will fire with a `ServerSocketChannel`. This is the channel that owns the listening socket. +/// Each time it accepts a new connection it will fire a `SocketChannel` through the `ChannelPipeline` via `fireChannelRead`: as a result, +/// the `ServerSocketChannel` operates on `Channel`s as inbound messages. Outbound messages are not supported on a `ServerSocketChannel` +/// which means that each write attempt will fail. +/// +/// Accepted `SocketChannel`s operate on `ByteBuffer` as inbound data, and `IOData` as outbound data. public final class ServerBootstrap { private let group: EventLoopGroup @@ -75,6 +81,8 @@ public final class ServerBootstrap { /// Initialize the `ServerSocketChannel` with `initializer`. The most common task in initializer is to add /// `ChannelHandler`s to the `ChannelPipeline`. /// + /// The `ServerSocketChannel` uses the accepted `Channel`s as inbound messages. + /// /// - note: To set the initializer for the accepted `SocketChannel`s, look at `ServerBootstrap.childChannelInitializer`. /// /// - parameters: @@ -87,6 +95,8 @@ public final class ServerBootstrap { /// Initialize the accepted `SocketChannel`s with `initializer`. The most common task in initializer is to add /// `ChannelHandler`s to the `ChannelPipeline`. /// + /// The accepted `Channel` will operate on `ByteBuffer` as inbound and `IOData` as outbound messages. + /// /// - parameters: /// - initializer: A closure that initializes the provided `Channel`. public func childChannelInitializer(_ initializer: @escaping (Channel) -> EventLoopFuture<()>) -> Self { @@ -254,6 +264,7 @@ public final class ServerBootstrap { /// /* the Channel is now connected */ /// ``` /// +/// The connected `SocketChannel` will operate on `ByteBuffer` as inbound and on `IOData` as outbound messages. public final class ClientBootstrap { private let group: EventLoopGroup @@ -273,6 +284,8 @@ public final class ClientBootstrap { /// Initialize the connected `SocketChannel` with `initializer`. The most common task in initializer is to add /// `ChannelHandler`s to the `ChannelPipeline`. /// + /// The connected `Channel` will operate on `ByteBuffer` as inbound and `IOData` as outbound messages. + /// /// - parameters: /// - handler: A closure that initializes the provided `Channel`. public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<()>) -> Self { @@ -410,6 +423,7 @@ public final class ClientBootstrap { /// try channel.closeFuture.wait() // Wait until the channel un-binds. /// ``` /// +/// The `DatagramChannel` will operate on `AddressedEnvelope` as inbound and outbound messages. public final class DatagramBootstrap { private let group: EventLoopGroup