Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private void OnEnable()
/// <param name="size"></param>
public int MaximumTransmissionUnitSize
{
set => MessageManager.NonFragmentedMessageMaxSize = value;
set => MessageManager.NonFragmentedMessageMaxSize = value & ~7; // Round down to nearest word aligned size
get => MessageManager.NonFragmentedMessageMaxSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ internal struct NetworkBatchHeader : INetworkSerializeByMemcpy
/// </summary>
public ushort Magic;

/// <summary>
/// Total number of messages in the batch.
/// </summary>
public ushort BatchCount;

/// <summary>
/// Total number of bytes in the batch.
/// </summary>
Expand All @@ -22,9 +27,5 @@ internal struct NetworkBatchHeader : INetworkSerializeByMemcpy
/// </summary>
public ulong BatchHash;

/// <summary>
/// Total number of messages in the batch.
/// </summary>
public ushort BatchCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal uint GetMessageType(Type t)
return m_MessageTypes[t];
}

public const int DefaultNonFragmentedMessageMaxSize = 1300;
public const int DefaultNonFragmentedMessageMaxSize = 1300 & ~7; // Round down to nearest word aligned size (1296)
public int NonFragmentedMessageMaxSize = DefaultNonFragmentedMessageMaxSize;
public int FragmentedMessageMaxSize = int.MaxValue;

Expand Down Expand Up @@ -829,11 +829,17 @@ internal unsafe void ProcessSendQueues()
// Skipping the Verify and sneaking the write mark in because we know it's fine.
queueItem.Writer.Handle->AllowedWriteMark = sizeof(NetworkBatchHeader);
#endif
queueItem.BatchHeader.BatchHash = XXHash.Hash64(queueItem.Writer.GetUnsafePtr() + sizeof(NetworkBatchHeader), queueItem.Writer.Length - sizeof(NetworkBatchHeader));

queueItem.BatchHeader.BatchSize = queueItem.Writer.Length;

var alignedLength = (queueItem.Writer.Length + 7) & ~7;
queueItem.Writer.TryBeginWrite(alignedLength);
Comment thread
SamuelBellomo marked this conversation as resolved.

queueItem.BatchHeader.BatchHash = XXHash.Hash64(queueItem.Writer.GetUnsafePtr() + sizeof(NetworkBatchHeader), alignedLength - sizeof(NetworkBatchHeader));

queueItem.BatchHeader.BatchSize = alignedLength;

queueItem.Writer.WriteValue(queueItem.BatchHeader);
queueItem.Writer.Seek(alignedLength);


try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IEnumerator TrackTotalNumberOfBytesSent()
}

Assert.True(observer.Found);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead, observer.Value);
Assert.AreEqual(((FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead) + 7) & ~7, observer.Value);
}

[UnityTest]
Expand All @@ -61,8 +61,6 @@ public IEnumerator TrackTotalNumberOfBytesReceived()
writer.Dispose();
}



var nbFrames = 0;
while (!observer.Found || nbFrames < 10)
{
Expand All @@ -71,7 +69,7 @@ public IEnumerator TrackTotalNumberOfBytesReceived()
}

Assert.True(observer.Found);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead, observer.Value);
Assert.AreEqual(((FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead) + 7) & ~7, observer.Value);
}

private class TotalBytesObserver : IMetricObserver
Expand All @@ -89,12 +87,22 @@ public TotalBytesObserver(IMetricDispatcher dispatcher, DirectionalMetricInfo me

public long Value { get; private set; }

private int m_BytesFoundCounter;
private long m_TotalBytes;

public void Observe(MetricCollection collection)
{
if (collection.TryGetCounter(m_MetricInfo.Id, out var counter) && counter.Value > 0)
{
Found = true;
Value = counter.Value;
// Don't assign another observed value once one is already observed
if (!Found)
{
Found = true;
Value = counter.Value;
m_TotalBytes += ((counter.Value + 7) & ~7);
m_BytesFoundCounter++;
UnityEngine.Debug.Log($"[{m_BytesFoundCounter}] Bytes Observed {counter.Value} | Total Bytes Observed: {m_TotalBytes}");
}
}
}
}
Expand Down