Skip to content

fix: expose timeout configs for UTP and enable heartbeats #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions com.unity.netcode.adapter.utp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ All notable changes to this package will be documented in this file. The format

## [1.0.0-pre.3] - 2021-10-22

#### Added

- Exposed `m_HeartbeatTimeoutMS`, `m_ConnectTimeoutMS`, `m_MaxConnectAttempts`, and `m_DisconnectTimeoutMS` parameters.

### Changed

- Updated Unity Transport package to 1.0.0-pre.7
- Updated Netcode for GameObjects dependency to 1.0.0-pre.3

### Fixed

- Fixed sends failing when send queue is filled or close to be filled.
- Heartbeats API not working for Unity Transport when running in the editor or development builds.

## [1.0.0-pre.2] - 2020-12-20

Expand Down
32 changes: 25 additions & 7 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ private enum State
[Tooltip("The maximum size in bytes of the send queue for batching Netcode events")]
[SerializeField] private int m_SendQueueBatchSize = InitialBatchQueueSize;

[Tooltip("A timeout in milliseconds after which a heartbeat is sent if there is no activity.")]
[SerializeField] private int m_HeartbeatTimeoutMS = NetworkParameterConstants.HeartbeatTimeoutMS;

[Tooltip("A timeout in milliseconds indicating how long we will wait until we send a new connection attempt.")]
[SerializeField] private int m_ConnectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS;

[Tooltip("The maximum amount of connection attempts we will try before disconnecting.")]
[SerializeField] private int m_MaxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts;

[Tooltip("A timeout in milliseconds indicating how long we will wait for a connection event, before we disconnect it. " +
"(The connection needs to receive data from the connected endpoint within this timeout." +
"Note that with heartbeats enabled, simply not" +
"sending any data will not be enough to trigger this timeout (since heartbeats count as connection event)")]
[SerializeField] private int m_DisconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS;

[Serializable]
public struct ConnectionAddressData
{
Expand Down Expand Up @@ -759,20 +774,23 @@ public override void Shutdown()

public void CreateDriver(UnityTransport transport, out NetworkDriver driver, out NetworkPipeline unreliableSequencedPipeline, out NetworkPipeline reliableSequencedPipeline, out NetworkPipeline reliableSequencedFragmentedPipeline)
{

#if UNITY_EDITOR || DEVELOPMENT_BUILD
var netParams = new NetworkConfigParameter
{
maxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts,
connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS,
disconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS,
maxFrameTimeMS = 100
maxConnectAttempts = transport.m_MaxConnectAttempts,
connectTimeoutMS = transport.m_ConnectTimeoutMS,
disconnectTimeoutMS = transport.m_DisconnectTimeoutMS,
heartbeatTimeoutMS = transport.m_HeartbeatTimeoutMS,
maxFrameTimeMS = 0
};

#if UNITY_EDITOR || DEVELOPMENT_BUILD
netParams.maxFrameTimeMS = 100;

var simulatorParams = ClientSimulatorParameters;
transport.m_NetworkParameters.Insert(0, simulatorParams);
transport.m_NetworkParameters.Insert(0, netParams);
#endif
transport.m_NetworkParameters.Insert(0, netParams);

if (transport.m_NetworkParameters.Count > 0)
{
driver = NetworkDriver.Create(transport.m_NetworkParameters.ToArray());
Expand Down