diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md
index 4765ba1a82..1aa0c61e84 100644
--- a/com.unity.netcode.gameobjects/CHANGELOG.md
+++ b/com.unity.netcode.gameobjects/CHANGELOG.md
@@ -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
diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs
index 6f81eea442..7dbe5e8f17 100644
--- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs
@@ -242,7 +242,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
/// Fill the given with as many bytes from the queue as
/// possible, disregarding message boundaries.
///
- ///
+ ///
/// 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
/// with the value returned by this method afterwards if the data can
@@ -252,15 +252,17 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
/// this could lead to reading messages from a corrupted queue.
///
/// The to write to.
+ /// Max number of bytes to copy (0 means writer capacity).
/// How many bytes were written to the writer.
- 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
{
diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
index 99682cb969..7836827fff 100644
--- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
@@ -727,6 +727,7 @@ private struct SendBatchedMessagesJob : IJob
public SendTarget Target;
public BatchedSendQueue Queue;
public NetworkPipeline ReliablePipeline;
+ public int MTU;
public void Execute()
{
@@ -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)
@@ -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();
}
diff --git a/com.unity.netcode.gameobjects/package.json b/com.unity.netcode.gameobjects/package.json
index d4952986c0..195af9588b 100644
--- a/com.unity.netcode.gameobjects/package.json
+++ b/com.unity.netcode.gameobjects/package.json
@@ -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"
}
}