Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -115,7 +115,8 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public void StartListening(object data)
{
serverChannel.StartListening(data);
if (serverChannel != null)
serverChannel.StartListening(data);
}
public object ChannelData
@@ -128,7 +129,8 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public void StopListening(object data)
{
serverChannel.StopListening(data);
if (serverChannel != null)
serverChannel.StopListening(data);
}
public string[] GetUrlsForUri(string objectURI)

View File

@@ -26,10 +26,9 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
@@ -89,6 +88,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public const uint OPEN_EXISTING = 3;
public const uint OPEN_ALWAYS = 4;
public const uint TRUNCATE_EXISTING = 5;
public const uint FILE_FLAG_OVERLAPPED = 0x40000000;
// Access flags
public const uint GENERIC_READ = 0x80000000;
@@ -103,6 +103,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
public const int ERROR_PIPE_NOT_CONNECTED = 233;
public const int ERROR_PIPE_CONNECTED = 535;
public const int ERROR_PIPE_LISTENING = 536;
public const int ERROR_IO_PENDING = 997;
public const int INVALID_HANDLE_VALUE = -1;
@@ -121,7 +122,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ConnectNamedPipe(
IntPtr hPipe,
IntPtr lpOverlapped
[In] ref NativeOverlapped lpOverlapped
);
[DllImport("kernel32.dll", SetLastError = true)]

View File

@@ -27,8 +27,8 @@
//
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
@@ -74,7 +74,7 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
{
IntPtr hPipe = NamedPipeHelper.CreateNamedPipe(
pipeName,
NamedPipeHelper.PIPE_ACCESS_DUPLEX,
NamedPipeHelper.PIPE_ACCESS_DUPLEX | NamedPipeHelper.FILE_FLAG_OVERLAPPED,
NamedPipeHelper.PIPE_TYPE_MESSAGE
| NamedPipeHelper.PIPE_READMODE_MESSAGE
| NamedPipeHelper.PIPE_WAIT,
@@ -85,27 +85,43 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32
IntPtr.Zero
);
if (hPipe.ToInt32() == NamedPipeHelper.INVALID_HANDLE_VALUE)
{
throw new NamedPipeException();
if (hPipe.ToInt32 () == NamedPipeHelper.INVALID_HANDLE_VALUE) {
throw new NamedPipeException (Marshal.GetLastWin32Error ());
}
bool canConnect = NamedPipeHelper.ConnectNamedPipe(hPipe, IntPtr.Zero);
int lastError = Marshal.GetLastWin32Error();
if (!canConnect && lastError == NamedPipeHelper.ERROR_PIPE_CONNECTED)
canConnect = true;
// Connect the named pipe with overlapped structure
// in order to make it altertable. This way we will
// wake up when someone aborts a thread waiting
// for this pipe.
NativeOverlapped overlapped = new NativeOverlapped ();
bool canConnect = NamedPipeHelper.ConnectNamedPipe (hPipe, ref overlapped);
if (canConnect)
{
return new NamedPipeSocket(hPipe);
}
else
{
NamedPipeHelper.CloseHandle(hPipe);
throw new NamedPipeException(lastError);
}
int lastError = Marshal.GetLastWin32Error ();
if (!canConnect) {
if (lastError == NamedPipeHelper.ERROR_IO_PENDING) {
uint bytesTransferred = 0;
if (!GetOverlappedResultEx (hPipe, ref overlapped, out bytesTransferred, Timeout.Infinite, true)) {
lastError = Marshal.GetLastWin32Error ();
NamedPipeHelper.CloseHandle (hPipe);
throw new NamedPipeException (lastError);
}
canConnect = true;
} else if (lastError == NamedPipeHelper.ERROR_PIPE_CONNECTED)
canConnect = true;
}
if (!canConnect) {
NamedPipeHelper.CloseHandle (hPipe);
throw new NamedPipeException (lastError);
}
return new NamedPipeSocket (hPipe);
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetOverlappedResultEx (IntPtr hFile, [In] ref System.Threading.NativeOverlapped lpOverlapped,
out uint lpNumberOfBytesTransferred, int dwMilliseconds, bool bAltertable);
}
}

View File

@@ -71,7 +71,12 @@ namespace System.Runtime.Remoting.Channels.Tcp
else {
IPHostEntry he = Dns.Resolve (Dns.GetHostName());
if (he.AddressList.Length == 0) throw new RemotingException ("IP address could not be determined for this host");
host = he.AddressList [0].ToString ();
AddressFamily addressFamily = (Socket.OSSupportsIPv4) ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
IPAddress addr = GetMachineAddress (he, addressFamily);
if (addr != null)
host = addr.ToString ();
else
host = he.AddressList [0].ToString ();
}
}
else
@@ -259,6 +264,22 @@ namespace System.Runtime.Remoting.Channels.Tcp
server_thread.Join ();
server_thread = null;
}
private static IPAddress GetMachineAddress (IPHostEntry host, AddressFamily addressFamily)
{
IPAddress result = null;
if (host != null) {
IPAddress[] addressList = host.AddressList;
for (int i = 0; i < addressList.Length; i++) {
if (addressList[i].AddressFamily == addressFamily) {
result = addressList[i];
break;
}
}
}
return result;
}
}
class ClientConnection

