Merge pull request #3248 from esdrubal/web_request_abort
[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 #if !MOBILE && !XAMMAC_4_5
35 using System.ServiceModel.Channels.NetTcp;
36 #endif
37 using System.ServiceModel.Description;
38
39 namespace System.ServiceModel.Channels
40 {
41         public class TcpTransportBindingElement
42                 : ConnectionOrientedTransportBindingElement
43         {
44                 internal const int DefaultPort = 808;
45
46                 int listen_backlog = 10;
47                 bool port_sharing_enabled = false;
48                 bool teredo_enabled = false;
49                 TcpConnectionPoolSettings pool = new TcpConnectionPoolSettings ();
50
51                 public TcpTransportBindingElement ()
52                 {
53                 }
54
55                 protected TcpTransportBindingElement (
56                         TcpTransportBindingElement other)
57                         : base (other)
58                 {
59                         listen_backlog = other.listen_backlog;
60                         port_sharing_enabled = other.port_sharing_enabled;
61                         pool.CopyPropertiesFrom (other.pool);
62                 }
63                 
64                 public TcpConnectionPoolSettings ConnectionPoolSettings {
65                         get { return pool; }
66                 }
67
68                 public int ListenBacklog {
69                         get { return listen_backlog; }
70                         set { listen_backlog = value; }
71                 }
72
73                 public bool PortSharingEnabled {
74                         get { return port_sharing_enabled; }
75                         set { port_sharing_enabled = value; }
76                 }
77
78                 public override string Scheme {
79                         get { return "net.tcp"; }
80                 }
81                 
82                 // As MSDN exposes, this' only available on Windows XP SP2 and Windows Server 2003
83                 public bool TeredoEnabled {
84                         get { return teredo_enabled; }
85                         set { teredo_enabled = value; }
86                 }
87
88                 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
89                         BindingContext context)
90                 {
91                         if (!CanBuildChannelFactory<TChannel> (context))
92                                 throw new InvalidOperationException (String.Format ("Not supported channel factory type '{0}'", typeof (TChannel)));
93
94 #if !MOBILE && !XAMMAC_4_5
95                         return new TcpChannelFactory<TChannel> (this, context);
96 #else
97                         throw new NotImplementedException ();
98 #endif
99                 }
100
101 #if !MOBILE && !XAMMAC_4_5
102                 public override IChannelListener<TChannel>
103                         BuildChannelListener<TChannel> (
104                         BindingContext context)
105                 {
106                         if (!CanBuildChannelListener<TChannel> (context))
107                                 throw new InvalidOperationException (String.Format ("Not supported channel listener type '{0}'", typeof (TChannel)));
108                         return new TcpChannelListener<TChannel> (this, context);
109                 }
110 #endif
111
112                 public override BindingElement Clone ()
113                 {
114                         return new TcpTransportBindingElement (this);
115                 }
116
117                 public override T GetProperty<T> (BindingContext context)
118                 {
119                         if (typeof (T) == typeof (IBindingDeliveryCapabilities))
120                                 return (T) (object) new TcpBindingProperties (this);
121                         return base.GetProperty<T> (context);
122                 }
123         }
124
125         class TcpBindingProperties : IBindingDeliveryCapabilities
126         {
127                 TcpTransportBindingElement source;
128
129                 public TcpBindingProperties (TcpTransportBindingElement source)
130                 {
131                         this.source = source;
132                 }
133
134                 public bool AssuresOrderedDelivery {
135                         get { return true; }
136                 }
137
138                 public bool QueuedDelivery {
139                         get { return false; }
140                 }
141         }
142 }