You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-16 15:16:33 +09:00
Robustified and optimized GetBestChunkSize()
This commit is contained in:
@@ -152,8 +152,9 @@ namespace Lidgren.Network
|
|||||||
|
|
||||||
internal static int GetBestChunkSize(int group, int totalBytes, int mtu)
|
internal static int GetBestChunkSize(int group, int totalBytes, int mtu)
|
||||||
{
|
{
|
||||||
int tryNumChunks = (totalBytes / (mtu - 8)) + 1;
|
int tryChunkSize = mtu - NetConstants.HeaderByteSize - 4; // naive approximation
|
||||||
int tryChunkSize = (totalBytes / tryNumChunks) + 1; // +1 since we immediately decrement it in the loop
|
int est = GetFragmentationHeaderSize(group, totalBytes, tryChunkSize, totalBytes / tryChunkSize);
|
||||||
|
tryChunkSize = mtu - NetConstants.HeaderByteSize - est; // slightly less naive approximation
|
||||||
|
|
||||||
int headerSize = 0;
|
int headerSize = 0;
|
||||||
do
|
do
|
||||||
@@ -164,9 +165,9 @@ namespace Lidgren.Network
|
|||||||
if (numChunks * tryChunkSize < totalBytes)
|
if (numChunks * tryChunkSize < totalBytes)
|
||||||
numChunks++;
|
numChunks++;
|
||||||
|
|
||||||
headerSize = GetFragmentationHeaderSize(group, totalBytes, tryChunkSize, numChunks);
|
headerSize = GetFragmentationHeaderSize(group, totalBytes, tryChunkSize, numChunks); // 4+ bytes
|
||||||
|
|
||||||
} while (tryChunkSize + headerSize + 5 + 1 >= mtu);
|
} while (tryChunkSize + headerSize + NetConstants.HeaderByteSize + 1 >= mtu);
|
||||||
|
|
||||||
return tryChunkSize;
|
return tryChunkSize;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user