]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Remade statistics and removed from unit tests
authorJamJar00 <jamster.30@btinternet.com>
Mon, 19 Dec 2016 18:02:37 +0000 (18:02 +0000)
committerJamJar00 <jamster.30@btinternet.com>
Mon, 19 Dec 2016 18:02:37 +0000 (18:02 +0000)
Hazel.UnitTests/Hazel.UnitTests.csproj
Hazel.UnitTests/StatisticsTests.cs [new file with mode: 0644]
Hazel.UnitTests/TestHelper.cs
Hazel/ConnectionStatistics.cs
Hazel/Properties/AssemblyInfo.cs
Hazel/Tcp/TcpConnection.cs
Hazel/Udp/UdpConnection.Reliable.cs
Hazel/Udp/UdpConnection.cs

index 466c3346bd237cf899e0137c0924efbc06a63cc7..a380240f9892d55aabd604b072c6a078d2694c64 100644 (file)
     </When>
     <Otherwise>
       <ItemGroup>
-        <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
+        <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
+          <Private>False</Private>
+        </Reference>
       </ItemGroup>
     </Otherwise>
   </Choose>
   <ItemGroup>
+    <Compile Include="StatisticsTests.cs" />
     <Compile Include="TestHelper.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TcpConnectionTests.cs" />
