Make use of AUTO_READ to not accept traffic before connection is complete

This commit is contained in:
Norman Maurer 2013-02-17 08:26:06 +01:00
parent 60ee9460a9
commit 2f737d4e70
2 changed files with 5 additions and 4 deletions

View File

@ -16,6 +16,7 @@
package io.netty.example.proxy;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
@ -41,8 +42,8 @@ public class HexDumpProxy {
try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(NioServerSocketChannel.class)
.childHandler(new HexDumpProxyInitializer(remoteHost, remotePort));
.childHandler(new HexDumpProxyInitializer(remoteHost, remotePort))
.childOption(ChannelOption.AUTO_READ, false);
b.bind(localPort).sync().channel().closeFuture().sync();
} finally {
b.shutdown();

View File

@ -54,8 +54,8 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
// Connection attempt succeeded:
// TODO: Begin to accept incoming traffic.
// connection complete start to auto read data
inboundChannel.config().setAutoRead(true);
} else {
// Close the connection if the connection attempt has failed.
inboundChannel.close();