Ignore test .dll and .pdb files
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Tcp / TcpClientChannel.cs
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 //
9
10 using System.Collections;
11 using System.IO;
12 using System.Net.Sockets;
13 using System.Runtime.Remoting.Messaging;
14 using System.Runtime.Remoting.Channels;
15 using System.Threading;
16
17 namespace System.Runtime.Remoting.Channels.Tcp
18 {
19         public class TcpClientChannel : IChannelSender, IChannel
20         {
21                 int priority = 1;                                       
22                 string name = "tcp";
23                 IClientChannelSinkProvider _sinkProvider;
24                 
25                 public TcpClientChannel ()
26                 {
27                 }
28
29                 public TcpClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
30                 {
31                         object val = properties ["name"];
32                         if (val != null) name = val as string;
33                         
34                         val = properties ["priority"];
35                         if (val != null) priority = Convert.ToInt32 (val);
36                         
37                         if (sinkProvider != null)
38                         {
39                                 _sinkProvider = sinkProvider;
40
41                                 // add the tcp provider at the end of the chain
42                                 IClientChannelSinkProvider prov = sinkProvider;
43                                 while (prov.Next != null) prov = prov.Next;
44                                 prov.Next = new TcpClientTransportSinkProvider ();
45
46                                 // Note: a default formatter is added only when
47                                 // no sink providers are specified in the config file.
48                         }
49                         else
50                         {
51                                 _sinkProvider = new BinaryClientFormatterSinkProvider ();
52                                 _sinkProvider.Next = new TcpClientTransportSinkProvider ();
53                         }
54
55                 }
56
57                 public TcpClientChannel (string name, IClientChannelSinkProvider sinkProvider)
58                 {
59                         this.name = name;
60                         _sinkProvider = sinkProvider;
61
62                         // add the tcp provider at the end of the chain
63                         IClientChannelSinkProvider prov = sinkProvider;
64                         while (prov.Next != null) prov = prov.Next;
65                         prov.Next = new TcpClientTransportSinkProvider ();
66                 }
67                 
68                 public string ChannelName
69                 {
70                         get {
71                                 return name;
72                         }
73                 }
74
75                 public int ChannelPriority
76                 {
77                         get {
78                                 return priority;
79                         }
80                 }
81
82                 public IMessageSink CreateMessageSink (string url,
83                                                        object remoteChannelData,
84                                                        out string objectURI)
85             {
86                         if (url == null && remoteChannelData != null) {
87                                 IChannelDataStore ds = remoteChannelData as IChannelDataStore;
88                                 if (ds != null && ds.ChannelUris.Length > 0)
89                                         url = ds.ChannelUris [0];
90                                 else {
91                                         objectURI = null;
92                                         return null;
93                                 }
94                         }
95
96                         if (Parse (url, out objectURI) == null)
97                                 return null;
98
99                         return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
100                 }
101
102                 public string Parse (string url, out string objectURI)
103                 {
104                         return TcpChannel.ParseChannelUrl (url, out objectURI);
105                 }
106         }
107 }