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;
|
package io.netty.example.proxy;
|
||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
|
||||||
@ -41,8 +42,8 @@ public class HexDumpProxy {
|
|||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
|
||||||
.channel(NioServerSocketChannel.class)
|
.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();
|
b.bind(localPort).sync().channel().closeFuture().sync();
|
||||||
} finally {
|
} finally {
|
||||||
b.shutdown();
|
b.shutdown();
|
||||||
|
@ -54,8 +54,8 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte
|
|||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
// Connection attempt succeeded:
|
// connection complete start to auto read data
|
||||||
// TODO: Begin to accept incoming traffic.
|
inboundChannel.config().setAutoRead(true);
|
||||||
} else {
|
} else {
|
||||||
// Close the connection if the connection attempt has failed.
|
// Close the connection if the connection attempt has failed.
|
||||||
inboundChannel.close();
|
inboundChannel.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user