]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Clean up some stuff
authorForest <chocozilla@gmail.com>
Wed, 2 Jan 2019 19:27:16 +0000 (11:27 -0800)
committerForest <chocozilla@gmail.com>
Thu, 3 Jan 2019 19:58:35 +0000 (11:58 -0800)
Hazel/Connection.cs
Hazel/NetworkConnectionListener.cs
Hazel/Udp/UdpClientConnection.cs
Hazel/Udp/UdpConnection.Reliable.cs
Hazel/Udp/UdpConnection.cs
Hazel/Udp/UdpConnectionListener.cs
Hazel/Udp/UdpServerConnection.cs

index f136ffc133da399fb1f327a7bcea292e5e34b831..5e14cc66e40af5a9a067d1a71eaf1a83967b8243 100644 (file)
@@ -113,20 +113,20 @@ namespace Hazel
         {
             get
             {
-                return this.state;
+                return this._state;
             }
             
             protected set
             {
-                this.state = value;
-                if (this.state == ConnectionState.Connected)
+                this._state = value;
+                if (this._state == ConnectionState.Connected)
                     connectWaitLock.Set();
                 else
                     connectWaitLock.Reset();
             }
         }
 
-        protected ConnectionState state;
+        protected ConnectionState _state;
 
         /// <summary>
         ///     Reset event that is triggered when the connection is marked Connected.
index 1e5e237aaa00e17b90abb9a6208bc47897205c1e..af26c4c48ba2408e002fe1d02cb28fbbe7289f0c 100644 (file)
@@ -16,7 +16,7 @@ namespace Hazel
         /// <summary>
         ///     The local end point the listener is listening for new clients on.
         /// </summary>
-        public EndPoint EndPoint { get; protected set; }
+        public IPEndPoint EndPoint { get; protected set; }
 
         /// <summary>
         ///     The <see cref="IPMode">IPMode</see> the listener is listening for new clients on.
