1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-16 07:06:30 +09:00

NetOutgoingMessage.Write(string) now preallocates the correct amount of memory

NetPeer.MessageAvailable added
This commit is contained in:
lidgren
2010-08-07 07:46:06 +00:00
parent 44089457f9
commit ffe86262c6
3 changed files with 17 additions and 3 deletions

View File

@@ -518,7 +518,7 @@ namespace Lidgren.Network
}
byte[] bytes = Encoding.UTF8.GetBytes(source);
EnsureBufferSize(m_bitLength + 1 + bytes.Length);
EnsureBufferSize(m_bitLength + 1 + (bytes.Length * 8));
WriteVariableUInt32((uint)bytes.Length);
Write(bytes);
}

View File

@@ -150,6 +150,19 @@ namespace Lidgren.Network
Thread.Sleep(3);
}
/// <summary>
/// Returns true if there is a queued message available to read using ReadMessage()
/// </summary>
public bool MessageAvailable
{
get
{
if (m_status == NetPeerStatus.NotRunning)
return false;
return (m_releasedIncomingMessages.Count > 0);
}
}
/// <summary>
/// Read a pending message from any connection, if any
/// </summary>

View File

@@ -93,9 +93,10 @@ namespace Lidgren.Network
m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage;
// Maximum transmission unit
// Ethernet can take 1500 bytes of payload, so lets stay below that.
// The aim is for a max full packet to be 1440 bytes (30 x 48 bytes, lower than 1468)
// 20 bytes ip header
// 8 bytes udp header
// 20 bytes IP header
// 8 bytes UDP header
// 5 bytes lidgren header for one message
// 1 byte just to be on the safe side
// Totals 1440 minus 34 = 1406 bytes free for payload