Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@@ -0,0 +1,133 @@
using System;
using System.Collections;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class SocketConnectAsyncTest
{
Socket serverSocket;
Socket clientSocket;
SocketAsyncEventArgs clientSocketAsyncArgs;
ManualResetEvent readyEvent;
ManualResetEvent mainEvent;
Exception error;
[TestFixtureSetUp]
public void SetUp ()
{
readyEvent = new ManualResetEvent (false);
mainEvent = new ManualResetEvent (false);
}
[TestFixtureTearDown]
public void TearDown ()
{
readyEvent.Close ();
mainEvent.Close ();
}
void StartServer()
{
readyEvent.Reset();
mainEvent.Reset();
ThreadPool.QueueUserWorkItem (_ => DoWork ());
readyEvent.WaitOne ();
}
void StopServer()
{
if (serverSocket != null)
serverSocket.Close ();
}
void DoWork ()
{
serverSocket = new Socket (
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
serverSocket.Bind (new IPEndPoint (IPAddress.Loopback, 0));
serverSocket.Listen (1);
var async = new SocketAsyncEventArgs ();
async.Completed += (s,e) => OnAccepted (e);
readyEvent.Set ();
if (!serverSocket.AcceptAsync (async))
OnAccepted (async);
}
void OnAccepted (SocketAsyncEventArgs e)
{
var acceptSocket = e.AcceptSocket;
mainEvent.Set ();
}
[Test]
[Category("Test")]
public void Connect ()
{
StartServer();
EndPoint serverEndpoint = serverSocket.LocalEndPoint;
var m = new ManualResetEvent (false);
var e = new SocketAsyncEventArgs ();
clientSocket = new Socket (
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocketAsyncArgs = new SocketAsyncEventArgs();
clientSocketAsyncArgs.RemoteEndPoint = serverEndpoint;
clientSocketAsyncArgs.Completed += (s,o) => {
if (o.SocketError != SocketError.Success)
error = new SocketException ((int)o.SocketError);
m.Set ();
};
bool res = clientSocket.ConnectAsync(clientSocketAsyncArgs);
if (res) {
if (!m.WaitOne (1500))
throw new TimeoutException ();
}
if (!mainEvent.WaitOne (1500))
throw new TimeoutException ();
if (error != null)
throw error;
m.Reset ();
mainEvent.Reset ();
StopServer();
// Try again to non-listening endpoint, expect error
error = null;
clientSocket = new Socket (
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocketAsyncArgs = new SocketAsyncEventArgs ();
clientSocketAsyncArgs.RemoteEndPoint = serverEndpoint;
clientSocketAsyncArgs.Completed += (s,o) => {
if (o.SocketError != SocketError.Success)
error = new SocketException ((int)o.SocketError);
m.Set ();
};
res = clientSocket.ConnectAsync (clientSocketAsyncArgs);
if (res) {
if (!m.WaitOne (1500))
throw new TimeoutException ();
}
Assert.IsTrue (error != null, "Connect - no error");
SocketException socketException = (SocketException)error;
Assert.IsTrue(socketException.ErrorCode == (int)SocketError.ConnectionRefused);
m.Reset ();
mainEvent.Reset ();
}
}
}

View File

@@ -1 +1 @@
0ae72b4c29ac57ce57fafde17a909f16b88df913
b6ddbf164a5e04ef05fc2d35b59923c2f82abef6

View File

@@ -74,6 +74,13 @@ namespace MonoTests.System.Net.Sockets {
//Assert.AreEqual (32, client.Ttl, "#A:Ttl");
#endif
#if NET_2_0
if (!Socket.OSSupportsIPv6)
#else
if (!Socket.SupportsIPv6)
#endif
Assert.Ignore ("IPv6 not enabled.");
client = new MyUdpClient (AddressFamily.InterNetworkV6);
s = client.Client;
Assert.IsNotNull (s, "#B:Client");
@@ -297,6 +304,13 @@ namespace MonoTests.System.Net.Sockets {
Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
}
#if NET_2_0
if (!Socket.OSSupportsIPv6)
#else
if (!Socket.SupportsIPv6)
#endif
Assert.Ignore ("IPv6 not enabled.");
using (MyUdpClient client = new MyUdpClient (IPEndPoint.MaxPort, AddressFamily.InterNetworkV6))
{
s = client.Client;
@@ -656,6 +670,13 @@ namespace MonoTests.System.Net.Sockets {
[Test] // JoinMulticastGroup (Int32, IPAddress)
public void JoinMulticastGroup2_Socket_Closed ()
{
#if NET_2_0
if (!Socket.OSSupportsIPv6)
#else
if (!Socket.SupportsIPv6)
#endif
Assert.Ignore ("IPv6 not enabled.");
IPAddress mcast_addr = null;
UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234));