2009-04-28 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / TcpTransportBindingElement.cs
1 //
2 // TcpTransportBindingElement.cs
3 //
4 // Authors:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //      Marcos Cobena (marcoscobena@gmail.com)
7 //
8 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Collections.Generic;
32 using System.Net;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35
36 namespace System.ServiceModel.Channels
37 {
38         [MonoTODO]
39         public class TcpTransportBindingElement
40                 : ConnectionOrientedTransportBindingElement
41         {
42                 internal const int DefaultPort = 808;
43
44                 int listen_backlog = 10;
45                 bool port_sharing_enabled = false;
46                 bool teredo_enabled = false;
47                 TcpConnectionPoolSettings pool = new TcpConnectionPoolSettings ();
48
49                 public TcpTransportBindingElement ()
50                 {
51                 }
52
53                 protected TcpTransportBindingElement (
54                         TcpTransportBindingElement other)
55                         : base (other)
56                 {
57                         listen_backlog = other.listen_backlog;
58                         port_sharing_enabled = other.port_sharing_enabled;
59                         pool.CopyPropertiesFrom (other.pool);
60                 }
61                 
62                 public TcpConnectionPoolSettings ConnectionPoolSettings {
63                         get { return pool; }
64                 }
65
66                 public int ListenBacklog {
67                         get { return listen_backlog; }
68                         set { listen_backlog = value; }
69                 }
70
71                 public bool PortSharingEnabled {
72                         get { return port_sharing_enabled; }
73                         set { port_sharing_enabled = value; }
74                 }
75
76                 public override string Scheme {
77                         get { return "net.tcp"; }
78                 }
79                 
80                 // As MSDN exposes, this' only available on Windows XP SP2 and Windows Server 2003
81                 public bool TeredoEnabled {
82                         get { return teredo_enabled; }
83                         set { teredo_enabled = value; }
84                 }
85
86                 [MonoTODO]
87                 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
88                         BindingContext context)
89                 {
90                         if (!CanBuildChannelFactory<TChannel> (context))
91                                 throw new InvalidOperationException (String.Format ("Not supported channel factory type '{0}'", typeof (TChannel)));
92                         return new TcpChannelFactory<TChannel> (this, context);
93                 }
94
95                 public override IChannelListener<TChannel>
96                         BuildChannelListener<TChannel> (
97                         BindingContext context)
98                 {
99                         if (!CanBuildChannelListener<TChannel> (context))
100                                 throw new InvalidOperationException (String.Format ("Not supported channel listener type '{0}'", typeof (TChannel)));
101                         return new TcpChannelListener<TChannel> (this, context);
102                 }
103
104                 public override BindingElement Clone ()
105                 {
106                         return new TcpTransportBindingElement (this);
107                 }
108
109                 [MonoTODO]
110                 public override T GetProperty<T> (BindingContext context)
111                 {
112                         // FIXME: ... or return ISecurityCapabilities?
113                         return context.GetInnerProperty<T> ();
114                 }
115         }
116 }