add ISafeSerializationData
[mcs.git] / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Tcp / TcpClientChannel.cs
blob37a34b161b1dfa0751400c7763860ba883fcd6a0
1 //
2 // System.Runtime.Remoting.Channels.Tcp.TcpClientChannel.cs
3 //
4 // Author: Dietmar Maurer (dietmar@ximian.com)
5 // Lluis Sanchez Gual (lluis@ideary.com)
6 //
7 // 2002 (C) Copyright, Ximian, Inc.
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.IO;
33 using System.Net.Sockets;
34 using System.Runtime.Remoting.Messaging;
35 using System.Runtime.Remoting.Channels;
36 using System.Threading;
38 namespace System.Runtime.Remoting.Channels.Tcp
40 public class TcpClientChannel : IChannelSender, IChannel
42 int priority = 1;
43 string name = "tcp";
44 IClientChannelSinkProvider _sinkProvider;
46 public TcpClientChannel ()
48 _sinkProvider = new BinaryClientFormatterSinkProvider ();
49 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
52 public TcpClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
54 if (properties != null) {
55 object val = properties ["name"];
56 if (val != null) name = val as string;
58 val = properties ["priority"];
59 if (val != null) priority = Convert.ToInt32 (val);
62 if (sinkProvider != null)
64 _sinkProvider = sinkProvider;
66 // add the tcp provider at the end of the chain
67 IClientChannelSinkProvider prov = sinkProvider;
68 while (prov.Next != null) prov = prov.Next;
69 prov.Next = new TcpClientTransportSinkProvider ();
71 // Note: a default formatter is added only when
72 // no sink providers are specified in the config file.
74 else
76 _sinkProvider = new BinaryClientFormatterSinkProvider ();
77 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
82 public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
84 this.name = name;
86 if (sinkProvider != null) {
87 _sinkProvider = sinkProvider;
89 // add the tcp provider at the end of the chain
90 IClientChannelSinkProvider prov = sinkProvider;
91 while (prov.Next != null)
92 prov = prov.Next;
93 prov.Next = new TcpClientTransportSinkProvider ();
94 } else {
95 _sinkProvider = new BinaryClientFormatterSinkProvider ();
96 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
100 public string ChannelName
102 get {
103 return name;
107 public int ChannelPriority
109 get {
110 return priority;
114 public virtual IMessageSink CreateMessageSink (string url,
115 object remoteChannelData,
116 out string objectURI)
118 if (url != null && Parse (url, out objectURI) != null)
119 return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
121 if (remoteChannelData != null) {
122 IChannelDataStore ds = remoteChannelData as IChannelDataStore;
123 if (ds != null && ds.ChannelUris.Length > 0)
124 url = ds.ChannelUris [0];
125 else {
126 objectURI = null;
127 return null;
131 if (Parse (url, out objectURI) == null)
132 return null;
134 return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
137 public string Parse (string url, out string objectURI)
139 return TcpChannel.ParseChannelUrl (url, out objectURI);