Handle multiple concurrent calls to BeginTryReceiveRequest
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / PeerTransportBindingElement.cs
1 //
2 // PeerTransportBindingElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections.Generic;
30 using System.Net;
31 using System.Net.Security;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
34
35 namespace System.ServiceModel.Channels
36 {
37         [MonoTODO]
38         public sealed class PeerTransportBindingElement
39                 : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
40         {
41                 long max_recv_message_size = 0x10000;
42                 int port;
43                 PeerSecuritySettings security = new PeerSecuritySettings ();
44
45                 public PeerTransportBindingElement ()
46                 {
47                 }
48
49                 private PeerTransportBindingElement (
50                         PeerTransportBindingElement other)
51                         : base (other)
52                 {
53                         max_recv_message_size = other.max_recv_message_size;
54                         port = other.port;
55                         other.security.CopyTo (security);
56                 }
57
58                 public IPAddress ListenIPAddress { get; set; }
59
60                 public override long MaxReceivedMessageSize {
61                         get { return max_recv_message_size; }
62                         set { max_recv_message_size = value; }
63                 }
64
65                 public int Port {
66                         get { return port; }
67                         set { port = value; }
68                 }
69
70                 public override string Scheme {
71                         get { return "net.p2p"; }
72                 }
73
74                 public override bool CanBuildChannelFactory<TChannel> (
75                         BindingContext context)
76                 {
77                         return  typeof (TChannel) == typeof (IOutputChannel) ||
78                                 typeof (TChannel) == typeof (IDuplexChannel);
79                 }
80
81                 public override bool CanBuildChannelListener<TChannel> (
82                         BindingContext context)
83                 {
84                         return  typeof (TChannel) == typeof (IInputChannel) ||
85                                 typeof (TChannel) == typeof (IDuplexChannel);
86                 }
87
88                 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
89                         BindingContext context)
90                 {
91                         if (!CanBuildChannelFactory<TChannel> (context))
92                                 throw new ArgumentException (String.Format ("Not supported channel type '{0}'", typeof (TChannel)));
93                         if (typeof (TChannel) == typeof (IOutputChannel))
94                                 return (IChannelFactory<TChannel>) (object) new PeerChannelFactory<IOutputChannel> (this, context);
95                         else if (typeof (TChannel) == typeof (IDuplexChannel))
96                                 return (IChannelFactory<TChannel>) (object) new PeerChannelFactory<IDuplexChannel> (this, context);
97                         throw new InvalidOperationException (String.Format ("Not supported channel '{0}' (is incorrectly allowed at construction time)", typeof (TChannel)));
98                 }
99
100                 public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
101                         BindingContext context)
102                 {
103                         if (!CanBuildChannelListener<TChannel> (context))
104                                 throw new ArgumentException (String.Format ("Not supported channel type '{0}'", typeof (TChannel)));
105
106                         // FIXME: check LocalIPAddress.
107
108                         if (typeof (TChannel) == typeof (IInputChannel))
109                                 return (IChannelListener<TChannel>) (object) new PeerChannelListener<IInputChannel> (this, context);
110                         else if (typeof (TChannel) == typeof (IDuplexChannel))
111                                 return (IChannelListener<TChannel>) (object) new PeerChannelListener<IDuplexChannel> (this, context);
112                         throw new InvalidOperationException (String.Format ("Not supported channel '{0}' (is incorrectly allowed at construction time)", typeof (TChannel)));
113                 }
114
115                 public override BindingElement Clone ()
116                 {
117                         return new PeerTransportBindingElement (this);
118                 }
119
120                 public override T GetProperty<T> (BindingContext context)
121                 {
122                         if (typeof (T) == typeof (IBindingMulticastCapabilities))
123                                 return (T) (object) this;
124                         if (typeof (T) == typeof (ISecurityCapabilities))
125                                 return (T) (object) this;
126                         if (typeof (T) == typeof (IBindingDeliveryCapabilities))
127                                 return (T) (object) this;
128
129                         return base.GetProperty<T> (context);
130                 }
131
132                 public PeerSecuritySettings Security {
133                         get { return security; }
134                 }
135
136                 [MonoTODO]
137                 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext contxt)
138                 {
139                         throw new NotImplementedException ();
140                 }
141
142                 [MonoTODO]
143                 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter, WsdlEndpointConversionContext context)
144                 {
145                         throw new NotImplementedException ();
146                 }
147
148                 [MonoTODO]
149                 void IWsdlExportExtension.ExportContract (WsdlExporter exporter, WsdlContractConversionContext context)
150                 {
151                         throw new NotImplementedException ();
152                 }
153         }
154 }