2009-06-11 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 11 Jun 2009 09:10:38 +0000 (09:10 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 11 Jun 2009 09:10:38 +0000 (09:10 -0000)
* 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

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChannelListenerBase_1.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpChannelListener.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpChannelListener.cs

index 98b44e5fad10b7fd45ac323fd3a4884b79214e86..89981ed5e17af1f4b244833048049bb1ba6f8515 100755 (executable)
@@ -1,3 +1,9 @@
+2009-06-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * HttpChannelListener.cs, TcpChannelListener.cs,
+         ChannelListenerBase_1.cs : put common internal listener base
+         and let it handle those async stuff.
+
 2009-06-10  Atsushi Enomoto  <atsushi@ximian.com>
 
        * ReplyChannelBase.cs : fix wrong null delegate check point.
index 8d11e8ce07be0c1e7b213d441279e6cf3e060482..9268afefbedd7dc642f4ba776d2f1d04b0c9b3db 100644 (file)
@@ -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
index 8711e3713bde6d18e6047714d9e66806b3e371ca..a1aeca44f00113d3e74ace38cf850cca39dacc0d 100644 (file)
@@ -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 ()
                {
index f5b813911e99660a8aaea66a5aa4aac5e10cdfd3..9bb36561be86609402bea6069e2e884ef8fb3ec5 100644 (file)
@@ -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)
                {