Skip to content

Commit b50b396

Browse files
feat: Update UTP to 1.4 and add ability to set UTP's MTU (#2716)
1 parent d565d9d commit b50b396

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
3434

3535
### Changed
3636

37+
- Updated dependency on `com.unity.transport` to version 1.4.0. (#2716)
38+
3739
## [1.6.0] - 2023-08-09
3840

3941
### Added

com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
242242
/// Fill the given <see cref="DataStreamWriter"/> with as many bytes from the queue as
243243
/// possible, disregarding message boundaries.
244244
/// </summary>
245-
///<remarks>
245+
/// <remarks>
246246
/// This does NOT actually consume anything from the queue. That is, calling this method
247247
/// does not reduce the length of the queue. Callers are expected to call
248248
/// <see cref="Consume"/> with the value returned by this method afterwards if the data can
@@ -252,15 +252,17 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
252252
/// this could lead to reading messages from a corrupted queue.
253253
/// </remarks>
254254
/// <param name="writer">The <see cref="DataStreamWriter"/> to write to.</param>
255+
/// <param name="maxBytes">Max number of bytes to copy (0 means writer capacity).</param>
255256
/// <returns>How many bytes were written to the writer.</returns>
256-
public int FillWriterWithBytes(ref DataStreamWriter writer)
257+
public int FillWriterWithBytes(ref DataStreamWriter writer, int maxBytes = 0)
257258
{
258259
if (!IsCreated || Length == 0)
259260
{
260261
return 0;
261262
}
262263

263-
var copyLength = Math.Min(writer.Capacity, Length);
264+
var maxLength = maxBytes == 0 ? writer.Capacity : maxBytes;
265+
var copyLength = Math.Min(maxLength, Length);
264266

265267
unsafe
266268
{

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ private struct SendBatchedMessagesJob : IJob
727727
public SendTarget Target;
728728
public BatchedSendQueue Queue;
729729
public NetworkPipeline ReliablePipeline;
730+
public int MTU;
730731

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

754755
result = Driver.EndSend(writer);
755756
if (result == written)
@@ -788,7 +789,8 @@ private void SendBatchedMessages(SendTarget sendTarget, BatchedSendQueue queue)
788789
Driver = m_Driver.ToConcurrent(),
789790
Target = sendTarget,
790791
Queue = queue,
791-
ReliablePipeline = m_ReliableSequencedPipeline
792+
ReliablePipeline = m_ReliableSequencedPipeline,
793+
MTU = NetworkManager ? NetworkManager.GetPeerMTU(sendTarget.ClientId) + m_Driver.MaxHeaderSize(sendTarget.NetworkPipeline) : 0,
792794
}.Run();
793795
}
794796

com.unity.netcode.gameobjects/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"unity": "2020.3",
77
"dependencies": {
88
"com.unity.nuget.mono-cecil": "1.10.1",
9-
"com.unity.transport": "1.3.4"
9+
"com.unity.transport": "1.4.0"
1010
}
1111
}

0 commit comments

Comments
 (0)