using System.Threading;
using System.Reflection;
using System.Text.RegularExpressions;
+using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
public const int BogusPort = 23483;
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectIPAddressAny ()
{
IPEndPoint ep = new IPEndPoint (IPAddress.Any, NetworkHelpers.FindFreePort ());
[Test]
[Category ("InetAccess")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BogusEndConnect ()
{
IPAddress ipOne = IPAddress.Parse (BogusAddress);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void AcceptBlockingStatus()
{
bool block;
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectFailAsync ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOptionBoolean ()
{
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
}
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void TestSelect1 ()
{
Socket srv = CreateServer (NetworkHelpers.FindFreePort ());
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void Disposed19 ()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void Disposed20 ()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void Disposed21 ()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void Disposed22 ()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void GetHashCodeTest ()
{
Socket server = new Socket (AddressFamily.InterNetwork,
}
[Test]
+ [Category ("RequiresBSDSockets")] // This verifies particular error codes, which we don't care about when nothing's working anyway.
public void SocketErrorTest ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void IsBoundTcp ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void IsBoundUdp ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
-
+
Assert.AreEqual (false, sock.NoDelay, "NoDelayDefaultTcp");
-
+
sock.Close ();
}
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof(InvalidOperationException))]
+#endif
public void BeginAcceptNotListening ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAccept ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAcceptData ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAcceptSocketUdp ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAcceptSocketBound ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAcceptSocket ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginAcceptSocketAccClosed ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectAddressPort ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectAddressPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectMultiple2 ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectMultipleListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectHostPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[Test]
[Category ("NotDotNet")] // "Needs XP or later"
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginDisconnect ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BindTwice ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Close ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectAddressPort ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectAddressPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultiple2 ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultipleListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectHostPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof(ObjectDisposedException))]
+#endif
public void ConnectHostPortClosed ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[Test]
[Category ("NotDotNet")] // "Needs XP or later"
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Disconnect ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveGeneric ()
{
int i;
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SendGeneric ()
{
int i;
listensock.Close ();
}
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (AggregateException))] // Something catches the PlatformNotSupportedException and re-throws an AggregateException
+#endif
+ public void ConcurrentExceedSocketLimit ()
+ {
+ var tasks = new Task[4];
+ for (int i = 0; i < 4; i++) {
+ tasks[i] = Task.Factory.StartNew (() => SendGenericExceedBuffer ());
+ }
+ Task.WaitAll (tasks);
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void SendGenericExceedBuffer ()
+ {
+ // Create a buffer larger than the default max.
+ const int BUFFER_SIZE = 65 * 1024;
+ int i;
+
+ IPEndPoint endpoint = new IPEndPoint(IPAddress.Loopback, NetworkHelpers.FindFreePort ());
+
+ Socket listensock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ listensock.Bind (endpoint);
+ listensock.Listen (1);
+
+ Socket sendsock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ sendsock.Connect (endpoint);
+
+ Socket clientsock = listensock.Accept ();
+
+ byte[] sendbuf = new byte[BUFFER_SIZE];
+
+ for (i = 0; i < BUFFER_SIZE; i++) {
+ sendbuf[i] = (byte)i;
+ }
+
+ Task sendTask = Task.Factory.StartNew(() => {
+ int sent = sendsock.Send (sendbuf);
+
+ Assert.AreEqual (BUFFER_SIZE, sent, "#1");
+ });
+
+ byte[] recvbuf = new byte[BUFFER_SIZE];
+
+ Task recvTask = Task.Factory.StartNew(() => {
+ int totalReceived = 0;
+ byte[] buffer = new byte[256];
+ while (totalReceived < sendbuf.Length) {
+ int recvd = clientsock.Receive (buffer, 0, buffer.Length, SocketFlags.None);
+ Array.Copy (buffer, 0, recvbuf, totalReceived, recvd);
+ totalReceived += recvd;
+ }
+
+ Assert.AreEqual (BUFFER_SIZE, totalReceived, "#2");
+ });
+
+ Assert.IsTrue (Task.WaitAll (new []{sendTask, recvTask}, 20 * 1000), "#2a");
+
+ for (i = 0; i < BUFFER_SIZE; i++) {
+ Assert.AreEqual (recvbuf[i], sendbuf[i],
+ "#3/" + i.ToString());
+ }
+
+ sendsock.Close ();
+ clientsock.Close ();
+ listensock.Close ();
+ }
+
[Test]
public void ListenNotBound ()
{
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CloseWhileReceiving ()
{
CWRSocket = new Socket (AddressFamily.InterNetwork,
}
[Test] // ReceiveFrom (Byte [], ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom1_Buffer_Null ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom1_Socket_Closed ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom2_Buffer_Null ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom2_Socket_Closed ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], Int32, SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom3_Buffer_Null ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], Int32, SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom3_Size_OutOfRange ()
{
Socket s;
}
[Test] // ReceiveFrom (Byte [], Int32, SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom3_Socket_Closed ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], Int32, Int32, SocketFlags, EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom4_Buffer_Null ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test] // ReceiveFrom (Byte [], Int32, Int32, SocketFlags, EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom4_Offset_OutOfRange ()
{
Socket s;
}
[Test] // ReceiveFrom (Byte [], Int32, Int32, SocketFlags, EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom4_Size_OutOfRange ()
{
Socket s;
}
[Test] // ReceiveFrom (Byte [], Int32, Int32, SocketFlags, ref EndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveFrom4_Socket_Closed ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ReceiveRemoteClosed ()
{
var port = NetworkHelpers.FindFreePort ();
//
// Test case for bug #471580
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void UdpDoubleBind ()
{
using (Socket s = new Socket (AddressFamily.InterNetwork,
// Test case for bug #31557
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void TcpDoubleBind ()
{
using (Socket s = new Socket (AddressFamily.InterNetwork,
[Test]
[Category ("NotOnMac")]
- public void ConnectedProperty ()
- {
+#if FULL_AOT_DESKTOP
+ [Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=52157")]
+#endif
+ public void ConnectedProperty ()
+ {
TcpListener listener = new TcpListener (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
listener.Start();
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_AddMembershipIPv4_IPv6MulticastOption ()
{
IPAddress mcast_addr = IPAddress.Parse ("239.255.255.250");
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_AddMembershipIPv4_MulticastOption ()
{
IPAddress mcast_addr = IPAddress.Parse ("239.255.255.250");
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_AddMembershipIPv6_IPv6MulticastOption ()
{
if (!Socket.OSSupportsIPv6)
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_AddMembershipIPv6_MulticastOption ()
{
if (!Socket.OSSupportsIPv6)
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_DropMembershipIPv4_IPv6MulticastOption ()
{
IPAddress mcast_addr = IPAddress.Parse ("239.255.255.250");
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_DropMembershipIPv4_MulticastOption ()
{
IPAddress mcast_addr = IPAddress.Parse ("239.255.255.250");
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_DropMembershipIPv6_IPv6MulticastOption ()
{
if (!Socket.OSSupportsIPv6)
}
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SetSocketOption3_DropMembershipIPv6_MulticastOption ()
{
if (!Socket.OSSupportsIPv6)
}
[Test]
+ [Category ("RequiresBSDSockets")] // on watchOS device this happens: System.Net.Sockets.SocketException : The requested address is not valid in this context. This situation is too complex to detect and throw a PlatformNotSupportedException, so just ignore it.
public void SetSocketOption_MulticastInterfaceIndex_Any ()
{
IPAddress ip = IPAddress.Parse ("239.255.255.250");
}
[Test]
+ [Category ("RequiresBSDSockets")] // on watchOS device this happens: System.Net.Sockets.SocketException : The requested address is not valid in this context. This situation is too complex to detect and throw a PlatformNotSupportedException, so just ignore it.
public void SetSocketOption_MulticastInterfaceIndex_Loopback ()
{
IPAddress ip = IPAddress.Parse ("239.255.255.250");
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Shutdown_NoConnect ()
{
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void SendAsyncFile ()
{
Socket serverSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectToIPV4EndPointUsingDualModelSocket () {
- using (var server = new Socket (SocketType.Stream, ProtocolType.Tcp))
- using (var client = new Socket (SocketType.Stream, ProtocolType.Tcp)) {
+ /*
+ * IPv6 DualMode sockets are defaults in Mono. Explicitly specify that
+ * anyways in this test to make it more interoparable with .NET where
+ * IPv6 and DualMode needs to be specified.
+ */
+ using (var server = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) {
+
var host = new IPEndPoint (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
-
+
+ server.DualMode = true;
server.Bind (host);
- server.Listen (0);
+ /*
+ * Nothing to Accept the connect - we need a backlog to make sure we don't get
+ Connection refused.
+ */
+ server.Listen (3);
var ep = server.LocalEndPoint as IPEndPoint;
-
+ var client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
client.Connect (ep);
- client.Disconnect (true);
-
+ client.Disconnect (false);
+ client.Close ();
+
+ client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
client.Connect (IPAddress.Loopback, ep.Port);
- client.Disconnect (true);
-
- client.Connect (new [] {IPAddress.Loopback}, ep.Port);
- client.Disconnect (true);
+ client.Disconnect (false);
+ client.Close ();
+
+ client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
+ client.Connect (new [] { IPAddress.Loopback }, ep.Port);
+ client.Disconnect (false);
+ client.Close ();
}
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectToIPV4EndPointUsingDualModelSocket () {
- using (var server = new Socket (SocketType.Stream, ProtocolType.Tcp))
- using (var client = new Socket (SocketType.Stream, ProtocolType.Tcp)) {
+ /*
+ * IPv6 DualMode sockets are defaults in Mono. Explicitly specify that
+ * anyways in this test to make it more interoparable with .NET where
+ * IPv6 and DualMode needs to be specified.
+ */
+ using (var server = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
+ {
var host = new IPEndPoint (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
-
+
+ server.DualMode = true;
server.Bind (host);
- server.Listen (0);
+ server.Listen (10);
var ep = server.LocalEndPoint as IPEndPoint;
-
+
BCCalledBack.Reset ();
+ var client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
var ar1 = client.BeginConnect (ep, BCCallback, client);
Assert.IsTrue (BCCalledBack.WaitOne (10000), "#1");
- client.Disconnect (true);
-
+ client.Disconnect (false);
+ client.Close ();
+
BCCalledBack.Reset ();
+ client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
var ar2 = client.BeginConnect (IPAddress.Loopback, ep.Port, BCCallback, client);
Assert.IsTrue (BCCalledBack.WaitOne (10000), "#2");
- client.Disconnect (true);
-
+ client.Disconnect (false);
+ client.Close ();
+
BCCalledBack.Reset ();
+ client = new Socket (AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
+ client.DualMode = true;
var ar3 = client.BeginConnect (new [] {IPAddress.Loopback}, ep.Port, BCCallback, client);
Assert.IsTrue (BCCalledBack.WaitOne (10000), "#2");
- client.Disconnect (true);
+ client.Disconnect (false);
+ client.Close();
}
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void UdpMulticasTimeToLive ()
{
/* see https://bugzilla.xamarin.com/show_bug.cgi?id=36941 */
socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 19);
}
}
+
+ [Test] // Covers 41616
+ public void ConnectAsyncUnhandledEx ()
+ {
+ var mre = new ManualResetEvent (false);
+
+ var endPoint = new IPEndPoint(0,0);
+ var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified);
+
+ var socketArgs = new SocketAsyncEventArgs();
+ socketArgs.RemoteEndPoint = endPoint;
+ socketArgs.Completed += (sender, e) => mre.Set ();
+
+ socket.ConnectAsync (socketArgs);
+
+ Assert.IsTrue (mre.WaitOne (1000), "ConnectedAsync timeout");
+ }
}
}