Просмотр исходного кода

2009-06-11 Atsushi Enomoto <[email protected]>

	* HttpChannelListener.cs, TcpChannelListener.cs,
	  ChannelListenerBase_1.cs : put common internal listener base
	  and let it handle those async stuff.


svn path=/trunk/mcs/; revision=135916
Atsushi Eno 16 лет назад
Родитель
Сommit
6f61807f8d

+ 6 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,9 @@
+2009-06-11  Atsushi Enomoto  <[email protected]>
+
+	* HttpChannelListener.cs, TcpChannelListener.cs,
+	  ChannelListenerBase_1.cs : put common internal listener base
+	  and let it handle those async stuff.
+
 2009-06-10  Atsushi Enomoto  <[email protected]>
 
 	* ReplyChannelBase.cs : fix wrong null delegate check point.

+ 80 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChannelListenerBase_1.cs

@@ -30,6 +30,86 @@ using System.ServiceModel;
 
 namespace System.ServiceModel.Channels
 {
+	internal abstract class InternalChannelListenerBase<TChannel>
+		: ChannelListenerBase<TChannel>
+		where TChannel : class, IChannel
+	{
+		protected InternalChannelListenerBase ()
+			: base ()
+		{
+		}
+
+		protected InternalChannelListenerBase (IDefaultCommunicationTimeouts timeouts)
+			: base (timeouts)
+		{
+		}
+
+		Func<TimeSpan,TChannel> accept_channel_delegate;
+		Func<TimeSpan,bool> wait_delegate;
+		Action<TimeSpan> open_delegate, close_delegate;
+
+		protected override IAsyncResult OnBeginAcceptChannel (
+			TimeSpan timeout, AsyncCallback callback,
+			object asyncState)
+		{
+			if (accept_channel_delegate == null)
+				accept_channel_delegate = new Func<TimeSpan,TChannel> (OnAcceptChannel);
+			return accept_channel_delegate.BeginInvoke (timeout, callback, asyncState);
+		}
+
+		protected override TChannel OnEndAcceptChannel (IAsyncResult result)
+		{
+			if (accept_channel_delegate == null)
+				throw new InvalidOperationException ("Async AcceptChannel operation has not started");
+			return accept_channel_delegate.EndInvoke (result);
+		}
+
+		protected override IAsyncResult OnBeginWaitForChannel (
+			TimeSpan timeout, AsyncCallback callback, object state)
+		{
+			if (wait_delegate == null)
+				wait_delegate = new Func<TimeSpan,bool> (OnWaitForChannel);
+			return wait_delegate.BeginInvoke (timeout, callback, state);
+		}
+
+		protected override bool OnEndWaitForChannel (IAsyncResult result)
+		{
+			if (wait_delegate == null)
+				throw new InvalidOperationException ("Async WaitForChannel operation has not started");
+			return wait_delegate.EndInvoke (result);
+		}
+
+		protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
+			AsyncCallback callback, object state)
+		{
+			if (open_delegate == null)
+				open_delegate = new Action<TimeSpan> (OnOpen);
+			return open_delegate.BeginInvoke (timeout, callback, state);
+		}
+
+		protected override void OnEndOpen (IAsyncResult result)
+		{
+			if (open_delegate == null)
+				throw new InvalidOperationException ("Async Open operation has not started");
+			open_delegate.EndInvoke (result);
+		}
+
+		protected override IAsyncResult OnBeginClose (TimeSpan timeout,
+			AsyncCallback callback, object state)
+		{
+			if (close_delegate == null)
+				close_delegate = new Action<TimeSpan> (OnClose);
+			return close_delegate.BeginInvoke (timeout, callback, state);
+		}
+
+		protected override void OnEndClose (IAsyncResult result)
+		{
+			if (close_delegate == null)
+				throw new InvalidOperationException ("Async Close operation has not started");
+			close_delegate.EndInvoke (result);
+		}
+	}
+
 	public abstract class ChannelListenerBase<TChannel>
 		: ChannelListenerBase, IChannelListener<TChannel>, 
 		IChannelListener,  ICommunicationObject

