Эх сурвалжийг харах

minimum and maximum timeout

eihrul 20 жил өмнө
parent
commit
59d5c26e38
3 өөрчлөгдсөн 14 нэмэгдсэн , 2 устгасан
  1. 4 1
      include/enet/enet.h
  2. 1 0
      peer.c
  3. 9 1
      protocol.c

+ 4 - 1
include/enet/enet.h

@@ -167,8 +167,10 @@ enum
    ENET_PEER_PACKET_LOSS_INTERVAL         = 10000,
    ENET_PEER_WINDOW_SIZE_SCALE            = 64 * 1024,
    ENET_PEER_TIMEOUT_LIMIT                = 32,
+   ENET_PEER_TIMEOUT_MINIMUM              = 3000,
+   ENET_PEER_TIMEOUT_MAXIMUM              = 30000,
    ENET_PEER_PING_INTERVAL                = 500,
-   ENET_PEER_UNSEQUENCED_WINDOW_SIZE      = 4 * 32
+   ENET_PEER_UNSEQUENCED_WINDOW_SIZE      = 4 * 32,
 };
 
 typedef struct _ENetChannel
@@ -206,6 +208,7 @@ typedef struct _ENetPeer
    enet_uint32   lastSendTime;
    enet_uint32   lastReceiveTime;
    enet_uint32   nextTimeout;
+   enet_uint32   earliestTimeout;
    enet_uint32   packetLossEpoch;
    enet_uint32   packetsSent;
    enet_uint32   packetsLost;

+ 1 - 0
peer.c

@@ -351,6 +351,7 @@ enet_peer_reset (ENetPeer * peer)
     peer -> lastSendTime = 0;
     peer -> lastReceiveTime = 0;
     peer -> nextTimeout = 0;
+    peer -> earliestTimeout = 0;
     peer -> packetLossEpoch = 0;
     peer -> packetsSent = 0;
     peer -> packetsLost = 0;

+ 9 - 1
protocol.c

@@ -486,6 +486,7 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
       return 0;
 
     peer -> lastReceiveTime = timeCurrent;
+    peer -> earliestTimeout = 0;
 
     roundTripTime = ENET_TIME_DIFFERENCE (timeCurrent, receivedSentTime);
 
@@ -948,7 +949,14 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even
        if (ENET_TIME_DIFFERENCE (timeCurrent, outgoingCommand -> sentTime) < outgoingCommand -> roundTripTimeout)
          continue;
 
-       if (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit)
+       if(peer -> earliestTimeout == 0 ||
+          ENET_TIME_LESS(outgoingCommand -> sentTime, peer -> earliestTimeout))
+           peer -> earliestTimeout = outgoingCommand -> sentTime;
+
+       if (peer -> earliestTimeout != 0 &&
+             (ENET_TIME_DIFFERENCE(timeCurrent, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MAXIMUM ||
+               (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit &&
+                 ENET_TIME_DIFFERENCE(timeCurrent, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MINIMUM)))
        {
           event -> type = ENET_EVENT_TYPE_DISCONNECT;
           event -> peer = peer;