]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Initial fix ideas
authorJamJar00 <jamster.30@btinternet.com>
Fri, 18 Nov 2016 00:04:39 +0000 (00:04 +0000)
committerJamJar00 <jamster.30@btinternet.com>
Fri, 18 Nov 2016 00:04:39 +0000 (00:04 +0000)
Hazel Networking Protocol.docx [new file with mode: 0644]
Hazel/Udp/UdpClientConnection.cs
Hazel/Udp/UdpConnectionListener.cs

diff --git a/Hazel Networking Protocol.docx b/Hazel Networking Protocol.docx
new file mode 100644 (file)
index 0000000..fd9c965
Binary files /dev/null and b/Hazel Networking Protocol.docx differ
index 04ff3a0192539ddfab5b1c29f2a75e8a15c6af81..afcc12492f414f4e9038aba0df37cd2c0eac84f4 100644 (file)
@@ -59,11 +59,6 @@ namespace Hazel.Udp
         /// <inheritdoc />
         protected override void WriteBytesToConnection(byte[] bytes)
         {
-            //Pack
-            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
-            args.SetBuffer(bytes, 0, bytes.Length);
-            args.RemoteEndPoint = RemoteEndPoint;
-
             lock (socketLock)
             {
                 if (State != ConnectionState.Connected && State != ConnectionState.Connecting)
@@ -71,7 +66,26 @@ namespace Hazel.Udp
 
                 try
                 {
-                    socket.SendToAsync(args);
+                    socket.BeginSendTo(
+                        bytes, 
+                        0, 
+                        bytes.Length, 
+                        SocketFlags.None, 
+                        RemoteEndPoint,
+                        delegate (IAsyncResult result)
+                        {
+                            try
+                            {
+                                lock (socket)
+                                    socket.EndSendTo(result);
+                            }
+                            catch (SocketException e)
+                            {
+                                HandleDisconnect(new HazelException("Could not send data as a SocketException occured.", e));
+                            }
+                        }, 
+                        null
+                    );
                 }
                 catch (ObjectDisposedException)
                 {
index f999202f784e0790a4e7fd5393d11b7e13cd0752..1d1048977f56f50a3e0334d5f0cc1e632a10a7fd 100644 (file)
@@ -180,14 +180,23 @@ namespace Hazel.Udp
         /// <param name="endPoint">The endpoint to send to.</param>
         internal void SendData(byte[] bytes, EndPoint endPoint)
         {
-            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
-            args.SetBuffer(bytes, 0, bytes.Length);
-            args.RemoteEndPoint = endPoint;
-
             try
             {
                 lock (listener)
-                    listener.SendToAsync(args);
+                {
+                    listener.BeginSendTo(
+                        bytes,
+                        0,
+                        bytes.Length,
+                        SocketFlags.None,
+                        endPoint,
+                        delegate (IAsyncResult result)
+                        {
+                            listener.EndSendTo(result);
+                        },
+                        null
+                    );
+                }
             }
             catch (SocketException e)
             {