1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-17 15:46: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>

View File

@@ -133,6 +133,7 @@ namespace DurableClient
bdr.AppendLine("SENT Reliable ordered: " + s_reliableOrderedNr[0] + ", " + s_reliableOrderedNr[1] + ", " + s_reliableOrderedNr[2]);
bdr.AppendLine("SENT Sequenced: " + s_sequencedNr[0] + ", " + s_sequencedNr[1] + ", " + s_sequencedNr[2]);
bdr.AppendLine("Unsent bytes: " + conn.UnsentBytesCount);
MainForm.label1.Text = bdr.ToString();
}
}

View File

@@ -8,12 +8,18 @@ namespace UnitTests
{
public static void Run()
{
NetQueue<int> queue = new NetQueue<int>(8);
NetQueue<int> queue = new NetQueue<int>(4);
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);
int[] arr = queue.ToArray();
if (arr.Length != 3)
throw new Exception("NetQueue.ToArray failure");
if (arr[0] != 1 || arr[1] != 2 || arr[2] != 3)
throw new Exception("NetQueue.ToArray failure");
bool ok;
int a;
@@ -69,6 +75,10 @@ namespace UnitTests
if (queue.Count != 0)
throw new Exception("NetQueue.Clear failed");
int[] arr2 = queue.ToArray();
if (arr2.Length != 0)
throw new Exception("NetQueue.ToArray failure");
Console.WriteLine("NetQueue tests OK");
}
}