Skip to content

Commit

Permalink
新的API一些调整
Browse files Browse the repository at this point in the history
准备发3.3.6了
  • Loading branch information
tywo45 committed Jul 25, 2019
1 parent 0821ea0 commit c3647b2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/src/main/java/org/tio/core/stat/ChannelStat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tio.core.stat;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.tio.utils.SystemTimer;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class ChannelStat implements java.io.Serializable {
/**
* 心跳超时次数
*/
public int heartbeatTimeoutCount = 0;
public AtomicInteger heartbeatTimeoutCount = new AtomicInteger();

/**
* 平均每次TCP接收到的字节数,这个可以用来监控慢攻击,配置PacketsPerTcpReceive定位慢攻击
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public void run() {
}

if (needRemove) {
channelContext.stat.heartbeatTimeoutCount++;
if (!serverAioListener.onHeartbeatTimeout(channelContext, interval, channelContext.stat.heartbeatTimeoutCount)) {
if (!serverAioListener.onHeartbeatTimeout(channelContext, interval, channelContext.stat.heartbeatTimeoutCount.incrementAndGet())) {
log.info("{}, {} ms没有收发消息", channelContext, interval);
channelContext.setCloseCode(CloseCode.HEARTBEAT_TIMEOUT);
Tio.remove(channelContext, interval + " ms没有收发消息");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface ServerAioListener extends AioListener {
* 服务器检查到心跳超时时,会调用这个函数
* @param channelContext
* @param interval 已经多久没有收发消息了,单位:毫秒
* @param heartbeatTimeoutCount 心跳超时次数,第一次超时此值是1,以此类推
* @param heartbeatTimeoutCount 心跳超时次数,第一次超时此值是1,以此类推。此值被保存在:channelContext.stat.heartbeatTimeoutCount
* @return 返回true,那么服务器则不关闭此连接;返回false,服务器将按心跳超时关闭该连接
*/
public boolean onHeartbeatTimeout(ChannelContext channelContext, Long interva, int heartbeatTimeoutCount);
Expand Down

0 comments on commit c3647b2

Please sign in to comment.