View File

@@ -1,3 +1,4 @@
../../test-helpers/NunitHelpers.cs
System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs
ServerObject.cs
ContextsTest.cs

View File

@@ -371,7 +371,7 @@ namespace MonoTests.Remoting
try {
testerSurrogate.ProcessContextData ();
Assert.IsTrue (false, "Exception not thrown");
Assert.Fail ("Exception not thrown");
} catch (Exception ex) {
if (ex.InnerException != null)
ex = ex.InnerException;

View File

@@ -169,16 +169,12 @@ namespace MonoTests.Remoting.Http
public void Main ()
{
channel = new HttpChannel (0);
try {
ChannelServices.RegisterChannel (channel);
MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
typeof (IFactorial),
"http://localhost:60000/MyEndPoint");
IFactorial cal = (IFactorial) obj;
Assert.AreEqual (cal.CalculateFactorial (4), 24);
} finally {
ChannelServices.UnregisterChannel (channel);
}
Assert.AreEqual (cal.CalculateFactorial (4), 24);
}
[TestFixtureSetUp]

View File

@@ -15,6 +15,7 @@ using NUnit.Framework;
namespace MonoTests.Remoting
{
/*
//[TestFixture]
public class HttpSyncCallTest : SyncCallTest
{
@@ -59,7 +60,7 @@ namespace MonoTests.Remoting
return new HttpChannelManager ();
}
}
*/
[Serializable]
public class HttpChannelManager : ChannelManager
{

View File

@@ -78,7 +78,7 @@ namespace MonoTests.Remoting
IpcServerChannel chan = new IpcServerChannel (channelName, portName);
string[] uris = chan.GetUrlsForUri ("server.rem");
Assert.IsNotNull (uris);
Assert.Greater (uris.Length, 0);
AssertHelper.Greater (uris.Length, 0);
bool found = false;
foreach (string s in uris) {
@@ -101,7 +101,7 @@ namespace MonoTests.Remoting
IpcChannel chan = new IpcChannel (props, null, null);
string[] uris = chan.GetUrlsForUri ("server.rem");
Assert.IsNotNull (uris);
Assert.Greater (uris.Length, 0);
AssertHelper.Greater (uris.Length, 0);
bool found = false;
foreach (string s in uris) {

View File

@@ -193,7 +193,7 @@ namespace MonoTests.Remoting
// The main test class
[TestFixture]
public class RemotingServicesTest : Assertion
public class RemotingServicesTest
{
private static int MarshalObjectId = 0;
@@ -233,13 +233,13 @@ namespace MonoTests.Remoting
MarshalObject objMarshal = NewMarshalObject ();
ObjRef objRef = RemotingServices.Marshal (objMarshal);
Assert ("#A01", objRef.URI != null);
Assert.IsNotNull (objRef.URI, "#A01");
MarshalObject objRem = (MarshalObject) RemotingServices.Unmarshal (objRef);
AssertEquals ("#A02", objMarshal.Id, objRem.Id);
Assert.AreEqual (objMarshal.Id, objRem.Id, "#A02");
objRem.Id = 2;
AssertEquals ("#A03", objMarshal.Id, objRem.Id);
Assert.AreEqual (objMarshal.Id, objRem.Id, "#A03");
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
@@ -248,7 +248,7 @@ namespace MonoTests.Remoting
objRef = RemotingServices.Marshal (objMarshal, objMarshal.Uri);
Assert ("#A04", objRef.URI.EndsWith (objMarshal.Uri));
Assert.IsTrue (objRef.URI.EndsWith (objMarshal.Uri), "#A04");
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
}
@@ -261,7 +261,7 @@ namespace MonoTests.Remoting
ObjRef objRef = RemotingServices.Marshal (derivedObjMarshal, derivedObjMarshal.Uri, typeof (MarshalObject));
// Check that the type of the marshaled object is MarshalObject
Assert ("#A05", objRef.TypeInfo.TypeName.StartsWith ((typeof (MarshalObject)).ToString ()));
Assert.IsTrue (objRef.TypeInfo.TypeName.StartsWith ((typeof (MarshalObject)).ToString ()), "#A05");
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(derivedObjMarshal);
@@ -273,11 +273,11 @@ namespace MonoTests.Remoting
{
MarshalObject objMarshal = NewMarshalObject ();
Assert ("#A06", RemotingServices.GetObjectUri (objMarshal) == null);
Assert.IsNull (RemotingServices.GetObjectUri (objMarshal), "#A06");
RemotingServices.Marshal (objMarshal);
Assert ("#A07", RemotingServices.GetObjectUri (objMarshal) != null);
Assert.IsNotNull (RemotingServices.GetObjectUri (objMarshal), "#A07");
// TODO: uncomment when RemotingServices.Disconnect is implemented
//RemotingServices.Disconnect(objMarshal);
}
@@ -297,7 +297,7 @@ namespace MonoTests.Remoting
try {
RemotingServices.Marshal (objMarshal, objMarshal.Uri);
MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);
Assert ("#A08", RemotingServices.IsTransparentProxy (objRem));
Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A08");
} finally {
ChannelServices.UnregisterChannel (chn);
RemotingServices.Disconnect (objMarshal);
@@ -324,7 +324,7 @@ namespace MonoTests.Remoting
// a real object
try {
RemotingServices.Marshal (objRem, objMarshal.Uri);
Fail ("#1");
Assert.Fail ("#1");
} catch (RemotingException e) {
}
} finally {
@@ -355,15 +355,15 @@ namespace MonoTests.Remoting
objRem.Method1 ();
// Tests RemotingServices.GetMethodBaseFromMethodMessage()
AssertEquals ("#A09", "Method1", proxy.MthBase.Name);
Assert ("#A09.1", !proxy.IsMethodOverloaded);
Assert.AreEqual ("Method1", proxy.MthBase.Name, "#A09");
Assert.IsFalse (proxy.IsMethodOverloaded, "#A09.1");
objRem.Method2 ();
Assert ("#A09.2", proxy.IsMethodOverloaded);
Assert.IsTrue (proxy.IsMethodOverloaded, "#A09.2");
// Tests RemotingServices.ExecuteMessage();
// If ExecuteMessage does it job well, Method1 should be called 2 times
AssertEquals ("#A10", 2, MarshalObject.Called);
Assert.AreEqual (2, MarshalObject.Called, "#A10");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -380,14 +380,14 @@ namespace MonoTests.Remoting
MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1238/MarshalObject.rem");
Assert ("#A10.1", RemotingServices.IsTransparentProxy (objRem));
Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A10.1");
objRem.Method1 ();
Thread.Sleep (20);
Assert ("#A10.2", !MarshalObject.IsMethodOneWay);
Assert.IsFalse (MarshalObject.IsMethodOneWay, "#A10.2");
objRem.Method3 ();
Thread.Sleep (20);
Assert ("#A10.3", MarshalObject.IsMethodOneWay);
Assert.IsTrue (MarshalObject.IsMethodOneWay, "#A10.3");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -409,7 +409,7 @@ namespace MonoTests.Remoting
ObjRef objRefRem = RemotingServices.GetObjRefForProxy ((MarshalByRefObject) objRem);
Assert ("#A11", objRefRem != null);
Assert.IsNotNull (objRefRem, "#A11");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -429,8 +429,8 @@ namespace MonoTests.Remoting
RealProxy rp = RemotingServices.GetRealProxy (objRem);
Assert ("#A12", rp != null);
AssertEquals ("#A13", "MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType ().ToString ());
Assert.IsNotNull (rp, "#A12");
Assert.AreEqual ("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType ().ToString (), "#A13");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -448,7 +448,7 @@ namespace MonoTests.Remoting
RemotingServices.Marshal (objRem);
objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1242/" + objRem.Uri);
Assert ("#A14", objRem != null);
Assert.IsNotNull (objRem, "#A14");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -468,7 +468,7 @@ namespace MonoTests.Remoting
RemotingServices.Marshal (objRem);
Type typeRem = RemotingServices.GetServerTypeForUri (RemotingServices.GetObjectUri (objRem));
AssertEquals ("#A15", type, typeRem);
Assert.AreEqual (type, typeRem, "#A15");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -487,12 +487,12 @@ namespace MonoTests.Remoting
MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1245/MarshalObject2.rem");
Assert ("#A16", RemotingServices.IsObjectOutOfAppDomain (objRem));
Assert ("#A17", RemotingServices.IsObjectOutOfContext (objRem));
Assert.IsTrue (RemotingServices.IsObjectOutOfAppDomain (objRem), "#A16");
Assert.IsTrue (RemotingServices.IsObjectOutOfContext (objRem), "#A17");
MarshalObject objMarshal = new MarshalObject ();
Assert ("#A18", !RemotingServices.IsObjectOutOfAppDomain (objMarshal));
Assert ("#A19", !RemotingServices.IsObjectOutOfContext (objMarshal));
Assert.IsFalse (RemotingServices.IsObjectOutOfAppDomain (objMarshal), "#A18");
Assert.IsFalse (RemotingServices.IsObjectOutOfContext (objMarshal), "#A19");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -510,16 +510,16 @@ namespace MonoTests.Remoting
MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/app/obj3.rem");
MarshalObject objRem2 = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/obj3.rem");
Assert ("#AN1", RemotingServices.IsTransparentProxy (objRem));
Assert ("#AN2", RemotingServices.IsTransparentProxy (objRem2));
Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#AN1");
Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem2), "#AN2");
AssertNotNull ("#AN3", RemotingServices.GetServerTypeForUri ("obj3.rem"));
AssertNotNull ("#AN4", RemotingServices.GetServerTypeForUri ("/app/obj3.rem"));
AssertNull ("#AN5", RemotingServices.GetServerTypeForUri ("//app/obj3.rem"));
AssertNull ("#AN6", RemotingServices.GetServerTypeForUri ("app/obj3.rem"));
AssertNull ("#AN7", RemotingServices.GetServerTypeForUri ("/whatever/obj3.rem"));
AssertNotNull ("#AN8", RemotingServices.GetServerTypeForUri ("/obj3.rem"));
AssertNull ("#AN9", RemotingServices.GetServerTypeForUri ("//obj3.rem"));
Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("obj3.rem"), "#AN3");
Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/app/obj3.rem"), "#AN4");
Assert.IsNull (RemotingServices.GetServerTypeForUri ("//app/obj3.rem"), "#AN5");
Assert.IsNull (RemotingServices.GetServerTypeForUri ("app/obj3.rem"), "#AN6");
Assert.IsNull (RemotingServices.GetServerTypeForUri ("/whatever/obj3.rem"), "#AN7");
Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/obj3.rem"), "#AN8");
Assert.IsNull (RemotingServices.GetServerTypeForUri ("//obj3.rem"), "#AN9");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -534,7 +534,7 @@ namespace MonoTests.Remoting
RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "getobjectwithchanneldata.rem", WellKnownObjectMode.Singleton);
string channelData = "test";
AssertNotNull ("#01", Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1247/getobjectwithchanneldata.rem", channelData));
Assert.IsNotNull (Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1247/getobjectwithchanneldata.rem", channelData), "#01");
} finally {
ChannelServices.UnregisterChannel (chn);
}
@@ -548,28 +548,28 @@ namespace MonoTests.Remoting
RemotingConfiguration.Configure (null);
o = RemotingServices.Connect (typeof (MarshalByRefObject), "tcp://localhost:3434/ff1.rem");
Assert ("#m1", o is DD);
Assert ("#m2", o is A);
Assert ("#m3", o is B);
Assert ("#m4", !(o is CC));
Assert.IsInstanceOfType (typeof (DD), o, "#m1");
Assert.IsInstanceOfType (typeof (A), o, "#m2");
Assert.IsInstanceOfType (typeof (B), o, "#m3");
AssertHelper.IsNotInstanceOfType (typeof (CC), !(o is CC), "#m4");
o = RemotingServices.Connect (typeof (A), "tcp://localhost:3434/ff3.rem");
Assert ("#a1", o is DD);
Assert ("#a2", o is A);
Assert ("#a3", o is B);
Assert ("#a4", !(o is CC));
Assert.IsInstanceOfType (typeof (DD), o, "#a1");
Assert.IsInstanceOfType (typeof (A), o, "#a2");
Assert.IsInstanceOfType (typeof (B), o, "#a3");
AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#a4");
o = RemotingServices.Connect (typeof (DD), "tcp://localhost:3434/ff4.rem");
Assert ("#d1", o is DD);
Assert ("#d2", o is A);
Assert ("#d3", o is B);
Assert ("#d4", !(o is CC));
Assert.IsInstanceOfType (typeof (DD), o, "#d1");
Assert.IsInstanceOfType (typeof (A), o, "#d2");
Assert.IsInstanceOfType (typeof (B), o, "#d3");
AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#d4");
o = RemotingServices.Connect (typeof (CC), "tcp://localhost:3434/ff5.rem");
Assert ("#c1", !(o is DD));
Assert ("#c2", o is A);
Assert ("#c3", o is B);
Assert ("#c4", o is CC);
AssertHelper.IsNotInstanceOfType (typeof (DD), o, "#c1");
Assert.IsInstanceOfType (typeof (A), o, "#c2");
Assert.IsInstanceOfType (typeof (B), o, "#c3");
Assert.IsInstanceOfType (typeof (CC), o, "#c4");
}
// Don't add any tests that must create channels
// after ConnectProxyCast (), because this test calls