From c865cdf96dd110927b29dd8010f1a97b2d0dca88 Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Sat, 29 May 2010 16:37:13 +0000 Subject: [PATCH] In Test: 2010-05-29 Robert Jordan * IpcChannelTest.cs: Add test for bug #609381. In System.Runtime.Remoting.Channels.Ipc.Win32: 2010-05-29 Robert Jordan * IpcChannelHelper.cs (copy): Take into account that the remoting stack is internally using MemoryStreams all over the place. Fixes bug #609381 as a side effect. * IpcChannel.cs (.ctor): Create an IpcClientChannel as well. svn path=/trunk/mcs/; revision=158161 --- .../ChangeLog | 8 ++++ .../IpcChannel.cs | 3 +- .../IpcChannelHelper.cs | 17 +++++--- .../System.Runtime.Remoting/Test/ChangeLog | 4 ++ .../Test/IpcChannelTest.cs | 40 +++++++++++++++++++ 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/ChangeLog b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/ChangeLog index 2bf20ad53b2..02fee79aaef 100644 --- a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/ChangeLog +++ b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/ChangeLog @@ -1,3 +1,11 @@ +2010-05-29 Robert Jordan + + * IpcChannelHelper.cs (copy): Take into account that the remoting + stack is internally using MemoryStreams all over the place. + Fixes bug #609381 as a side effect. + + * IpcChannel.cs (.ctor): Create an IpcClientChannel as well. + 2005-11-05 Robert Jordan * IpcClientChannel.cs, IpcServerChannel.cs: Added missing ctors. diff --git a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannel.cs b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannel.cs index a311ed1180f..5cb721944f4 100644 --- a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannel.cs +++ b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannel.cs @@ -53,7 +53,8 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32 /// Creates a server channel. /// /// The port name. - public IpcChannel(string portName) + public IpcChannel(string portName) + : this() { serverChannel = new IpcServerChannel(portName); } diff --git a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannelHelper.cs b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannelHelper.cs index 55210c6cd88..6b018b035f4 100644 --- a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannelHelper.cs +++ b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/IpcChannelHelper.cs @@ -117,18 +117,25 @@ namespace System.Runtime.Remoting.Channels.Ipc.Win32 /// /// Copies a stream. /// - /// - /// - public static void Copy(Stream from, Stream to) + /// + /// + public static void Copy(Stream input, Stream output) { + MemoryStream ms = input as MemoryStream; + if (ms != null) + { + ms.WriteTo (output); + return; + } + // TODO: find out the optimal chunk size. const int size = 1024 * 1024; byte[] buffer = new byte[size]; int count; - while ((count = from.Read(buffer, 0, size)) > 0) + while ((count = input.Read(buffer, 0, size)) > 0) { - to.Write(buffer, 0, count); + output.Write(buffer, 0, count); } } diff --git a/mcs/class/System.Runtime.Remoting/Test/ChangeLog b/mcs/class/System.Runtime.Remoting/Test/ChangeLog index 8b3c8e5c94a..cd19e34c0c7 100644 --- a/mcs/class/System.Runtime.Remoting/Test/ChangeLog +++ b/mcs/class/System.Runtime.Remoting/Test/ChangeLog @@ -1,3 +1,7 @@ +2010-05-29 Robert Jordan + + * IpcChannelTest.cs: Add test for bug #609381. + 2010-02-28 Robert Jordan * BaseCalls.cs: Enable tests again. See bug #576618. diff --git a/mcs/class/System.Runtime.Remoting/Test/IpcChannelTest.cs b/mcs/class/System.Runtime.Remoting/Test/IpcChannelTest.cs index 338e3b70697..394e8f00c4a 100644 --- a/mcs/class/System.Runtime.Remoting/Test/IpcChannelTest.cs +++ b/mcs/class/System.Runtime.Remoting/Test/IpcChannelTest.cs @@ -27,6 +27,46 @@ namespace MonoTests.Remoting string objectUri; c.CreateMessageSink (null, cd, out objectUri); } + + [Test] + public void Bug609381 () + { + string portName = "ipc" + Guid.NewGuid ().ToString ("N"); + string objUri = "ipcserver609381.rem"; + string url = String.Format ("ipc://{0}/{1}", portName, objUri); + + IpcChannel serverChannel = new IpcChannel (portName); + ChannelServices.RegisterChannel (serverChannel); + + RemotingServices.Marshal (new Server (), objUri); + + Server client = (Server) RemotingServices.Connect (typeof (Server), url); + + int count = 10 * 1024 * 1024; + byte[] sendBuf = new byte[count]; + sendBuf [sendBuf.Length - 1] = 41; + + byte[] recvBuf = client.Send (sendBuf); + + Assert.IsNotNull (recvBuf); + Assert.AreNotSame (sendBuf, recvBuf); + Assert.AreEqual (count, recvBuf.Length); + Assert.AreEqual (42, recvBuf [recvBuf.Length - 1]); + + sendBuf = null; + recvBuf = null; + + ChannelServices.UnregisterChannel (serverChannel); + } + + class Server : MarshalByRefObject + { + public byte[] Send (byte[] payload) + { + payload [payload.Length - 1]++; + return payload; + } + } } } -- 2.25.1