namespace MonoTests.System.Net.Sockets
{
[TestFixture]
- [Category ("RequiresBSDSockets")]
public class SocketTest
{
- // note: also used in SocketCas tests
public const string BogusAddress = "192.168.244.244";
- 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")]
+ [Category ("NotWorking")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BogusEndConnect ()
{
IPAddress ipOne = IPAddress.Parse (BogusAddress);
- IPEndPoint ipEP = new IPEndPoint (ipOne, BogusPort);
+ IPEndPoint ipEP = new IPEndPoint (ipOne, NetworkHelpers.FindFreePort ());
Socket sock = new Socket (ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult ar = sock.BeginConnect (ipEP, null, null);
}
[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,
SocketType.Stream,
ProtocolType.Tcp);
- IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
- BogusPort);
+ IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
SocketError_event.Reset ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void IsBoundTcp ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
- IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
- BogusPort);
+ IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
Assert.AreEqual (false, sock.IsBound, "IsBoundTcp #1");
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void IsBoundUdp ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
- IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
- BogusPort);
+ IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
Assert.AreEqual (false, sock.IsBound, "IsBoundUdp #1");
}
[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]
public void BeginConnectAddressPortNull ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPAddress ip = null;
try {
- sock.BeginConnect (ip, 1244, BCCallback,
+ sock.BeginConnect (ip, port, BCCallback,
sock);
Assert.Fail ("BeginConnectAddressPortNull #1");
} catch (ArgumentNullException) {
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectAddressPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[ExpectedException (typeof(ObjectDisposedException))]
public void BeginConnectAddressPortClosed ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Close ();
- sock.BeginConnect (ip, 1244, BCCallback, sock);
+ sock.BeginConnect (ip, port, BCCallback, sock);
}
[Test]
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectMultiple2 ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[Test]
public void BeginConnectMultipleNull ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPAddress[] ips = null;
try {
- sock.BeginConnect (ips, 1246, BCCallback,
+ sock.BeginConnect (ips, port, BCCallback,
sock);
Assert.Fail ("BeginConnectMultipleNull #1");
} catch (ArgumentNullException) {
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectMultipleListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[ExpectedException (typeof(ObjectDisposedException))]
public void BeginConnectMultipleClosed ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Close ();
- sock.BeginConnect (ips, 1247, BCCallback, sock);
+ sock.BeginConnect (ips, port, BCCallback, sock);
}
[Test]
}
[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]
public void ConnectAddressPortNull ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPAddress ip = null;
try {
- sock.Connect (ip, 1249);
+ sock.Connect (ip, port);
Assert.Fail ("ConnectAddressPortNull #1");
} catch (ArgumentNullException) {
} finally {
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectAddressPortListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[ExpectedException (typeof(ObjectDisposedException))]
public void ConnectAddressPortClosed ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Close ();
- sock.Connect (ip, 1250);
+ sock.Connect (ip, port);
}
[Test]
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultiple2 ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[Test]
public void ConnectMultipleNull ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPAddress[] ips = null;
try {
- sock.Connect (ips, 1251);
+ sock.Connect (ips, port);
Assert.Fail ("ConnectMultipleNull #1");
} catch (ArgumentNullException) {
} finally {
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectMultipleListen ()
{
Socket sock = new Socket (AddressFamily.InterNetwork,
[ExpectedException (typeof(ObjectDisposedException))]
public void ConnectMultipleClosed ()
{
+ var port = NetworkHelpers.FindFreePort ();
Socket sock = new Socket (AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Close ();
- sock.Connect (ips, 1252);
+ sock.Connect (ips, port);
}
[Test]
}
[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;
}
[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];
}
[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 = 256 * 256 * 65;
+ const int BUFFER_SIZE = 65 * 1024;
int i;
IPEndPoint endpoint = new IPEndPoint(IPAddress.Loopback, NetworkHelpers.FindFreePort ());
byte[] buffer = new byte[256];
while (totalReceived < sendbuf.Length) {
int recvd = clientsock.Receive (buffer, 0, buffer.Length, SocketFlags.None);
- buffer.CopyTo (recvbuf, totalReceived);
+ Array.Copy (buffer, 0, recvbuf, totalReceived, recvd);
totalReceived += recvd;
}
Assert.AreEqual (BUFFER_SIZE, totalReceived, "#2");
});
- Task.WaitAll (new []{sendTask, recvTask});
+ Assert.IsTrue (Task.WaitAll (new []{sendTask, recvTask}, 20 * 1000), "#2a");
for (i = 0; i < BUFFER_SIZE; i++) {
Assert.AreEqual (recvbuf[i], sendbuf[i],
}
[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 case for https://bugzilla.novell.com/show_bug.cgi?id=443346
+ // See also https://bugzilla.xamarin.com/show_bug.cgi?id=52157
[Test]
- [Category ("NotOnMac")]
- public void ConnectedProperty ()
- {
- TcpListener listener = new TcpListener (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
+ public void ConnectedProperty ()
+ {
+ var port = NetworkHelpers.FindFreePort ();
+ var listener = new TcpListener (IPAddress.Loopback, port);
listener.Start();
- Socket client = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- client.Connect (IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port);
- Socket server = listener.AcceptSocket ();
+ var client = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ client.Connect (IPAddress.Loopback, port);
+ var server = listener.AcceptSocket ();
- try {
- server.EndSend(server.BeginSend (new byte[10], 0, 10, SocketFlags.None, null, null));
+ const int blobSize = 2048;
+
+ // Small send/recv buffers so that our send operation will fill them
+ server.ReceiveBufferSize = server.SendBufferSize = 256;
+ client.ReceiveBufferSize = client.SendBufferSize = 256;
+
+ // Setting this linger state causes shutdown to be a hard close (RST if send data is pending)
+ server.LingerState = client.LingerState = new LingerOption (true, 0);
+
+ // KeepAlive being set introduces another opportunity for a RST according to some documentation
+ server.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
+ client.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
+
+ try
+ {
+ // Fill the send buffer
+ client.Send (new byte[blobSize]);
+ // Now shut down the socket. Because of the linger state this will hard close and send RST.
+ client.Shutdown (SocketShutdown.Both);
client.Close ();
- try {
- server.EndReceive (server.BeginReceive (new byte[10], 0, 10, SocketFlags.None, null, null));
- } catch {
+
+ Assert.IsFalse (client.Connected);
+ Assert.IsTrue (server.Connected);
+
+ var isDead = false;
+
+ try
+ {
+ // On Windows this BeginSend succeeds... it really shouldn't and a sync send fails.
+ // On Linux this fails with a ConnectionReset.
+ var ar = server.BeginSend (new byte[blobSize], 0, blobSize, SocketFlags.None, null, null);
+ // On Mac we get an erroneous WSAESHUTDOWN (10058) here
+ server.EndSend (ar);
+ }
+ catch (SocketException se)
+ {
+ isDead = true;
+
+ if (
+ (se.SocketErrorCode != SocketError.ConnectionReset) &&
+ (se.SocketErrorCode != SocketError.Shutdown)
+ )
+ throw;
+ }
+
+ if (!isDead)
+ {
+ try
+ {
+ // On Windows this second send operation will fail with a ConnectionReset.
+ var ar = server.BeginSend (new byte[blobSize], 0, blobSize, SocketFlags.None, null, null);
+ server.EndSend (ar);
+ }
+ catch (SocketException se)
+ {
+ if (se.SocketErrorCode != SocketError.ConnectionReset)
+ throw;
+ }
}
- Assert.IsTrue (!client.Connected);
- Assert.IsTrue (!server.Connected);
- } finally {
+
+ Assert.IsFalse (client.Connected);
+ Assert.IsFalse (server.Connected);
+ }
+ finally
+ {
listener.Stop ();
client.Close ();
server.Close ();
}
[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)
IPv6MulticastOption option = new IPv6MulticastOption (
IPAddress.Parse ("ff02::1"));
- s.Bind (new IPEndPoint (IPAddress.IPv6Any, 1902));
+ s.Bind (new IPEndPoint (IPAddress.IPv6Any, 0));
s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.AddMembership,
option);
s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DropMembership,
}
[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
+ [Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=43172")]
public void SendAsyncFile ()
{
Socket serverSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
mSent.Set ();
}, clientSocket);
- if (!mSent.WaitOne (1500))
- throw new TimeoutException ();
- if (!mReceived.WaitOne (1500))
- throw new TimeoutException ();
+ Assert.IsTrue (mSent.WaitOne (5000), "#1");
+ Assert.IsTrue (mReceived.WaitOne (5000), "#2");
} finally {
if (File.Exists (temp))
File.Delete (temp);
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectToIPV4EndPointUsingDualModelSocket () {
/*
* IPv6 DualMode sockets are defaults in Mono. Explicitly specify that
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginConnectToIPV4EndPointUsingDualModelSocket () {
/*
* IPv6 DualMode sockets are defaults in Mono. Explicitly specify that
client.DualMode = true;
var ar1 = client.BeginConnect (ep, BCCallback, client);
Assert.IsTrue (BCCalledBack.WaitOne (10000), "#1");
+ Assert.AreEqual(server.AddressFamily, client.RemoteEndPoint.AddressFamily, "#2");
+ Assert.AreEqual(server.AddressFamily, client.LocalEndPoint.AddressFamily, "#3");
client.Disconnect (false);
client.Close ();
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");
+ Assert.IsTrue (BCCalledBack.WaitOne (10000), "#4");
+ Assert.AreEqual(server.AddressFamily, client.RemoteEndPoint.AddressFamily, "#5");
+ Assert.AreEqual(server.AddressFamily, client.LocalEndPoint.AddressFamily, "#6");
client.Disconnect (false);
client.Close ();
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");
+ Assert.IsTrue (BCCalledBack.WaitOne (10000), "#7");
+ Assert.AreEqual(server.AddressFamily, client.RemoteEndPoint.AddressFamily, "#8");
+ Assert.AreEqual(server.AddressFamily, client.LocalEndPoint.AddressFamily, "#9");
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 */
Assert.IsTrue (mre.WaitOne (1000), "ConnectedAsync timeout");
}
+
+ [Test] // Covers https://bugzilla.xamarin.com/show_bug.cgi?id=52549
+ public void SocketMismatchProtocol ()
+ {
+ try {
+ using (Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Tcp));
+ Assert.Fail ("#1");
+ } catch (SocketException e) {
+ // Only work on OSX
+ // Assert.AreEqual(SocketError.ProtocolType, e.SocketErrorCode, "#2");
+ }
+
+ try {
+ using (Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Udp));
+ Assert.Fail ("#3");
+ } catch (SocketException e) {
+ // Only work on OSX
+ // Assert.AreEqual(SocketError.ProtocolType, e.SocketErrorCode, "#4");
+ }
+ }
}
}