Remove no needed return statements and cleanup examples.

Motivation:

We do not need to use return in the closures used in the examples.

Modifications:

- Remove return
- Remove bug where we set the same channel option two times in one example

Result:

Cleaner code.
This commit is contained in:
Norman Maurer 2018-02-16 10:50:57 +01:00
parent 0e7b90ef16
commit 3f4a755de1
5 changed files with 8 additions and 9 deletions

View File

@ -25,8 +25,8 @@
/// // Set the handlers that are appled to the accepted child `Channel`s.
/// .childChannelInitializer { channel in
/// // Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
/// return channel.pipeline.add(handler: BackPressureHandler()).then { () in
/// return channel.pipeline.add(handler: MyChannelHandler())
/// channel.pipeline.add(handler: BackPressureHandler()).then { () in
/// channel.pipeline.add(handler: MyChannelHandler())
/// }
/// }
///

View File

@ -122,9 +122,9 @@ let bootstrap = ServerBootstrap(group: group)
// Set the handlers that are appled to the accepted Channels
.childChannelInitializer { channel in
// Add handler that will buffer data until a \n is received
return channel.pipeline.add(handler: LineDelimiterCodec()).then { v in
channel.pipeline.add(handler: LineDelimiterCodec()).then { v in
// Its important we use the same handler for all accepted channels. The ChatHandler is thread-safe!
return channel.pipeline.add(handler: chatHandler)
channel.pipeline.add(handler: chatHandler)
}
}

View File

@ -54,7 +54,6 @@ private final class EchoHandler: ChannelInboundHandler {
let group = MultiThreadedEventLoopGroup(numThreads: 1)
let bootstrap = ClientBootstrap(group: group)
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
// Enable SO_REUSEADDR.
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
.channelInitializer { channel in

View File

@ -49,8 +49,8 @@ let bootstrap = ServerBootstrap(group: group)
// Set the handlers that are appled to the accepted Channels
.childChannelInitializer { channel in
// Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
return channel.pipeline.add(handler: BackPressureHandler()).then { v in
return channel.pipeline.add(handler: EchoHandler())
channel.pipeline.add(handler: BackPressureHandler()).then { v in
channel.pipeline.add(handler: EchoHandler())
}
}

View File

@ -395,8 +395,8 @@ let bootstrap = ServerBootstrap(group: group)
// Set the handlers that are applied to the accepted Channels
.childChannelInitializer { channel in
return channel.pipeline.addHTTPServerHandlers().then { _ in
return channel.pipeline.add(handler: HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
channel.pipeline.addHTTPServerHandlers().then { _ in
channel.pipeline.add(handler: HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
}
}