Transport.MaxPacketSize moved to TransportLayer.GetMaxPacketSize because it depends on the layer

This commit is contained in:
vis2k 2018-11-15 09:22:13 +01:00
parent 7056ccd428
commit 1289dee8b3
8 changed files with 28 additions and 11 deletions

View File

@ -174,9 +174,9 @@ protected virtual bool SendBytes( byte[] bytes, int channelId = Channels.Default
{ {
if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); } if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); }
if (bytes.Length > Transport.MaxPacketSize) if (bytes.Length > Transport.layer.GetMaxPacketSize())
{ {
Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.MaxPacketSize + " bytes"); Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.layer.GetMaxPacketSize() + " bytes");
return false; return false;
} }

View File

@ -425,7 +425,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo
// original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might // original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might
// be useful for debugging. // be useful for debugging.
if (bytes.Length > Transport.MaxPacketSize) if (bytes.Length > Transport.layer.GetMaxPacketSize())
{ {
Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp);
} }

View File

@ -72,9 +72,9 @@ public void WriteBytesAndSize(byte[] buffer, int offset, int count)
writer.Write(false); // notNull? writer.Write(false); // notNull?
return; return;
} }
if (count > Transport.MaxPacketSize) if (count > Transport.layer.GetMaxPacketSize())
{ {
Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.MaxPacketSize + " bytes."); Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.layer.GetMaxPacketSize() + " bytes.");
return; return;
} }

View File

@ -9,6 +9,7 @@ namespace Mirror
public class LLAPITransport : TransportLayer public class LLAPITransport : TransportLayer
{ {
readonly ConnectionConfig connectionConfig; readonly ConnectionConfig connectionConfig;
readonly GlobalConfig globalConfig;
readonly int channelId; // always use first channel readonly int channelId; // always use first channel
byte error; byte error;
@ -36,6 +37,7 @@ public LLAPITransport(GlobalConfig globalConfig = null, ConnectionConfig connect
globalConfig.MinTimerTimeout = 1; globalConfig.MinTimerTimeout = 1;
globalConfig.MaxTimerTimeout = 12000; globalConfig.MaxTimerTimeout = 12000;
} }
this.globalConfig = globalConfig;
NetworkTransport.Init(globalConfig); NetworkTransport.Init(globalConfig);
// create connection config if none passed // create connection config if none passed
@ -257,5 +259,10 @@ public void Shutdown()
clientConnectionId = -1; clientConnectionId = -1;
Debug.Log("LLAPITransport.Shutdown"); Debug.Log("LLAPITransport.Shutdown");
} }
public int GetMaxPacketSize()
{
return globalConfig.MaxPacketSize;
}
} }
} }

View File

@ -100,5 +100,11 @@ public virtual void Shutdown()
client.Disconnect(); client.Disconnect();
server.Stop(); server.Stop();
} }
public int GetMaxPacketSize()
{
// Telepathy's limit is Array.Length, which is int
return int.MaxValue;
}
} }
} }

View File

@ -116,5 +116,12 @@ public void Shutdown()
client.Shutdown(); client.Shutdown();
if (server != null) server.Shutdown(); if (server != null) server.Shutdown();
} }
public int GetMaxPacketSize()
{
if (server != null) return server.GetMaxPacketSize();
if (client != null) return client.GetMaxPacketSize();
return 0;
}
} }
} }

View File

@ -6,9 +6,6 @@ namespace Mirror
// Transport class used by HLAPI /////////////////////////////////////////// // Transport class used by HLAPI ///////////////////////////////////////////
public static class Transport public static class Transport
{ {
// hlapi needs to know max packet size to show warnings
public static int MaxPacketSize = ushort.MaxValue;
// selected transport layer // selected transport layer
// the transport is normally initialized in NetworkManager InitializeTransport // the transport is normally initialized in NetworkManager InitializeTransport
// initialize it yourself if you are not using NetworkManager // initialize it yourself if you are not using NetworkManager
@ -39,5 +36,6 @@ public interface TransportLayer
// common // common
void Shutdown(); void Shutdown();
int GetMaxPacketSize();
} }
} }

View File

@ -30,7 +30,6 @@ public void TestWritingLargeMessage()
[Test] [Test]
public void TestWritingHugeArray() public void TestWritingHugeArray()
{ {
Transport.MaxPacketSize = 1000000;
// try serializing array > 64KB and see what happens // try serializing array > 64KB and see what happens
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
writer.WriteBytesAndSize(new byte[100000]); writer.WriteBytesAndSize(new byte[100000]);