You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-06 02:11:06 +09:00
- Fixed various number to avoid re-allocating netbuffer storage
This commit is contained in:
@@ -122,7 +122,10 @@ namespace Lidgren.Network
|
||||
{
|
||||
m_peer.VerifyNetworkThread();
|
||||
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(m_peerConfiguration.AppIdentifier.Length + 1 + 4);
|
||||
int preAllocate = 13 + m_peerConfiguration.AppIdentifier.Length;
|
||||
preAllocate += (m_localHailMessage == null ? 0 : m_localHailMessage.LengthBytes);
|
||||
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(preAllocate);
|
||||
om.m_messageType = NetMessageType.Connect;
|
||||
om.Write(m_peerConfiguration.AppIdentifier);
|
||||
om.Write(m_peer.m_uniqueIdentifier);
|
||||
@@ -146,7 +149,7 @@ namespace Lidgren.Network
|
||||
if (onLibraryThread)
|
||||
m_peer.VerifyNetworkThread();
|
||||
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(m_peerConfiguration.AppIdentifier.Length + 1 + 4);
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(m_peerConfiguration.AppIdentifier.Length + 13);
|
||||
om.m_messageType = NetMessageType.ConnectResponse;
|
||||
om.Write(m_peerConfiguration.AppIdentifier);
|
||||
om.Write(m_peer.m_uniqueIdentifier);
|
||||
@@ -197,7 +200,7 @@ namespace Lidgren.Network
|
||||
|
||||
internal void SendConnectionEstablished()
|
||||
{
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(0);
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(4);
|
||||
om.m_messageType = NetMessageType.ConnectionEstablished;
|
||||
om.Write((float)NetTime.Now);
|
||||
m_peer.SendLibrary(om, m_remoteEndPoint);
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Lidgren.Network
|
||||
|
||||
private void SendMTUSuccess(int size)
|
||||
{
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(1);
|
||||
NetOutgoingMessage om = m_peer.CreateMessage(4);
|
||||
om.Write(size);
|
||||
om.m_messageType = NetMessageType.ExpandMTUSuccess;
|
||||
int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
|
||||
|
||||
@@ -28,17 +28,17 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
|
||||
internal byte[] GetStorage(int minimumCapacity)
|
||||
internal byte[] GetStorage(int minimumCapacityInBytes)
|
||||
{
|
||||
if (m_storagePool == null)
|
||||
return new byte[minimumCapacity];
|
||||
return new byte[minimumCapacityInBytes];
|
||||
|
||||
lock (m_storagePool)
|
||||
{
|
||||
for (int i = 0; i < m_storagePool.Count; i++)
|
||||
{
|
||||
byte[] retval = m_storagePool[i];
|
||||
if (retval != null && retval.Length >= minimumCapacity)
|
||||
if (retval != null && retval.Length >= minimumCapacityInBytes)
|
||||
{
|
||||
m_storagePool[i] = null;
|
||||
m_storagePoolBytes -= retval.Length;
|
||||
@@ -46,8 +46,8 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
}
|
||||
m_statistics.m_bytesAllocated += minimumCapacity;
|
||||
return new byte[minimumCapacity];
|
||||
m_statistics.m_bytesAllocated += minimumCapacityInBytes;
|
||||
return new byte[minimumCapacityInBytes];
|
||||
}
|
||||
|
||||
internal void Recycle(byte[] storage)
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace ChatClient
|
||||
public static void Connect(string host, int port)
|
||||
{
|
||||
s_client.Start();
|
||||
NetOutgoingMessage hail = s_client.CreateMessage();
|
||||
hail.Write("This is the hail message");
|
||||
NetOutgoingMessage hail = s_client.CreateMessage("This is the hail message");
|
||||
s_client.Connect(host, port, hail);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user