MCPcopy Create free account
hub / github.com/e2wugui/zeze / checkKeepAlive

Method checkKeepAlive

ZezeJava/ZezeJava/src/main/java/Zeze/Net/Service.java:877–902  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 11

getConfigMethod · 0.95
getCurrentSecondsMethod · 0.95
foreachMethod · 0.95
onKeepAliveTimeoutMethod · 0.95
onSendKeepAliveMethod · 0.95
getHandshakeOptionsMethod · 0.80
getKeepRecvTimeoutMethod · 0.80
getKeepSendTimeoutMethod · 0.80
getActiveRecvTimeMethod · 0.80
getActiveSendTimeMethod · 0.80
getTypeMethod · 0.65

Tested by

no test coverage detected