_enet timeout

This commit is contained in:
2023-05-21 20:23:51 +03:00
parent d3f14efbbd
commit d65af4c621
4 changed files with 21 additions and 2 deletions

View File

@@ -134,6 +134,9 @@ bool ENetDriver::Connect()
return false;
}
// Change the maximum timeout for the peer
enet_peer_timeout(_peer, ENET_PEER_TIMEOUT_LIMIT, ENET_PEER_TIMEOUT_MINIMUM, _config.ConnectionTimeout * 1000);
return true;
}
@@ -141,7 +144,7 @@ void ENetDriver::Disconnect()
{
if (_peer)
{
enet_peer_disconnect_now(_peer, 0);
enet_peer_disconnect(_peer, 0);
_peer = nullptr;
LOG(Info, "Disconnected");
}
@@ -153,7 +156,7 @@ void ENetDriver::Disconnect(const NetworkConnection& connection)
ENetPeer* peer;
if (_peerMap.TryGet(connectionId, peer))
{
enet_peer_disconnect_now(peer, 0);
enet_peer_disconnect(peer, 0);
_peerMap.Remove(connectionId);
}
else
@@ -214,6 +217,7 @@ void ENetDriver::SendMessage(const NetworkChannelType channelType, const Network
{
ASSERT(!IsServer());
SendPacketToPeer(_peer, channelType, message);
enet_host_flush(_host);
}
void ENetDriver::SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target)
@@ -223,6 +227,7 @@ void ENetDriver::SendMessage(NetworkChannelType channelType, const NetworkMessag
if (_peerMap.TryGet(target.ConnectionId, peer) && peer && peer->state == ENET_PEER_STATE_CONNECTED)
{
SendPacketToPeer(peer, channelType, message);
enet_host_flush(_host);
}
}
@@ -235,6 +240,7 @@ void ENetDriver::SendMessage(const NetworkChannelType channelType, const Network
if (_peerMap.TryGet(target.ConnectionId, peer) && peer && peer->state == ENET_PEER_STATE_CONNECTED)
{
SendPacketToPeer(peer, channelType, message);
enet_host_flush(_host);
}
}
}

View File

@@ -51,6 +51,12 @@ API_STRUCT(Namespace="FlaxEngine.Networking") struct FLAXENGINE_API NetworkConfi
API_FIELD()
uint16 ConnectionsLimit = 32;
/// <summary>
/// The timeout in seconds for the peer to disconnect.
/// </summary>
API_FIELD()
uint16 ConnectionTimeout = 30;
/// <summary>
/// Address used to connect to or listen at.
/// </summary>

View File

@@ -187,6 +187,7 @@ bool StartPeer()
LOG(Error, "Unknown Network Driver type {0}", String(settings.NetworkDriver));
return true;
}
networkConfig.ConnectionTimeout = settings.Timeout;
networkConfig.NetworkDriver = ScriptingObject::NewObject(networkDriverType);
NetworkManager::Peer = NetworkPeer::CreatePeer(networkConfig);
if (!NetworkManager::Peer)

View File

@@ -32,6 +32,12 @@ public:
API_FIELD(Attributes="EditorOrder(100), Limit(0, 1000), EditorDisplay(\"General\", \"Network FPS\")")
float NetworkFPS = 60.0f;
/// <summary>
/// The timeout in seconds for the peer to disconnect.
/// </summary>
API_FIELD(Attributes="EditorOrder(200), Limit(0, 32768), EditorDisplay(\"General\")")
int32 Timeout = 30;
/// <summary>
/// Address of the server (server/host always runs on localhost). Only IPv4 is supported.
/// </summary>