Make use of AUTO_READ to not accept traffic before connection is complete
This commit is contained in:
parent
60ee9460a9
commit
2f737d4e70
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user