]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Reduced to .NET target version 3.5 and refactored IPv6 support to fit.
authorJamJar00 <jamster.30@btinternet.com>
Sun, 17 Jul 2016 14:31:46 +0000 (15:31 +0100)
committerJamJar00 <jamster.30@btinternet.com>
Sun, 17 Jul 2016 14:31:46 +0000 (15:31 +0100)
24 files changed:
Hazel.UnitTests/Hazel.UnitTests.csproj
Hazel.UnitTests/TcpConnectionTests.cs
Hazel.UnitTests/UdpConnectionTests.cs
Hazel/ConnectionListener.cs
Hazel/ConnectionStatistics.cs
Hazel/DisconnectedEventArgs.cs
Hazel/DocInclude/TcpListenerExample.cs
Hazel/DocInclude/UdpListenerExample.cs
Hazel/Hazel.csproj
Hazel/IPMode.cs
Hazel/NetworkConnection.cs
Hazel/NetworkConnectionListener.cs
Hazel/NetworkEndPoint.cs
Hazel/ObjectPool.cs
Hazel/SendOption.cs
Hazel/SendOptionInternal.cs
Hazel/Tcp/StateObject.cs
Hazel/Tcp/TcpConnection.cs
Hazel/Tcp/TcpConnectionListener.cs
Hazel/Udp/UdpClientConnection.cs
Hazel/Udp/UdpConnection.KeepAlive.cs
Hazel/Udp/UdpConnection.Reliable.cs
Hazel/Udp/UdpConnectionListener.cs
Hazel/Udp/UdpServerConnection.cs

index 62520fde33ae55b57e2dd04a46ec41983c308112..466c3346bd237cf899e0137c0924efbc06a63cc7 100644 (file)
@@ -8,7 +8,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Hazel.UnitTests</RootNamespace>
     <AssemblyName>Hazel.UnitTests</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@@ -16,6 +16,7 @@
     <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
     <IsCodedUITest>False</IsCodedUITest>
     <TestProjectType>UnitTest</TestProjectType>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
index ccdf31460aa8ab8b12b89476daf78c457e6ac965..b092b5ec031651964843dc026880c9b2199bb04d 100644 (file)
@@ -54,18 +54,13 @@ namespace Hazel.UnitTests
         ///     Tests dual mode connectivity.
         /// </summary>
         [TestMethod]
-        public void TcpDualModeConnectionTest()
+        public void TcpIPv6ConnectionTest()
         {
-            using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4AndIPv6))
+            using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.IPv6Any, 4296, IPMode.IPv6))
             {
                 listener.Start();
 
-                using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
-                {
-                    connection.Connect();
-                }
-
-                using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4AndIPv6)))
+                using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.IPv6Loopback, 4296, IPMode.IPv6)))
                 {
                     connection.Connect();
                 }
index 3db82c56b367b35f4c86e268e3d3bb678fb7b8ba..003cc22e49d943124c132f518aaf1b85e1ee6c7d 100644 (file)
@@ -18,7 +18,7 @@ namespace Hazel.UnitTests
         {
             NetworkEndPoint ep = new NetworkEndPoint(IPAddress.Loopback, 4296);
 
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(ep))
             {
                 listener.Start();
@@ -41,7 +41,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpIPv4ConnectionTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
             {
                 listener.Start();
@@ -54,18 +54,13 @@ namespace Hazel.UnitTests
         ///     Tests dual mode connectivity.
         /// </summary>
         [TestMethod]
-        public void UdpDualModeConnectionTest()
+        public void UdpIPv6ConnectionTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4AndIPv6))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.IPv6Any, 4296, IPMode.IPv6)))
             {
                 listener.Start();
 
-                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
-                {
-                    connection.Connect();
-                }
-
-                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4AndIPv6)))
+                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.IPv6Loopback, 4296, IPMode.IPv6)))
                 {
                     connection.Connect();
                 }
