minimum and maximum timeout

This commit is contained in:
eihrul 2005-05-24 06:08:30 +00:00
parent 2ef761a8d2
commit 59d5c26e38
3 changed files with 14 additions and 2 deletions

View file

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

1
peer.c
View file

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

View file

@ -486,6 +486,7 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
return 0; return 0;
peer -> lastReceiveTime = timeCurrent; peer -> lastReceiveTime = timeCurrent;
peer -> earliestTimeout = 0;
roundTripTime = ENET_TIME_DIFFERENCE (timeCurrent, receivedSentTime); 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) if (ENET_TIME_DIFFERENCE (timeCurrent, outgoingCommand -> sentTime) < outgoingCommand -> roundTripTimeout)
continue; 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 -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer; event -> peer = peer;