+ 1 - 51
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpChannelListener.cs

@@ -99,7 +99,7 @@ namespace System.ServiceModel.Channels
 		}
 	}
 
-	internal abstract class HttpChannelListenerBase<TChannel> : ChannelListenerBase<TChannel>
+	internal abstract class HttpChannelListenerBase<TChannel> : InternalChannelListenerBase<TChannel>
 		where TChannel : class, IChannel
 	{
 		HttpTransportBindingElement source;
@@ -112,7 +112,6 @@ namespace System.ServiceModel.Channels
 			BindingContext context)
 			: base (context.Binding)
 		{
-			accept_channel_delegate = new Func<TimeSpan,TChannel> (OnAcceptChannel);
 
 			// FIXME: consider ListenUriMode
 			// FIXME: there should be some way to post-provide Uri in case of null listenerUri in context.
@@ -150,60 +149,11 @@ namespace System.ServiceModel.Channels
 
 		protected abstract TChannel CreateChannel (TimeSpan timeout);
 
-		Func<TimeSpan,TChannel> accept_channel_delegate;
-
-		protected override IAsyncResult OnBeginAcceptChannel (
-			TimeSpan timeout, AsyncCallback callback,
-			object asyncState)
-		{
-			return accept_channel_delegate.BeginInvoke (timeout, callback, asyncState);
-		}
-
-		protected override TChannel OnEndAcceptChannel (IAsyncResult result)
-		{
-			return accept_channel_delegate.EndInvoke (result);
-		}
-
-		protected override IAsyncResult OnBeginWaitForChannel (
-			TimeSpan timeout, AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
-		protected override bool OnEndWaitForChannel (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-
 		protected override bool OnWaitForChannel (TimeSpan timeout)
 		{
 			throw new NotImplementedException ();
 		}
 
-		protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
-			AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
-		protected override void OnEndOpen (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override IAsyncResult OnBeginClose (TimeSpan timeout,
-			AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override void OnEndClose (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-
 		[MonoTODO ("find out what to do here.")]
 		protected override void OnAbort ()
 		{

+ 1 - 53
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs

@@ -18,7 +18,7 @@ using System.Xml;
 
 namespace System.ServiceModel.Channels
 {
-	internal class TcpChannelListener<TChannel> : ChannelListenerBase<TChannel> 
+	internal class TcpChannelListener<TChannel> : InternalChannelListenerBase<TChannel> 
 		where TChannel : class, IChannel
 	{
 		List<IChannel> channels = new List<IChannel> ();
@@ -80,32 +80,6 @@ namespace System.ServiceModel.Channels
 			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
-		protected override IAsyncResult OnBeginAcceptChannel (TimeSpan timeout,
-			AsyncCallback callback, object asyncState)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override TChannel OnEndAcceptChannel (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-		
-		[MonoTODO]
-		protected override IAsyncResult OnBeginWaitForChannel (
-			TimeSpan timeout, AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override bool OnEndWaitForChannel (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-
 		[MonoTODO]
 		protected override bool OnWaitForChannel (TimeSpan timeout)
 		{
@@ -120,20 +94,6 @@ namespace System.ServiceModel.Channels
 			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
-		protected override IAsyncResult OnBeginClose (TimeSpan timeout,
-			AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
-			AsyncCallback callback, object state)
-		{
-			throw new NotImplementedException ();
-		}
-
 		[MonoTODO]
 		protected override void OnClose (TimeSpan timeout)
 		{
@@ -141,18 +101,6 @@ namespace System.ServiceModel.Channels
 			tcp_listener = null;
 		}
 		
-		[MonoTODO]
-		protected override void OnEndClose (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-
-		[MonoTODO]
-		protected override void OnEndOpen (IAsyncResult result)
-		{
-			throw new NotImplementedException ();
-		}
-		
 		[MonoTODO]
 		protected override void OnOpen (TimeSpan timeout)
 		{