X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Runtime.Remoting%2FSystem.Runtime.Remoting.Channels.Tcp%2FTcpServerChannel.cs;h=300954769ed8d3d11ccbeaf0f8d816e32c297989;hb=64f85a65b023522d3f34e9932e6a843e0ad8fc3b;hp=a538a34b71a7a33b58894104da3abe677edd888d;hpb=74c2e813151ef52866b58da63aeeed698b5e67dd;p=mono.git diff --git a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs index a538a34b71a..300954769ed 100644 --- a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs +++ b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs @@ -56,9 +56,13 @@ namespace System.Runtime.Remoting.Channels.Tcp RemotingThreadPool threadPool; +#if TARGET_JVM + private volatile bool stopped = false; +#endif + void Init (IServerChannelSinkProvider serverSinkProvider) { - if (serverSinkProvider == null) + if (serverSinkProvider == null) { serverSinkProvider = new BinaryServerFormatterSinkProvider (); } @@ -80,16 +84,16 @@ namespace System.Runtime.Remoting.Channels.Tcp // Gets channel data from the chain of channel providers channel_data = new ChannelDataStore (null); - IServerChannelSinkProvider provider = serverSinkProvider; - while (provider != null) - { - provider.GetChannelData(channel_data); - provider = provider.Next; - } + IServerChannelSinkProvider provider = serverSinkProvider; + while (provider != null) + { + provider.GetChannelData(channel_data); + provider = provider.Next; + } // Creates the sink chain that will process all incoming messages - IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain (serverSinkProvider, this); + IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain (serverSinkProvider, this); sink = new TcpServerTransportSink (next_sink); } @@ -103,35 +107,35 @@ namespace System.Runtime.Remoting.Channels.Tcp IServerChannelSinkProvider serverSinkProvider) { foreach(DictionaryEntry property in properties) - { - switch((string)property.Key) - { + { + switch((string)property.Key) + { case "name": name = property.Value.ToString(); break; - case "port": + case "port": port = Convert.ToInt32(property.Value); - break; - case "priority": + break; + case "priority": priority = Convert.ToInt32(property.Value); - break; - case "bindTo": + break; + case "bindTo": bindAddress = IPAddress.Parse((string)property.Value); - break; - case "rejectRemoteRequests": + break; + case "rejectRemoteRequests": if(Convert.ToBoolean(properties["rejectRemoteRequests"])) bindAddress = IPAddress.Loopback; break; case "supressChannelData": supressChannelData = Convert.ToBoolean (property.Value); - break; + break; case "useIpAddress": useIpAddress = Convert.ToBoolean (property.Value); break; case "machineName": host = property.Value as string; break; - } + } } Init (serverSinkProvider); } @@ -178,18 +182,18 @@ namespace System.Runtime.Remoting.Channels.Tcp return "tcp://" + host + ":" + port; } - public string[] GetUrlsForUri (string uri) - { + public virtual string[] GetUrlsForUri (string uri) + { if (!uri.StartsWith ("/")) uri = "/" + uri; - - string [] chnl_uris = channel_data.ChannelUris; - string [] result = new String [chnl_uris.Length]; - - for (int i = 0; i < chnl_uris.Length; i++) - result [i] = chnl_uris [i] + uri; - - return result; - } + + string [] chnl_uris = channel_data.ChannelUris; + string [] result = new String [chnl_uris.Length]; + + for (int i = 0; i < chnl_uris.Length; i++) + result [i] = chnl_uris [i] + uri; + + return result; + } public string Parse (string url, out string objectURI) { @@ -200,24 +204,40 @@ namespace System.Runtime.Remoting.Channels.Tcp { try { - while (true) +#if !TARGET_JVM + while(true) +#else + while(!stopped) +#endif { Socket socket = listener.AcceptSocket (); ClientConnection reader = new ClientConnection (this, socket, sink); try { if (!threadPool.RunThread (new ThreadStart (reader.ProcessMessages))) socket.Close (); - } catch {} + } catch (Exception e) + { +#if DEBUG + Console.WriteLine("Exception caught in TcpServerChannel.WaitForConnections during start process message: {0} {1}", e.GetType(), e.Message); +#endif + } } } - catch - {} + catch (Exception e) + { +#if DEBUG + Console.WriteLine("Exception caught in TcpServerChannel.WaitForConnections, stop channel's thread : {0} {1}", e.GetType(), e.Message); +#endif + } } public void StartListening (object data) { +#if TARGET_JVM + stopped = false; +#endif listener = new TcpListener (bindAddress, port); - if (server_thread == null) + if (server_thread == null) { threadPool = RemotingThreadPool.GetSharedPool (); listener.Start (); @@ -238,13 +258,20 @@ namespace System.Runtime.Remoting.Channels.Tcp public void StopListening (object data) { +#if TARGET_JVM + stopped = true; +#endif if (server_thread == null) return; +#if !TARGET_JVM server_thread.Abort (); +#else + server_thread.Interrupt (); +#endif listener.Stop (); threadPool.Free (); server_thread.Join (); - server_thread = null; + server_thread = null; } } @@ -265,9 +292,8 @@ namespace System.Runtime.Remoting.Channels.Tcp _id = _count++; } - public Stream Stream - { - get { return _stream; } + public Socket Socket { + get { return _socket; } } public byte[] Buffer @@ -291,7 +317,7 @@ namespace System.Runtime.Remoting.Channels.Tcp switch (type) { case MessageStatus.MethodMessage: - _sink.InternalProcessMessage (this); + _sink.InternalProcessMessage (this, _stream); break; case MessageStatus.Unknown: @@ -304,7 +330,9 @@ namespace System.Runtime.Remoting.Channels.Tcp } catch (Exception ex) { -// Console.WriteLine (ex); +#if DEBUG + Console.WriteLine ("The exception was caught during TcpServerChannel.ProcessMessages: {0}, {1}", ex.GetType(), ex.Message); +#endif } finally {