diff --git a/Hazel.UnitTests/StatisticsTests.cs b/Hazel.UnitTests/StatisticsTests.cs
new file mode 100644 (file)
index 0000000..2afd179
--- /dev/null
@@ -0,0 +1,161 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Hazel.UnitTests
+{
+    [TestClass]
+    public class StatisticsTests
+    {
+        [TestMethod]
+        public void SendTests()
+        {
+            ConnectionStatistics statistics = new ConnectionStatistics();
+
+            statistics.LogUnreliableSend(10, 11);
+
+            Assert.AreEqual(1, statistics.MessagesSent);
+            Assert.AreEqual(1, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(0, statistics.ReliableMessagesSent);
+            Assert.AreEqual(0, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(0, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(10, statistics.DataBytesSent);
+            Assert.AreEqual(11, statistics.TotalBytesSent);
+
+            statistics.LogReliableSend(5, 8);
+
+            Assert.AreEqual(2, statistics.MessagesSent);
+            Assert.AreEqual(1, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(1, statistics.ReliableMessagesSent);
+            Assert.AreEqual(0, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(0, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(15, statistics.DataBytesSent);
+            Assert.AreEqual(19, statistics.TotalBytesSent);
+
+            statistics.LogFragmentedSend(6, 10);
+
+            Assert.AreEqual(3, statistics.MessagesSent);
+            Assert.AreEqual(1, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(1, statistics.ReliableMessagesSent);
+            Assert.AreEqual(1, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(0, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(21, statistics.DataBytesSent);
+            Assert.AreEqual(29, statistics.TotalBytesSent);
+
+            statistics.LogAcknowledgementSend(4);
+
+            Assert.AreEqual(4, statistics.MessagesSent);
+            Assert.AreEqual(1, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(1, statistics.ReliableMessagesSent);
+            Assert.AreEqual(1, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(1, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(0, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(21, statistics.DataBytesSent);
+            Assert.AreEqual(33, statistics.TotalBytesSent);
+
+            statistics.LogHelloSend(7);
+
+            Assert.AreEqual(5, statistics.MessagesSent);
+            Assert.AreEqual(1, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(1, statistics.ReliableMessagesSent);
+            Assert.AreEqual(1, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(1, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(1, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(21, statistics.DataBytesSent);
+            Assert.AreEqual(40, statistics.TotalBytesSent);
+            
+            Assert.AreEqual(0, statistics.MessagesReceived);
+            Assert.AreEqual(0, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(0, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(0, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(0, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(0, statistics.DataBytesReceived);
+            Assert.AreEqual(0, statistics.TotalBytesReceived);
+        }
+
+        [TestMethod]
+        public void ReceiveTests()
+        {
+            ConnectionStatistics statistics = new ConnectionStatistics();
+
+            statistics.LogUnreliableReceive(10, 11);
+
+            Assert.AreEqual(1, statistics.MessagesReceived);
+            Assert.AreEqual(1, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(0, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(0, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(0, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(10, statistics.DataBytesReceived);
+            Assert.AreEqual(11, statistics.TotalBytesReceived);
+
+            statistics.LogReliableReceive(5, 8);
+
+            Assert.AreEqual(2, statistics.MessagesReceived);
+            Assert.AreEqual(1, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(1, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(0, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(0, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(15, statistics.DataBytesReceived);
+            Assert.AreEqual(19, statistics.TotalBytesReceived);
+
+            statistics.LogFragmentedReceive(6, 10);
+
+            Assert.AreEqual(3, statistics.MessagesReceived);
+            Assert.AreEqual(1, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(1, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(1, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(0, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(21, statistics.DataBytesReceived);
+            Assert.AreEqual(29, statistics.TotalBytesReceived);
+
+            statistics.LogAcknowledgementReceive(4);
+
+            Assert.AreEqual(4, statistics.MessagesReceived);
+            Assert.AreEqual(1, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(1, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(1, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(1, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(0, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(21, statistics.DataBytesReceived);
+            Assert.AreEqual(33, statistics.TotalBytesReceived);
+
+            statistics.LogHelloReceive(7);
+
+            Assert.AreEqual(5, statistics.MessagesReceived);
+            Assert.AreEqual(1, statistics.UnreliableMessagesReceived);
+            Assert.AreEqual(1, statistics.ReliableMessagesReceived);
+            Assert.AreEqual(1, statistics.FragmentedMessagesReceived);
+            Assert.AreEqual(1, statistics.AcknowledgementMessagesReceived);
+            Assert.AreEqual(1, statistics.HelloMessagesReceived);
+
+            Assert.AreEqual(21, statistics.DataBytesReceived);
+            Assert.AreEqual(40, statistics.TotalBytesReceived);
+
+            Assert.AreEqual(0, statistics.MessagesSent);
+            Assert.AreEqual(0, statistics.UnreliableMessagesSent);
+            Assert.AreEqual(0, statistics.ReliableMessagesSent);
+            Assert.AreEqual(0, statistics.FragmentedMessagesSent);
+            Assert.AreEqual(0, statistics.AcknowledgementMessagesSent);
+            Assert.AreEqual(0, statistics.HelloMessagesSent);
+
+            Assert.AreEqual(0, statistics.DataBytesSent);
+            Assert.AreEqual(0, statistics.TotalBytesSent);
+        }
+    }
+}
index 87091fcca6c2268211479c0ec2879db87b5011f9..a66dc6f461e04e28335ddfeaf62aa797a99b249c 100644 (file)
@@ -25,13 +25,7 @@ namespace Hazel.UnitTests
             //Setup listener
             listener.NewConnection += delegate(object sender, NewConnectionEventArgs args)
             {
-                Assert.AreEqual(0, args.Connection.Statistics.DataBytesReceived);
-                Assert.AreEqual(0, args.Connection.Statistics.TotalBytesReceived);
-                
                 args.Connection.SendBytes(data, sendOption);
-                
-                Assert.AreEqual(data.Length, args.Connection.Statistics.DataBytesSent);
-                Assert.AreEqual(data.Length + headerSize, args.Connection.Statistics.TotalBytesSent);
             };
 
             listener.Start();
@@ -55,11 +49,6 @@ namespace Hazel.UnitTests
 
             //Wait until data is received
             mutex.WaitOne();
-
-            Assert.AreEqual(1, connection.Statistics.DataBytesSent);
-            Assert.AreEqual(data.Length, connection.Statistics.DataBytesReceived);
-            Assert.AreEqual(totalHandshakeSize, connection.Statistics.TotalBytesSent);
-            Assert.AreEqual(data.Length + headerSize, connection.Statistics.TotalBytesReceived);
         }
 
         /// <summary>
@@ -88,11 +77,6 @@ namespace Hazel.UnitTests
 
                     Assert.AreEqual(sendOption, innerArgs.SendOption);
 
-                    Assert.AreEqual(0, args.Connection.Statistics.DataBytesSent);
-                    Assert.AreEqual(data.Length, args.Connection.Statistics.DataBytesReceived);
-                    Assert.AreEqual(0, args.Connection.Statistics.TotalBytesSent);
-                    Assert.AreEqual(data.Length + headerSize, args.Connection.Statistics.TotalBytesReceived);
-
                     mutex2.Set();
                 };
 
@@ -110,11 +94,6 @@ namespace Hazel.UnitTests
 
             //Wait until data is received
             mutex2.WaitOne();
-
-            Assert.AreEqual(data.Length + 1, connection.Statistics.DataBytesSent);
-            Assert.AreEqual(0, connection.Statistics.DataBytesReceived);
-            Assert.AreEqual(totalHandshakeSize + data.Length + headerSize, connection.Statistics.TotalBytesSent);
-            Assert.AreEqual(0, connection.Statistics.TotalBytesReceived);
         }
 
         /// <summary>
index 85f40e765e257c561d4e2d37c9b64e79a56000dc..be8770e087f8e6c95ea437f740c0dcf3673928e3 100644 (file)
@@ -14,25 +14,120 @@ namespace Hazel
     public class ConnectionStatistics
     {
         /// <summary>
-        ///     The number of messages sent.
+        ///     The total number of messages sent.
+        /// </summary>
+        public long MessagesSent
+        {
+            get
+            {
+                return UnreliableMessagesSent + ReliableMessagesSent + FragmentedMessagesSent + AcknowledgementMessagesSent + HelloMessagesSent;
+            }
+        }
+
+        /// <summary>
+        ///     The number of unreliable messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of messages that were sent from the <see cref="Connection"/>, incremented each time that 
-        ///     LogSend is called by the Connection. Messages that caused an error are not counted and messages are only 
-        ///     counted once all other operations in the send are complete.
+        ///     This is the number of unreliable messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogUnreliableSend is called by the Connection. Messages that caused an error are not 
+        ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
-        public long MessagesSent
+        public long UnreliableMessagesSent
+        {
+            get
+            {
+                return Interlocked.Read(ref unreliableMessagesSent);
+            }
+        }
+
+        /// <summary>
+        ///     The number of unreliable messages sent.
+        /// </summary>
+        long unreliableMessagesSent;
+
+        /// <summary>
+        ///     The number of reliable messages sent.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of reliable messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogReliableSend is called by the Connection. Messages that caused an error are not 
+        ///     counted and messages are only counted once all other operations in the send are complete.
+        /// </remarks>
+        public long ReliableMessagesSent
+        {
+            get
+            {
+                return Interlocked.Read(ref reliableMessagesSent);
+            }
+        }
+
+        /// <summary>
+        ///     The number of unreliable messages sent.
+        /// </summary>
+        long reliableMessagesSent;
+
+        /// <summary>
+        ///     The number of fragmented messages sent.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of fragmented messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogFragmentedSend is called by the Connection. Messages that caused an error are not 
+        ///     counted and messages are only counted once all other operations in the send are complete.
+        /// </remarks>
+        public long FragmentedMessagesSent
+        {
+            get
+            {
+                return Interlocked.Read(ref fragmentedMessagesSent);
+            }
+        }
+
+        /// <summary>
+        ///     The number of fragmented messages sent.
+        /// </summary>
+        long fragmentedMessagesSent;
+
+        /// <summary>
+        ///     The number of acknowledgement messages sent.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of acknowledgements that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogAcknowledgementSend is called by the Connection. Messages that caused an error are not 
+        ///     counted and messages are only counted once all other operations in the send are complete.
+        /// </remarks>
+        public long AcknowledgementMessagesSent
+        {
+            get
+            {
+                return Interlocked.Read(ref acknowledgementMessagesSent);
+            }
+        }
+
+        /// <summary>
+        ///     The number of acknowledgement messages sent.
+        /// </summary>
+        long acknowledgementMessagesSent;
+
+        /// <summary>
+        ///     The number of hello messages sent.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of hello messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogHelloSend is called by the Connection. Messages that caused an error are not 
+        ///     counted and messages are only counted once all other operations in the send are complete.
+        /// </remarks>
+        public long HelloMessagesSent
         {
             get
             {
-                return Interlocked.Read(ref messagesSent);
+                return Interlocked.Read(ref helloMessagesSent);
             }
         }
 
         /// <summary>
-        ///     The number of messages sent.
+        ///     The number of hello messages sent.
         /// </summary>
-        long messagesSent;
+        long helloMessagesSent;
 
         /// <summary>
         ///     The number of bytes of data sent.
@@ -88,24 +183,115 @@ namespace Hazel
         long totalBytesSent;
 
         /// <summary>
-        ///     The number of messages received.
+        ///     The total number of messages received.
+        /// </summary>
+        public long MessagesReceived
+        {
+            get
+            {
+                return UnreliableMessagesReceived + ReliableMessagesReceived + FragmentedMessagesReceived + AcknowledgementMessagesReceived + helloMessagesReceived;
+            }
+        }
+        
+        /// <summary>
+        ///     The number of unreliable messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of messages that were received by the <see cref="Connection"/>, incremented each time that 
-        ///     LogReceive is called by the Connection. Messages are counted before the receive event is invoked.
+        ///     This is the number of unreliable messages that were received by the <see cref="Connection"/>, incremented
+        ///     each time that LogUnreliableReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
-        public long MessagesReceived
+        public long UnreliableMessagesReceived
         {
             get
             {
-                return Interlocked.Read(ref messagesReceived);
+                return Interlocked.Read(ref unreliableMessagesReceived);
             }
         }
 
         /// <summary>
-        ///     The number of messages received.
+        ///     The number of unreliable messages received.
         /// </summary>
-        long messagesReceived;
+        long unreliableMessagesReceived;
+
+        /// <summary>
+        ///     The number of reliable messages received.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of reliable messages that were received by the <see cref="Connection"/>, incremented
+        ///     each time that LogReliableReceive is called by the Connection. Messages are counted before the receive event is invoked.
+        /// </remarks>
+        public long ReliableMessagesReceived
+        {
+            get
+            {
+                return Interlocked.Read(ref reliableMessagesReceived);
+            }
+        }
+
+        /// <summary>
+        ///     The number of reliable messages received.
+        /// </summary>
+        long reliableMessagesReceived;
+
+        /// <summary>
+        ///     The number of fragmented messages received.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of fragmented messages that were received by the <see cref="Connection"/>, incremented
+        ///     each time that LogFragmentedReceive is called by the Connection. Messages are counted before the receive event is invoked.
+        /// </remarks>
+        public long FragmentedMessagesReceived
+        {
+            get
+            {
+                return Interlocked.Read(ref fragmentedMessagesReceived);
+            }
+        }
+
+        /// <summary>
+        ///     The number of fragmented messages received.
+        /// </summary>
+        long fragmentedMessagesReceived;
+
+        /// <summary>
+        ///     The number of acknowledgement messages received.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of acknowledgement messages that were received by the <see cref="Connection"/>, incremented
+        ///     each time that LogAcknowledgemntReceive is called by the Connection. Messages are counted before the receive event is invoked.
+        /// </remarks>
+        public long AcknowledgementMessagesReceived
+        {
+            get
+            {
+                return Interlocked.Read(ref acknowledgementMessagesReceived);
+            }
+        }
+
+        /// <summary>
+        ///     The number of acknowledgement messages received.
+        /// </summary>
+        long acknowledgementMessagesReceived;
+
+        /// <summary>
+        ///     The number of hello messages received.
+        /// </summary>
+        /// <remarks>
+        ///     This is the number of hello messages that were received by the <see cref="Connection"/>, incremented
+        ///     each time that LogHelloReceive is called by the Connection. Messages are counted before the receive event is invoked.
+        /// </remarks>
+        public long HelloMessagesReceived
+        {
+            get
+            {
+                return Interlocked.Read(ref helloMessagesReceived);
+            }
+        }
+
+        /// <summary>
+        ///     The number of hello messages received.
+        /// </summary>
+        long helloMessagesReceived;
 
         /// <summary>
         ///     The number of bytes of data received.
@@ -160,33 +346,145 @@ namespace Hazel
         long totalBytesReceived;
 
         /// <summary>
-        ///     Logs the sending of a data packet in the statistics.
+        ///     Logs the sending of an unreliable data packet in the statistics.
         /// </summary>
         /// <param name="dataLength">The number of bytes of data sent.</param>
         /// <param name="totalLength">The total number of bytes sent.</param>
         /// <remarks>
         ///     This should be called after the data has been sent and should only be called for data that is sent sucessfully.
         /// </remarks>
-        internal void LogSend(int dataLength, int totalLength)
+        internal void LogUnreliableSend(int dataLength, int totalLength)
         {
-            Interlocked.Increment(ref messagesSent);
+            Interlocked.Increment(ref unreliableMessagesSent);
             Interlocked.Add(ref dataBytesSent, dataLength);
             Interlocked.Add(ref totalBytesSent, totalLength);
         }
 
         /// <summary>
-        ///     Logs the receiving of a data packet in the statistics.
+        ///     Logs the sending of a reliable data packet in the statistics.
+        /// </summary>
+        /// <param name="dataLength">The number of bytes of data sent.</param>
+        /// <param name="totalLength">The total number of bytes sent.</param>
+        /// <remarks>
+        ///     This should be called after the data has been sent and should only be called for data that is sent sucessfully.
+        /// </remarks>
+        internal void LogReliableSend(int dataLength, int totalLength)
+        {
+            Interlocked.Increment(ref reliableMessagesSent);
+            Interlocked.Add(ref dataBytesSent, dataLength);
+            Interlocked.Add(ref totalBytesSent, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the sending of a fragmented data packet in the statistics.
+        /// </summary>
+        /// <param name="dataLength">The number of bytes of data sent.</param>
+        /// <param name="totalLength">The total number of bytes sent.</param>
+        /// <remarks>
+        ///     This should be called after the data has been sent and should only be called for data that is sent sucessfully.
+        /// </remarks>
+        internal void LogFragmentedSend(int dataLength, int totalLength)
+        {
+            Interlocked.Increment(ref fragmentedMessagesSent);
+            Interlocked.Add(ref dataBytesSent, dataLength);
+            Interlocked.Add(ref totalBytesSent, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the sending of a acknowledgement data packet in the statistics.
+        /// </summary>
+        /// <param name="totalLength">The total number of bytes sent.</param>
+        /// <remarks>
+        ///     This should be called after the data has been sent and should only be called for data that is sent sucessfully.
+        /// </remarks>
+        internal void LogAcknowledgementSend(int totalLength)
+        {
+            Interlocked.Increment(ref acknowledgementMessagesSent);
+            Interlocked.Add(ref totalBytesSent, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the sending of a hellp data packet in the statistics.
+        /// </summary>
+        /// <param name="totalLength">The total number of bytes sent.</param>
+        /// <remarks>
+        ///     This should be called after the data has been sent and should only be called for data that is sent sucessfully.
+        /// </remarks>
+        internal void LogHelloSend(int totalLength)
+        {
+            Interlocked.Increment(ref helloMessagesSent);
+            Interlocked.Add(ref totalBytesSent, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the receiving of an unreliable data packet in the statistics.
+        /// </summary>
+        /// <param name="dataLength">The number of bytes of data received.</param>
+        /// <param name="totalLength">The total number of bytes received.</param>
+        /// <remarks>
+        ///     This should be called before the received event is invoked so it is up to date for subscribers to that event.
+        /// </remarks>
+        internal void LogUnreliableReceive(int dataLength, int totalLength)
+        {
+            Interlocked.Increment(ref unreliableMessagesReceived);
+            Interlocked.Add(ref dataBytesReceived, dataLength);
+            Interlocked.Add(ref totalBytesReceived, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the receiving of a reliable data packet in the statistics.
+        /// </summary>
+        /// <param name="dataLength">The number of bytes of data received.</param>
+        /// <param name="totalLength">The total number of bytes received.</param>
+        /// <remarks>
+        ///     This should be called before the received event is invoked so it is up to date for subscribers to that event.
+        /// </remarks>
+        internal void LogReliableReceive(int dataLength, int totalLength)
+        {
+            Interlocked.Increment(ref reliableMessagesReceived);
+            Interlocked.Add(ref dataBytesReceived, dataLength);
+            Interlocked.Add(ref totalBytesReceived, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the receiving of a fragmented data packet in the statistics.
         /// </summary>
         /// <param name="dataLength">The number of bytes of data received.</param>
         /// <param name="totalLength">The total number of bytes received.</param>
         /// <remarks>
         ///     This should be called before the received event is invoked so it is up to date for subscribers to that event.
         /// </remarks>
-        internal void LogReceive(int dataLength, int totalLength)
+        internal void LogFragmentedReceive(int dataLength, int totalLength)
         {
-            Interlocked.Increment(ref messagesReceived);
+            Interlocked.Increment(ref fragmentedMessagesReceived);
             Interlocked.Add(ref dataBytesReceived, dataLength);
             Interlocked.Add(ref totalBytesReceived, totalLength);
         }
+
+        /// <summary>
+        ///     Logs the receiving of an acknowledgement data packet in the statistics.
+        /// </summary>
+        /// <param name="totalLength">The total number of bytes received.</param>
+        /// <remarks>
+        ///     This should be called before the received event is invoked so it is up to date for subscribers to that event.
+        /// </remarks>
+        internal void LogAcknowledgementReceive(int totalLength)
+        {
+            Interlocked.Increment(ref acknowledgementMessagesReceived);
+            Interlocked.Add(ref totalBytesReceived, totalLength);
+        }
+
+        /// <summary>
+        ///     Logs the receiving of a hello data packet in the statistics.
+        /// </summary>
+        /// <param name="totalLength">The total number of bytes received.</param>
+        /// <remarks>
+        ///     This should be called before the received event is invoked so it is up to date for subscribers to that event.
+        /// </remarks>
+        internal void LogHelloReceive(int totalLength)
+        {
+            Interlocked.Increment(ref helloMessagesReceived);
+            Interlocked.Add(ref totalBytesReceived, totalLength);
+        }
     }
 }
index d03fb6b7b5cb1ec71e5262c387db7104c787fda8..a4db5c693ba42e563332cbb533a1198bac18c663 100644 (file)
@@ -37,3 +37,6 @@ using System.Runtime.InteropServices;
 
 // NuGet version information
 [assembly: AssemblyInformationalVersion("0.0.0-beta")]
+
+// Show internals to unit testing assembly so it can test
+[assembly:InternalsVisibleTo("Hazel.UnitTests")]
\ No newline at end of file
index c64190761db4934a45da5f8a8b60fba7751f024d..99d60c1be5e82d09c2c9e1112038e6cbde8d2ee3 100644 (file)
@@ -157,7 +157,7 @@ namespace Hazel.Tcp
                 }
             }
 
-            Statistics.LogSend(bytes.Length, fullBytes.Length);
+            Statistics.LogFragmentedSend(bytes.Length, fullBytes.Length);
         }
 
         /// <summary>
@@ -197,7 +197,7 @@ namespace Hazel.Tcp
                 HandleDisconnect(new HazelException("An exception occured while initiating a header receive operation.", e));
             }
 
-            Statistics.LogReceive(bytes.Length, bytes.Length + 4);
+            Statistics.LogFragmentedReceive(bytes.Length, bytes.Length + 4);
 
             //Fire DataReceived event
             InvokeDataReceived(bytes, SendOption.FragmentedReliable);
index 0ced33401b2a3cebf1f9096f0e4620094432e807..2b5868353082301dac914a6941781609c304c497 100644 (file)
@@ -253,7 +253,7 @@ namespace Hazel.Udp
             //Write to connection
             WriteBytesToConnection(bytes);
 
-            Statistics.LogSend(data.Length, bytes.Length);
+            Statistics.LogReliableSend(data.Length, bytes.Length);
         }
 
         /// <summary>
@@ -265,7 +265,7 @@ namespace Hazel.Udp
             if (ProcessReliableReceive(buffer))
                 InvokeDataReceived(SendOption.Reliable, buffer, 3);
 
-            Statistics.LogReceive(buffer.Length - 3, buffer.Length);
+            Statistics.LogReliableReceive(buffer.Length - 3, buffer.Length);
         }
 
         /// <summary>
@@ -376,7 +376,7 @@ namespace Hazel.Udp
                 }
             }
             
-            Statistics.LogReceive(0, bytes.Length);
+            Statistics.LogReliableReceive(0, bytes.Length);
         }
 
         /// <summary>
index e65b1f5d45e9b86f45a29fe4d51763ffa8627bb9..7e7e745dbb572e3ff1f7e38671108139ec2f0b9b 100644 (file)
@@ -98,18 +98,17 @@ namespace Hazel.Udp
                 //We need to acknowledge hello messages but dont want to invoke any events!
                 case (byte)SendOptionInternal.Hello:
                     ProcessReliableReceive(buffer);
-                    Statistics.LogReceive(buffer.Length - 3, buffer.Length);
+                    Statistics.LogHelloReceive(buffer.Length);
                     break;
 
                 case (byte)SendOptionInternal.Disconnect:
-                    HandleDisconnect();
-                    Statistics.LogReceive(0, buffer.Length);
+                    HandleDisconnect();                    
                     break;
 
                 //Treat everything else as unreliable
                 default:
                     InvokeDataReceived(SendOption.None, buffer, 1);
-                    Statistics.LogReceive(buffer.Length - 1, buffer.Length);
+                    Statistics.LogUnreliableReceive(buffer.Length - 1, buffer.Length);
                     break;
             }
         }
@@ -127,7 +126,7 @@ namespace Hazel.Udp
             //Write to connection
             WriteBytesToConnection(bytes);
 
-            Statistics.LogSend(data.Length, bytes.Length);
+            Statistics.LogUnreliableSend(data.Length, bytes.Length);
         }
 
         /// <summary>