@@ -78,7 +73,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpUnreliableServerToClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerToClientTest(listener, connection, 1, 3, SendOption.None);
@@ -91,7 +86,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpReliableServerToClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerToClientTest(listener, connection, 3, 3, SendOption.Reliable);
@@ -104,7 +99,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpUnreliableClientToServerTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientToServerTest(listener, connection, 1, 3, SendOption.None);
@@ -117,7 +112,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpReliableClientToServerTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientToServerTest(listener, connection, 3, 3, SendOption.Reliable);
@@ -130,7 +125,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void KeepAliveClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.Start();
@@ -156,7 +151,7 @@ namespace Hazel.UnitTests
         {
             ManualResetEvent mutex = new ManualResetEvent(false);
 
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.NewConnection += delegate(object sender, NewConnectionEventArgs args)
@@ -188,7 +183,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void ClientDisconnectTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientDisconnectTest(listener, connection);
@@ -201,7 +196,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void ServerDisconnectTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerDisconnectTest(listener, connection);
index 4cd01a83c0108dde4606b65da3b3e94df8f1044a..e24962aa8dae6aa119186fe3a6dec290dba0b4a5 100644 (file)
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
index 450c3d6c6c57e3a2fd9c4646d1c0f38ab8acf26c..85f40e765e257c561d4e2d37c9b64e79a56000dc 100644 (file)
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
index 21e29f58487f1a1e3a95b073078ecf791cd41dbf..36ec2e5a604192e29578e746b96187cc8b1c5b36 100644 (file)
@@ -16,7 +16,7 @@ namespace Hazel
     ///     <include file="DocInclude/common.xml" path="docs/item[@name='Recyclable']/*" />
     /// </remarks>
     /// <threadsafety static="true" instance="true"/>
-    public class DisconnectedEventArgs : IRecyclable
+    public class DisconnectedEventArgs : EventArgs, IRecyclable
     {
         /// <summary>
         ///     Object pool for this event.
index bac1feefa3833d811b253be2ad37dc58ec2f6ede..468452be949dc135e7e02d11f7f2eca3ec8c8988 100644 (file)
@@ -3,7 +3,7 @@
     static void Main(string[] args)
     {
         //Setup listener
-        using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296))
+        using (TcpConnectionListener listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
         {
             //Start listening for new connection events
             listener.NewConnection += delegate(object sender, NewConnectionEventArgs a)
index 73c24321d93a146c70d355f8e9f7cce4745eee2d..4c26c4968529669c5365bf95dd204fa8434b865a 100644 (file)
@@ -3,7 +3,7 @@
     static void Main(string[] args)
     {
         //Setup listener
-        using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296))
+        using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
         {
             //Start listening for new connection events
             listener.NewConnection += delegate(object sender, NewConnectionEventArgs a)
index 1bf7a708769b5cdbbca5b30ab110edf476d3bb9c..2b143af1bd7a6d839a64711f0c4643d6ef4f30f6 100644 (file)
@@ -9,8 +9,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Hazel</RootNamespace>
     <AssemblyName>Hazel</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -44,7 +45,6 @@
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
   </ItemGroup>
index 1c8c48248d0ba2f62b650f68d5280abd4ecff199..04c8c3875a4ab5d472ce527801932c8df918bf7a 100644 (file)
@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
@@ -22,8 +22,9 @@ namespace Hazel
         IPv4,
 
         /// <summary>
-        ///     Instruction to use dual mode sockets, both IPv4 and IPv6 connections will be able to connect.
+        ///     Instruction to use IPv6 only, IPv4 connections will not be able to connect. IPv4 addresses can be connected 
+        ///     by converting to IPv6 addresses.
         /// </summary>
-        IPv4AndIPv6
+        IPv6
     }
 }
index 18a660e4e060c64fce2a6d9a8b9cac6878e383fc..7aef3e4f96e17bff4dc6d14b48ecce6b93bda38e 100644 (file)
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
@@ -21,5 +21,10 @@ namespace Hazel
         ///     <see cref="ConnectionEndPoint"/> as the base <see cref="Connection"/> does.
         /// </remarks>
         public EndPoint RemoteEndPoint { get; protected set; }
+
+        /// <summary>
+        ///     The <see cref="IPMode">IPMode</see> the client is connected using.
+        /// </summary>
+        public IPMode IPMode { get; protected set; }
     }
 }
index 30be50540297803e9da0bb363f3f0df3750fa189..1e5e237aaa00e17b90abb9a6208bc47897205c1e 100644 (file)
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
@@ -14,13 +14,13 @@ namespace Hazel
     public abstract class NetworkConnectionListener : ConnectionListener
     {
         /// <summary>
-        ///     The local IP address the listener is listening for new clients on.
+        ///     The local end point the listener is listening for new clients on.
         /// </summary>
-        public IPAddress IPAddress { get; protected set; }
+        public EndPoint EndPoint { get; protected set; }
 
         /// <summary>
-        ///     The port the listener is listening for new clients on.
+        ///     The <see cref="IPMode">IPMode</see> the listener is listening for new clients on.
         /// </summary>
-        public int Port { get; protected set; }
+        public IPMode IPMode { get; protected set; }
     }
 }
index 7e7117134027a099b221e4a42f280d1a3337e9aa..b6b642726d03f4adb2f5ca81239077419cc91852 100644 (file)
@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
+
 
 using System.Net;
 
