Skip to content

feat: Update UTP to 1.4 and add ability to set UTP's MTU #2716

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 8 commits into from
Oct 4, 2023
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 @@ -34,6 +34,8 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Changed

- Updated dependency on `com.unity.transport` to version 1.4.0. (#2716)

## [1.6.0] - 2023-08-09

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
/// Fill the given <see cref="DataStreamWriter"/> with as many bytes from the queue as
/// possible, disregarding message boundaries.
/// </summary>
///<remarks>
/// <remarks>
/// This does NOT actually consume anything from the queue. That is, calling this method
/// does not reduce the length of the queue. Callers are expected to call
/// <see cref="Consume"/> with the value returned by this method afterwards if the data can
Expand All @@ -252,15 +252,17 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
/// this could lead to reading messages from a corrupted queue.
/// </remarks>
/// <param name="writer">The <see cref="DataStreamWriter"/> to write to.</param>
/// <param name="maxBytes">Max number of bytes to copy (0 means writer capacity).</param>
/// <returns>How many bytes were written to the writer.</returns>
public int FillWriterWithBytes(ref DataStreamWriter writer)
public int FillWriterWithBytes(ref DataStreamWriter writer, int maxBytes = 0)
{
if (!IsCreated || Length == 0)
{
return 0;
}

var copyLength = Math.Min(writer.Capacity, Length);
var maxLength = maxBytes == 0 ? writer.Capacity : maxBytes;
var copyLength = Math.Min(maxLength, Length);

unsafe
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ private struct SendBatchedMessagesJob : IJob
public SendTarget Target;
public BatchedSendQueue Queue;
public NetworkPipeline ReliablePipeline;
public int MTU;

public void Execute()
{
Expand All @@ -749,7 +750,7 @@ public void Execute()
// in the stream (the send queue does that automatically) we are sure they'll be
// reassembled properly at the other end. This allows us to lift the limit of ~44KB
// on reliable payloads (because of the reliable window size).
var written = pipeline == ReliablePipeline ? Queue.FillWriterWithBytes(ref writer) : Queue.FillWriterWithMessages(ref writer);
var written = pipeline == ReliablePipeline ? Queue.FillWriterWithBytes(ref writer, MTU) : Queue.FillWriterWithMessages(ref writer);

result = Driver.EndSend(writer);
if (result == written)
Expand Down Expand Up @@ -788,7 +789,8 @@ private void SendBatchedMessages(SendTarget sendTarget, BatchedSendQueue queue)
Driver = m_Driver.ToConcurrent(),
Target = sendTarget,
Queue = queue,
ReliablePipeline = m_ReliableSequencedPipeline
ReliablePipeline = m_ReliableSequencedPipeline,
MTU = NetworkManager ? NetworkManager.GetPeerMTU(sendTarget.ClientId) + m_Driver.MaxHeaderSize(sendTarget.NetworkPipeline) : 0,
}.Run();
}

Expand Down
2 changes: 1 addition & 1 deletion com.unity.netcode.gameobjects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"unity": "2020.3",
"dependencies": {
"com.unity.nuget.mono-cecil": "1.10.1",
"com.unity.transport": "1.3.4"
"com.unity.transport": "1.4.0"
}
}