()
| 875 | } |
| 876 | |
| 877 | private void checkKeepAlive() throws Exception { |
| 878 | var conf = getConfig().getHandshakeOptions(); |
| 879 | var keepRecvTimeout = conf.getKeepRecvTimeout() > 0 ? conf.getKeepRecvTimeout() : Integer.MAX_VALUE; |
| 880 | var keepSendTimeout = conf.getKeepSendTimeout() > 0 ? conf.getKeepSendTimeout() : Integer.MAX_VALUE; |
| 881 | int now = (int)GlobalTimer.getCurrentSeconds(); |
| 882 | foreach(socket -> { |
| 883 | if (socket instanceof TcpSocket) { |
| 884 | int recvTime = now - socket.getActiveRecvTime(); |
| 885 | if (recvTime > keepRecvTimeout) { |
| 886 | try { |
| 887 | onKeepAliveTimeout(socket); |
| 888 | } catch (Exception e) { |
| 889 | logger.error("onKeepAliveTimeout exception:", e); |
| 890 | } |
| 891 | } |
| 892 | if (socket.getType() == AsyncSocket.Type.eClient && (now - socket.getActiveSendTime() > keepSendTimeout || |
| 893 | recvTime > keepSendTimeout)) { // 上次接收时间超过SendTimeout也要发起KeepAlive,通过RPC回复更新上次接收时间 |
| 894 | try { |
| 895 | onSendKeepAlive(socket); |
| 896 | } catch (Exception e) { |
| 897 | logger.error("onSendKeepAlive exception:", e); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | }); |
| 902 | } |
| 903 | |
| 904 | @SuppressWarnings({"MethodMayBeStatic", "RedundantThrows"}) |
| 905 | protected void onKeepAliveTimeout(@NotNull AsyncSocket socket) throws Exception { |
nothing calls this directly
no test coverage detected