@@ -32,7 +32,7 @@ namespace Hazel
         /// </summary>
         /// <param name="endPoint">The end point to wrap.</param>
         /// <param name="mode">The IP mode to use.</param>
-        public NetworkEndPoint(EndPoint endPoint, IPMode mode = IPMode.IPv4AndIPv6)
+        public NetworkEndPoint(EndPoint endPoint, IPMode mode = IPMode.IPv4)
         {
             this.EndPoint = endPoint;
             this.IPMode = mode;
@@ -47,8 +47,8 @@ namespace Hazel
         /// <remarks>
         ///     When using this constructor <see cref="EndPoint"/> will contain an <see cref="IPEndPoint"/>.
         /// </remarks>
-        public NetworkEndPoint(IPAddress address, int port, IPMode mode = IPMode.IPv4AndIPv6)
-            : this(new IPEndPoint(address, port))
+        public NetworkEndPoint(IPAddress address, int port, IPMode mode = IPMode.IPv4)
+            : this(new IPEndPoint(address, port), mode)
         {
 
         }
@@ -62,8 +62,8 @@ namespace Hazel
         /// <remarks>
         ///     When using this constructor <see cref="EndPoint"/> will contain an <see cref="IPEndPoint"/>.
         /// </remarks>
-        public NetworkEndPoint(string IP, int port, IPMode mode = IPMode.IPv4AndIPv6)
-            : this(IPAddress.Parse(IP), port)
+        public NetworkEndPoint(string IP, int port, IPMode mode = IPMode.IPv4)
+            : this(IPAddress.Parse(IP), port, mode)
         {
             
         }
index 7a410e41f8a41960c1c5e9dfefd6d5d38a6c9c85..a4d8d68426c45e2f1c2058c2a3554bd082099b64 100644 (file)
@@ -1,9 +1,11 @@
 ï»¿using System;
+#if NET_45
 using System.Collections.Concurrent;
+#else
 using System.Collections.Generic;
+#endif
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Hazel
 {
@@ -17,7 +19,11 @@ namespace Hazel
         /// <summary>
         ///     Our pool of objects
         /// </summary>
+#if NET_45
         ConcurrentBag<T> pool = new ConcurrentBag<T>();
+#else
+        Queue<T> pool = new Queue<T>();
+#endif
 
         /// <summary>
         ///     The generator for creating new objects.
@@ -39,10 +45,17 @@ namespace Hazel
         /// <returns>An instance of T.</returns>
         internal T GetObject()
         {
+#if NET_45
             T item;
             if (pool.TryTake(out item))
                 return item;
-
+#else
+            lock (pool)
+            {
+                if (pool.Count > 0)
+                    return pool.Dequeue();
+            }
+#endif
             return objectFactory.Invoke();
         }
 
@@ -52,7 +65,12 @@ namespace Hazel
         /// <param name="item">The item to return.</param>
         internal void PutObject(T item)
         {
+#if NET_45
             pool.Add(item);
+#else
+            lock (pool)
+                pool.Enqueue(item);
+#endif
         }
     }
 }
index 2629711ef21ab84839ad001a0f0009c2af64cf6a..a81fded3d2b93380c9fcf17faea5e522f47b99a1 100644 (file)
@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Hazel
 {
index e39e7e53953afe7aa3d8ec0d0e0abb97ed253694..2a7a707bae0b27b606742ca60e64f28f22bba34c 100644 (file)
@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel
 {
index c5878f9fab694a06ef653d78dff9aacbae660f7f..8c4ac20768cceccc5db40ee29fdb9dd2905aecd4 100644 (file)
@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Hazel.Tcp
 {
index 62e32cb4528e897dd636e1a26e938853bce51128..2507870d2673dc3ab7c93a183be8a8f82b5fe55c 100644 (file)
@@ -58,6 +58,7 @@ namespace Hazel.Tcp
 
                 this.EndPoint = remoteEndPoint;
                 this.RemoteEndPoint = remoteEndPoint.EndPoint;
+                this.IPMode = remoteEndPoint.IPMode;
 
                 //Create a socket
                 if (remoteEndPoint.IPMode == IPMode.IPv4)
@@ -68,12 +69,9 @@ namespace Hazel.Tcp
                         throw new HazelException("IPV6 not supported!");
 
                     socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
+                    socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
                 }
 
-                //Set parameters of socket
-                if (remoteEndPoint.IPMode == IPMode.IPv4AndIPv6)
-                    socket.DualMode = true;
-
                 socket.NoDelay = true;
             }
         }