index 048ff60cf18f01a02f814bcbb9aeaa290468a121..4dd101ec9c59a27c333ffbb3ac6a0611189a3ba5 100644 (file)
@@ -78,9 +78,6 @@ namespace Hazel.Udp
         {
             DataSentRaw?.Invoke(bytes, length);
 
-            if (State != ConnectionState.Connected && State != ConnectionState.Connecting)
-                throw new InvalidOperationException("Could not send data as this Connection is not connected and is not connecting. Did you disconnect?");
-
             try
             {
                 socket.BeginSendTo(
@@ -123,9 +120,6 @@ namespace Hazel.Udp
         {
             DataSentRaw?.Invoke(bytes, length);
 
-            if (State != ConnectionState.Connected && State != ConnectionState.Connecting)
-                throw new InvalidOperationException("Could not send data as this Connection is not connected and is not connecting. Did you disconnect?");
-
             try
             {
                 socket.SendTo(
@@ -166,10 +160,7 @@ namespace Hazel.Udp
         /// <inheritdoc />
         public override void ConnectAsync(byte[] bytes = null, int timeout = 5000)
         {
-            if (State != ConnectionState.NotConnected)
-                throw new InvalidOperationException("Cannot connect as the Connection is already connected.");
-
-            State = ConnectionState.Connecting;
+            this.State = ConnectionState.Connecting;
 
             //Begin listening
             try
@@ -292,11 +283,11 @@ namespace Hazel.Udp
         {
             if (disposing)
             {
-                if (this.state == ConnectionState.Connected
-                    || this.state == ConnectionState.Disconnecting)
+                if (this._state == ConnectionState.Connected
+                    || this._state == ConnectionState.Disconnecting)
                 {
-                    // SendDisconnect();
-                    this.state = ConnectionState.NotConnected;
+                    SendDisconnect();
+                    this._state = ConnectionState.NotConnected;
                 }
             }
 
index 4788cdbbe3309c1e7a00a83861897fc5b019fa73..0e1182e288808a269d8dec7828c80290a5e50769 100644 (file)
@@ -200,12 +200,12 @@ namespace Hazel.Udp
                 foreach (var kvp in this.reliableDataPacketsSent)
                 {
                     Packet pkt = kvp.Value;
-                    
-                        try
-                        {
-                            output += pkt.Resend();
-                        }
-                        catch { }
+
+                    try
+                    {
+                        output += pkt.Resend();
+                    }
+                    catch { }
 
                     minTimeout = Math.Min(pkt.NextTimeout, minTimeout);
                 }
@@ -239,8 +239,7 @@ namespace Hazel.Udp
                 buffer,
                 sendLength,
                 resendTimeout > 0 ? resendTimeout : (int)Math.Max(300, Math.Min(AveragePingMs * this.ResendPingMultiplier, 2000)),
-                ackCallback
-            );
+                ackCallback);
 
             if (!reliableDataPacketsSent.TryAdd(id, packet))
             {
index a488cdeda3feb6f61cfa62e99d7de61b22c34097..7c1b59260299f072156b542a358133e07016ad4e 100644 (file)
@@ -41,7 +41,7 @@ namespace Hazel.Udp
         public override void Send(MessageWriter msg)
         {
             //Early check
-            if (State != ConnectionState.Connected)
+            if (this._state != ConnectionState.Connected)
                 throw new InvalidOperationException("Could not send data as this Connection is not connected. Did you disconnect?");
 
             byte[] buffer = new byte[msg.Length];
@@ -75,10 +75,6 @@ namespace Hazel.Udp
         /// </remarks>
         public override void SendBytes(byte[] bytes, SendOption sendOption = SendOption.None)
         {
-            //Early check
-            if (State != ConnectionState.Connected)
-                throw new InvalidOperationException("Could not send data as this Connection is not connected. Did you disconnect?");
-
             //Add header information and send
             HandleSend(bytes, (byte)sendOption);
         }
@@ -100,10 +96,6 @@ namespace Hazel.Udp
         /// </remarks>
         public override void SendBytes(byte[] bytes, int offset, int length, SendOption sendOption = SendOption.None)
         {
-            //Early check
-            if (State != ConnectionState.Connected)
-                throw new InvalidOperationException("Could not send data as this Connection is not connected. Did you disconnect?");
-
             switch (sendOption)
             {
                 //Handle reliable header and hellos
@@ -269,9 +261,9 @@ namespace Hazel.Udp
             bool invoke = false;
             lock (this)
             {
-                if (this.state == ConnectionState.Connected)
+                if (this._state == ConnectionState.Connected)
                 {
-                    this.state = skipSendDisconnect ? ConnectionState.NotConnected : ConnectionState.Disconnecting;
+                    this._state = skipSendDisconnect ? ConnectionState.NotConnected : ConnectionState.Disconnecting;
                     invoke = true;
                 }
             }
index e8f4defbc387e41b5df52b6c08664b23d1d11064..b61a91a2c91488c365df6d09865c1cd829d68c5b 100644 (file)
@@ -57,6 +57,9 @@ namespace Hazel.Udp
                 this.socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
             }
 
+            socket.ReceiveBufferSize = 4194304;
+            socket.SendBufferSize = 1048576;
+            
             reliablePacketTimer = new Timer(ManageReliablePackets, null, 100, Timeout.Infinite);
         }
 
@@ -100,7 +103,7 @@ namespace Hazel.Udp
         /// <summary>
         ///     Instructs the listener to begin listening.
         /// </summary>
-        public void StartListeningForData()
+        private void StartListeningForData()
         {
             EndPoint remoteEP = EndPoint;
 
@@ -214,21 +217,9 @@ namespace Hazel.Udp
                 }
             }
 
-            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
-            try
-            {
-                //Inform the connection of the buffer (new connections need to send an ack back to client)
-                connection.HandleReceive(message, bytesReceived);
-            }
-            finally
-            {
-                var el = stopwatch.ElapsedMilliseconds;
-                if (el > 5)
-                {
-                    this.Logger?.Invoke($"Long Packet {el}ms = {string.Join(" ", message.Buffer.Take(bytesReceived))}");
-                }
-            }
-
+            //Inform the connection of the buffer (new connections need to send an ack back to client)
+            connection.HandleReceive(message, bytesReceived);
+            
             //If it's a new connection invoke the NewConnection event.
             if (!aware)
             {
index b0f5058477a52648da3236d0217b677b47d8ae9f..a9f63c4f29c1392d0a426f885d1d73f58df4f92d 100644 (file)
@@ -21,12 +21,7 @@ namespace Hazel.Udp
         ///     created this connection and is hence the listener this conenction sends and receives via.
         /// </remarks>
         public UdpConnectionListener Listener { get; private set; }
-
-        /// <summary>
-        ///     Lock object for the writing to the state of the connection.
-        /// </summary>
-        private ReaderWriterLockSlim stateLock = new ReaderWriterLockSlim();
-
+        
         /// <summary>
         ///     Creates a UdpConnection for the virtual connection to the endpoint.
         /// </summary>
@@ -47,9 +42,6 @@ namespace Hazel.Udp
         /// <inheritdoc />
         protected override void WriteBytesToConnection(byte[] bytes, int length)
         {
-            if (State != ConnectionState.Connected)
-                throw new InvalidOperationException("Could not send data: Not connected.");
-
             Listener.SendData(bytes, length, RemoteEndPoint);
         }
 
@@ -98,11 +90,11 @@ namespace Hazel.Udp
 
             if (disposing)
             {
-                if (this.state == ConnectionState.Connected
-                    || this.state == ConnectionState.Disconnecting)
+                if (this._state == ConnectionState.Connected
+                    || this._state == ConnectionState.Disconnecting)
                 {
                     SendDisconnect();
-                    this.state = ConnectionState.NotConnected;
+                    this._state = ConnectionState.NotConnected;
                 }
             }