You've already forked lidgren-network-gen3
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:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user