using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.Text;
+using System.Threading;
namespace System.ServiceModel.Channels
{
{
PeerTransportBindingElement source;
BindingContext context;
- Uri listen_uri;
- List<IChannel> channels = new List<IChannel> ();
+ TChannel channel;
MessageEncoder encoder;
+ AutoResetEvent accept_handle = new AutoResetEvent (false);
public PeerChannelListener (PeerTransportBindingElement source,
BindingContext context)
- : base (context.Binding)
+ : base (context)
{
- // FIXME: consider ListenUriMode
- // FIXME: there should be some way to post-provide Uri in case of null listenerUri in context.
- listen_uri = context.ListenUriBaseAddress != null ?
- new Uri (context.ListenUriBaseAddress, context.ListenUriRelativeAddress) : null;
+ this.source = source;
foreach (BindingElement be in context.RemainingBindingElements) {
MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
if (mbe != null) {
}
}
if (encoder == null)
- encoder = new TextMessageEncoder (MessageVersion.Default, Encoding.UTF8);
+ encoder = new BinaryMessageEncoder ();
}
public PeerResolver Resolver { get; set; }
get { return encoder; }
}
- public override Uri Uri {
- get { return listen_uri; }
- }
-
protected override TChannel OnAcceptChannel (TimeSpan timeout)
{
- TChannel ch = PopulateChannel (timeout);
- channels.Add (ch);
- return ch;
+ DateTime start = DateTime.Now;
+ if (channel != null)
+ if (!accept_handle.WaitOne (timeout))
+ throw new TimeoutException ();
+ channel = PopulateChannel (timeout - (DateTime.Now - start));
+ ((CommunicationObject) (object) channel).Closed += delegate {
+ this.channel = null;
+ accept_handle.Set ();
+ };
+ return channel;
}
TChannel PopulateChannel (TimeSpan timeout)
protected override void OnOpen (TimeSpan timeout)
{
- throw new NotImplementedException ();
}
protected override void OnClose (TimeSpan timeout)
{
- if (ServiceHostingEnvironment.InAspNet)
- return;
-
- foreach (TChannel ch in channels)
- ch.Close(timeout);
+ if (channel != null)
+ channel.Close (timeout);
}
- [MonoTODO ("find out what to do here.")]
protected override void OnAbort ()
{
+ if (channel != null)
+ channel.Abort ();
}
}
}