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

NetConnection.UnsentBytesCount added

This commit is contained in:
lidgren
2010-09-07 06:53:23 +00:00
parent fa3bd2646f
commit c185b3b16f
5 changed files with 55 additions and 3 deletions

View File

@@ -82,6 +82,33 @@ namespace Lidgren.Network
/// </summary>
public NetPeer Owner { get { return m_owner; } }
/// <summary>
/// Gets the number of bytes queued for sending to this connection
/// </summary>
public int UnsentBytesCount
{
get
{
int mtu = m_owner.Configuration.MaximumTransmissionUnit - NetConstants.FragmentHeaderSize;
int retval = 0;
NetSending[] arr = m_unsentMessages.ToArray();
foreach (NetSending send in arr)
{
if (send.FragmentGroupId == 0)
{
retval += send.Message.LengthBytes;
}
else
{
int thisFragmentLength = (send.FragmentNumber == send.FragmentTotalCount - 1 ? (send.Message.LengthBytes - (mtu * (send.FragmentTotalCount - 1))) : mtu);
retval += thisFragmentLength;
}
}
return retval;
}
}
internal NetConnection(NetPeer owner, IPEndPoint remoteEndpoint)
{
m_owner = owner;

View File

@@ -195,6 +195,22 @@ namespace Lidgren.Network
return false;
}
public T[] ToArray()
{
lock (m_lock)
{
T[] retval = new T[m_size];
int ptr = m_head;
for (int i = 0; i < m_size; i++)
{
retval[i] = m_items[ptr++];
if (ptr >= m_items.Length)
ptr = 0;
}
return retval;
}
}
public void Clear()
{
lock (m_lock)

View File

@@ -31,8 +31,6 @@ namespace Lidgren.Network
/// </summary>
public static class NetUtility
{
private static Regex s_regIP;
/// <summary>
/// Get IPv4 endpoint from notation (xxx.xxx.xxx.xxx) or hostname and port number
/// </summary>