@@ -349,7 +347,7 @@ namespace Hazel.Tcp
 
                     if (socket.Connected)
                         socket.Shutdown(SocketShutdown.Send);
-                    socket.Dispose();
+                    socket.Close();
                 }
             }
 
index 055febe2b5240618f63f0d2232698eb788428cc0..78b7fa0c3e20cf0416142d5c166773651ec40728 100644 (file)
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Tcp
 {
@@ -25,12 +25,23 @@ namespace Hazel.Tcp
         /// <param name="IPAddress">The IPAddress to listen on.</param>
         /// <param name="port">The port to listen on.</param>
         /// <param name="mode">The <see cref="IPMode"/> to listen with.</param>
-        public TcpConnectionListener(IPAddress IPAddress, int port, IPMode mode = IPMode.IPv4AndIPv6)
+        [Obsolete("Temporary constructor in beta only, use NetworkEndPoint constructor instead.")]
+        public TcpConnectionListener(IPAddress IPAddress, int port, IPMode mode = IPMode.IPv4)
+            : this (new NetworkEndPoint(IPAddress, port, mode))
+        {
+
+        }
+
+        /// <summary>
+        ///     Creates a new TcpConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
+        /// </summary>
+        /// <param name="endPoint">The end point to listen on.</param>
+        public TcpConnectionListener(NetworkEndPoint endPoint)
         {
-            this.IPAddress = IPAddress;
-            this.Port = port;
+            this.EndPoint = endPoint.EndPoint;
+            this.IPMode = endPoint.IPMode;
 
-            if (mode == IPMode.IPv4)
+            if (endPoint.IPMode == IPMode.IPv4)
                 this.listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             else
             {
@@ -38,10 +49,8 @@ namespace Hazel.Tcp
                     throw new HazelException("IPV6 not supported!");
 
                 this.listener = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+                this.listener.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
             }
-            
-            if (mode == IPMode.IPv4AndIPv6)
-                this.listener.DualMode = true;
         }
 
         /// <inheritdoc />
@@ -51,7 +60,7 @@ namespace Hazel.Tcp
             {
                 lock (listener)
                 {
-                    listener.Bind(new IPEndPoint(IPAddress, Port));
+                    listener.Bind(EndPoint);
                     listener.Listen(1000);
 
                     listener.BeginAccept(AcceptConnection, null);
@@ -102,7 +111,7 @@ namespace Hazel.Tcp
             if (disposing)
             {
                 lock (listener)
-                    listener.Dispose();
+                    listener.Close();
             }
 
             base.Dispose(disposing);
index c0df18bd29534414ed21bbeb006c4715cf3dd7f1..f8836fbaa0e950d3ecbf606b64d0d4c4838e4bbc 100644 (file)
@@ -5,7 +5,7 @@ using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Udp
 {
@@ -41,13 +41,17 @@ namespace Hazel.Udp
             {
                 this.EndPoint = remoteEndPoint;
                 this.RemoteEndPoint = remoteEndPoint.EndPoint;
+                this.IPMode = remoteEndPoint.IPMode;
 
                 if (remoteEndPoint.IPMode == IPMode.IPv4)
                     socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                 else
                 {
+                    if (!Socket.OSSupportsIPv6)
+                        throw new HazelException("IPV6 not supported!");
+
                     socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
-                    socket.DualMode = true;
+                    socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);    //TODO these lines shouldn't be needed anymore
                 }
             }
         }
@@ -96,7 +100,10 @@ namespace Hazel.Udp
                 //Begin listening
                 try
                 {
-                    socket.Bind(new IPEndPoint(IPAddress.Any, 0));
+                    if (IPMode == IPMode.IPv4)
+                        socket.Bind(new IPEndPoint(IPAddress.Any, 0));
+                    else
+                        socket.Bind(new IPEndPoint(IPAddress.IPv6Any, 0));
                 }
                 catch (SocketException e)
                 {
@@ -232,7 +239,7 @@ namespace Hazel.Udp
                 {
                     State = ConnectionState.NotConnected;
 
-                    socket.Dispose();
+                    socket.Close();
                 }
             }
 
index f2864f7edc4ddc04550001e2f310e233e57de63d..d789a48800faeb93ed2683cb16adeb5eefe8e357 100644 (file)
@@ -4,7 +4,7 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Udp
 {
index 05d6b8961084c7b18c32cbbe482cc1f6c1ccd3e1..f3217f4765eb233de25b3c88bb88eba6b1017895 100644 (file)
@@ -4,7 +4,7 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Udp
 {
index 6d0c9c88d5d30618ea928c47d2d56f159a02152f..066975dd792c320382ac00a84cdb36b42775a3dc 100644 (file)
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Udp
 {
@@ -19,8 +19,6 @@ namespace Hazel.Udp
         /// </summary>
         Socket listener;
 
-        IPEndPoint bindOn;
-
         /// <summary>
         ///     Buffer to store incoming data in.
         /// </summary>
@@ -32,24 +30,36 @@ namespace Hazel.Udp
         Dictionary<EndPoint, UdpServerConnection> connections = new Dictionary<EndPoint, UdpServerConnection>();
 
         /// <summary>
-        ///     Creates a new ConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
+        ///     Creates a new UdpConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
         /// </summary>
         /// <param name="IPAddress">The IPAddress to listen on.</param>
         /// <param name="port">The port to listen on.</param>
         /// <param name="mode">The <see cref="IPMode"/> to listen with.</param>
-        public UdpConnectionListener(IPAddress IPAddress, int port, IPMode mode = IPMode.IPv4AndIPv6)
+        [Obsolete("Temporary constructor in beta only, use NetworkEndPoint constructor instead.")]
+        public UdpConnectionListener(IPAddress IPAddress, int port, IPMode mode = IPMode.IPv4)
+            : this (new NetworkEndPoint(IPAddress, port, mode))
         {
-            this.IPAddress = IPAddress;
-            this.Port = port;
 
-             this.bindOn = new IPEndPoint(IPAddress, Port);
+        }
+
+        /// <summary>
+        ///     Creates a new UdpConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
+        /// </summary>
+        /// <param name="endPoint">The endpoint to listen on.</param>
+        public UdpConnectionListener(NetworkEndPoint endPoint)
+        {
+            this.EndPoint = endPoint.EndPoint;
+            this.IPMode = endPoint.IPMode;
 
-            if (mode == IPMode.IPv4)
+            if (endPoint.IPMode == IPMode.IPv4)
                 this.listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             else
             {
+                if (!Socket.OSSupportsIPv6)
+                    throw new HazelException("IPV6 not supported!");
+
                 this.listener = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
-                this.listener.DualMode = true;
+                this.listener.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
             }
         }
 
@@ -59,7 +69,7 @@ namespace Hazel.Udp
             try
             {
                 lock (listener)
-                    listener.Bind(bindOn);
+                    listener.Bind(EndPoint);
             }
             catch (SocketException e)
             {
@@ -74,7 +84,7 @@ namespace Hazel.Udp
         /// </summary>
         void StartListeningForData()
         {
-            EndPoint remoteEP = (EndPoint)bindOn;
+            EndPoint remoteEP = EndPoint;
             
             try
             {
@@ -94,7 +104,7 @@ namespace Hazel.Udp
         void ReadCallback(IAsyncResult result)
         {
             int bytesReceived;
-            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
+            EndPoint remoteEndPoint = new IPEndPoint(IPMode == IPMode.IPv4 ? IPAddress.Any : IPAddress.IPv6Any, 0);
 
             //End the receive operation
             try
@@ -142,7 +152,7 @@ namespace Hazel.Udp
                     if (buffer[0] != (byte)SendOptionInternal.Hello || buffer.Length != 3)
                         return;
 
-                    connection = new UdpServerConnection(this, remoteEndPoint);
+                    connection = new UdpServerConnection(this, remoteEndPoint, IPMode);
                     connections.Add(remoteEndPoint, connection);
 
                     //Then ping back an ack to make sure they're happy (unless we rejected them...)
@@ -200,7 +210,7 @@ namespace Hazel.Udp
             if (disposing)
             {
                 lock (listener)
-                    listener.Dispose();
+                    listener.Close();
             }
 
             base.Dispose(disposing);
index eca3c3e2c2ca842cd0e7fc217a1f8ca6a4232f7f..4d3419aaaa7da8e1b771b51f7c55c43bcab4c086 100644 (file)
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
+
 
 namespace Hazel.Udp
 {
@@ -32,12 +32,14 @@ namespace Hazel.Udp
         /// </summary>
         /// <param name="listener">The listener that created this connection.</param>
         /// <param name="endPoint">The endpoint that we are connected to.</param>
-        internal UdpServerConnection(UdpConnectionListener listener, EndPoint endPoint)
+        /// <param name="IPMode">The IPMode we are connected using.</param>
+        internal UdpServerConnection(UdpConnectionListener listener, EndPoint endPoint, IPMode IPMode)
             : base()
         {
             this.Listener = listener;
             this.RemoteEndPoint = endPoint;
             this.EndPoint = new NetworkEndPoint(endPoint);
+            this.IPMode = IPMode;
 
             State = ConnectionState.Connected;
         }