Merge pull request #890 from xoofx/master
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Tcp / TcpClientTransportSink.cs
index 8b058db0ddd86b26e957e30a50a9a949470aed62..df0f08501bddd3c8a13dacc27262484deb372c26 100644 (file)
@@ -5,7 +5,7 @@
 //         Lluis Sanchez Gual (lluis@ideary.com)
 //
 // 2002 (C) Copyright, Ximian, Inc.
-//\r
+//
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-\r
-using System;\r
-using System.Runtime.Remoting.Channels;\r
-using System.Runtime.Remoting.Messaging;\r
-using System.Collections;\r
-using System.IO;\r
-using System.Threading;\r
-\r
-namespace System.Runtime.Remoting.Channels.Tcp\r
-{\r
+
+using System;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Messaging;
+using System.Collections;
+using System.IO;
+using System.Threading;
+
+namespace System.Runtime.Remoting.Channels.Tcp
+{
        internal class TcpClientTransportSink : IClientChannelSink
        {
                string _host;
-               string _url;
                int _port;
                
                public TcpClientTransportSink (string url)
                {
                        string objectUri;
-                       _host = TcpChannel.ParseTcpURL (url, out objectUri, out _port);
-                       _url = url;
+                       string port;
+                       
+                       TcpChannel.ParseTcpURL (url, out _host, out port, out objectUri);
+                       
+                       try {
+                               if (port != null)
+                                       _port = Convert.ToInt32 (port);
+                               else
+                                       _port = 0;
+                       } catch {
+                               _host = null;
+                               _port = -1;
+                       }
                }
 
                public IDictionary Properties
                {
-                       get \r
+                       get 
                        {
                                return null;
                        }
@@ -60,7 +70,7 @@ namespace System.Runtime.Remoting.Channels.Tcp
 
                public IClientChannelSink NextChannelSink
                {
-                       get \r
+                       get 
                        {
                                // we are the last one
                                return null;
@@ -83,13 +93,17 @@ namespace System.Runtime.Remoting.Channels.Tcp
                                // response of the server
 
                                connection = TcpConnectionPool.GetConnection (_host, _port);
-                               TcpMessageIO.SendMessageStream (connection.Stream, requestStream, headers, connection.Buffer);
+                               TcpMessageIO.SendMessageStream (connection.Stream, requestStream, headers, connection.Buffer, isOneWay);
                                connection.Stream.Flush ();
 
                                if (!isOneWay) 
                                {
                                        sinkStack.Push (this, connection);
-                                       ThreadPool.QueueUserWorkItem (new WaitCallback(ReadAsyncTcpMessage), sinkStack);
+                                       ThreadPool.QueueUserWorkItem (new WaitCallback(data => {
+                                               try {
+                                                       ReadAsyncTcpMessage (data);
+                                               } catch {}
+                                               }), sinkStack);
                                }
                                else
                                        connection.Release();
@@ -187,5 +201,5 @@ namespace System.Runtime.Remoting.Channels.Tcp
 
        }
 
-\r
-}\r
+
+}