Skip to content

feat: Allow reliable sends to go over maximum payload size #2081

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 2 commits into from
Jul 26, 2022
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
2 changes: 2 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Changed

- When using `UnityTransport`, _reliable_ payloads are now allowed to exceed the configured 'Max Payload Size'. Unreliable payloads remain bounded by this setting. (#2081)

### Fixed

- Fixed issue where NetworkAnimator was not removing its subscription from OnClientConnectedCallback when despawned during the shutdown sequence. (#2074)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ public int MaxPacketQueueSize
set => m_MaxPacketQueueSize = value;
}

[Tooltip("The maximum size of a payload that can be handled by the transport.")]
[Tooltip("The maximum size of an unreliable payload that can be handled by the transport.")]
[SerializeField]
private int m_MaxPayloadSize = InitialMaxPayloadSize;

/// <summary>The maximum size of a payload that can be handled by the transport.</summary>
/// <summary>The maximum size of an unreliable payload that can be handled by the transport.</summary>
public int MaxPayloadSize
{
get => m_MaxPayloadSize;
Expand Down Expand Up @@ -1148,14 +1148,14 @@ public override NetcodeNetworkEvent PollEvent(out ulong clientId, out ArraySegme
/// <param name="networkDelivery">The delivery type (QoS) to send data with</param>
public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
{
if (payload.Count > m_MaxPayloadSize)
var pipeline = SelectSendPipeline(networkDelivery);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻
YAY


if (pipeline != m_ReliableSequencedPipeline && payload.Count > m_MaxPayloadSize)
{
Debug.LogError($"Payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
Debug.LogError($"Unreliable payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
return;
}

var pipeline = SelectSendPipeline(networkDelivery);

var sendTarget = new SendTarget(clientId, pipeline);
if (!m_SendQueue.TryGetValue(sendTarget, out var queue))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,26 @@ public IEnumerator SendQueuesFlushedOnRemoteClientDisconnect([ValueSource("k_Del

yield return null;
}

[UnityTest]
public IEnumerator ReliablePayloadsCanBeLargerThanMaximum()
{
InitializeTransport(out m_Server, out m_ServerEvents);
InitializeTransport(out m_Client1, out m_Client1Events);

m_Server.StartServer();
m_Client1.StartClient();

yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events);

var payloadSize = UnityTransport.InitialMaxPayloadSize + 1;
var data = new ArraySegment<byte>(new byte[payloadSize]);

m_Server.Send(m_Client1.ServerClientId, data, NetworkDelivery.Reliable);

yield return WaitForNetworkEvent(NetworkEvent.Data, m_Client1Events);

yield return null;
}
}
}