我用netty做一个文件传输,当客户端下载文件时,服务端传文件。服务端传文件的代码如下:
final ChunkedStream chunkedStream = new ChunkedStream(fis);
ctx.channel().writeAndFlush(chunkedStream).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if(!future.isSuccess()) {
logger.debug("File send timeout");
}
if (ctx != null ) {
if (ctx.channel().isActive()) {
System.out.println("close again?");
ctx.close();
}
}
if (chunkedStream != null) {
chunkedStream.close();
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
});
问题出现在以下场景:我写了一个下载超时控制的handler,当超过指定时间