Skip to content

Commit

Permalink
!7 添加心跳检测,防止设备干坏事
Browse files Browse the repository at this point in the history
Merge pull request !7 from zhansheng/N/A
  • Loading branch information
glaciall authored and gitee-org committed Jul 7, 2021
2 parents 55d4b1e + a1ead9b commit a12a702
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/cn/org/hentai/jtt1078/server/Jtt1078Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import io.netty.util.AttributeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

/**
* Created by matrixy on 2019/4/9.
Expand Down Expand Up @@ -88,6 +89,18 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
ctx.close();
}

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.READER_IDLE) {
String tag = SessionManager.get(ctx.channel(), "tag");
logger.info("read timeout: {}",tag);
release(ctx.channel());
}
}
}

private void release(io.netty.channel.Channel channel)
{
String tag = SessionManager.get(channel, "tag");
Expand Down

0 comments on commit a12a702

Please sign in to comment.