Network/ENet: Add DisconnectTimeout event

This commit is contained in:
SirLynix 2022-09-09 12:56:50 +02:00
parent 3f38c52455
commit e063c7b45e
5 changed files with 19 additions and 11 deletions

View File

@ -95,7 +95,7 @@ namespace Nz
int ReceiveIncomingCommands(ENetEvent* event);
void NotifyConnect(ENetPeer* peer, ENetEvent* event, bool incoming);
void NotifyDisconnect(ENetPeer*, ENetEvent* event);
void NotifyDisconnect(ENetPeer*, ENetEvent* event, bool timeout);
void SendAcknowledgements(ENetPeer* peer);
bool SendReliableOutgoingCommands(ENetPeer* peer);

View File

@ -246,6 +246,7 @@ namespace Nz
UInt64 m_totalByteReceived;
UInt64 m_totalByteSent;
bool m_isSimulationEnabled;
bool m_timedOut;
};
}

View File

@ -119,14 +119,19 @@ namespace Nz
None,
/** a peer has disconnected. This event is generated on a successful
* completion of a disconnect initiated by enet_peer_disconnect, if
* a peer has timed out, or if a connection request initialized by
* enet_host_connect has timed out. The peer field contains the peer
* which disconnected. The data field contains user supplied data
* completion of a disconnect initiated by enet_peer_disconnect.
* The peer field contains the peer which disconnected.
* The data field contains user supplied data
* describing the disconnection, or 0, if none is available.
*/
Disconnect,
/** a peer has timed out. This event is generated if a connected peer timed out
* or if a enet_host_connected has timed out. The peer field contains the peer
* which disconnected.
*/
DisconnectTimeout,
/** a connection request initiated by enet_host_connect from this host has completed.
* The peer field contains the peer which successfully connected.
*/

View File

@ -386,7 +386,7 @@ namespace Nz
case ENetPeerState::Zombie:
m_recalculateBandwidthLimits = true;
event->type = ENetEventType::Disconnect;
event->type = (peer.m_timedOut) ? ENetEventType::DisconnectTimeout : ENetEventType::Disconnect;
event->peer = &peer;
event->data = peer.m_eventData;
@ -787,7 +787,7 @@ namespace Nz
peer->DispatchState((peer->GetState() == ENetPeerState::Connecting) ? ENetPeerState::ConnectionSucceeded : ENetPeerState::ConnectionPending);
}
void ENetHost::NotifyDisconnect(ENetPeer* peer, ENetEvent* event)
void ENetHost::NotifyDisconnect(ENetPeer* peer, ENetEvent* event, bool timeout)
{
if (peer->GetState() >= ENetPeerState::ConnectionPending)
m_recalculateBandwidthLimits = true;
@ -796,7 +796,7 @@ namespace Nz
peer->Reset();
else if (event)
{
event->type = ENetEventType::Disconnect;
event->type = (timeout) ? ENetEventType::DisconnectTimeout : ENetEventType::Disconnect;
event->peer = peer;
event->data = peer->m_eventData;
@ -805,6 +805,7 @@ namespace Nz
else
{
peer->m_eventData = 0;
peer->m_timedOut = timeout;
peer->DispatchState(ENetPeerState::Zombie);
}
@ -1123,7 +1124,7 @@ namespace Nz
if (!currentPeer->IsConnected())
{
//< Network is down or unreachable (ex: IPv6 address when not supported), fails peer connection immediately
NotifyDisconnect(currentPeer, event);
NotifyDisconnect(currentPeer, event, true);
return 1;
}

View File

@ -163,6 +163,7 @@ namespace Nz
m_incomingUnsequencedGroup = 0;
m_outgoingUnsequencedGroup = 0;
m_eventData = 0;
m_timedOut = false;
m_totalByteReceived = 0;
m_totalByteSent = 0;
m_totalPacketReceived = 0;
@ -308,7 +309,7 @@ namespace Nz
if (m_earliestTimeout != 0 && (ENetTimeDifference(serviceTime, m_earliestTimeout) >= m_timeoutMaximum ||
(command.roundTripTimeout >= command.roundTripTimeoutLimit && ENetTimeDifference(serviceTime, m_earliestTimeout) >= m_timeoutMinimum)))
{
m_host->NotifyDisconnect(this, event);
m_host->NotifyDisconnect(this, event, true);
return true;
}
@ -510,7 +511,7 @@ namespace Nz
if (commandNumber != ENetProtocolCommand_Disconnect)
return false;
m_host->NotifyDisconnect(this, event);
m_host->NotifyDisconnect(this, event, false);
break;
case ENetPeerState::DisconnectLater: