2010-01-22 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 22 Jan 2010 05:00:21 +0000 (05:00 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 22 Jan 2010 05:00:21 +0000 (05:00 -0000)
* TcpDuplexSessionChannel.cs, PeerDuplexChannel.cs,
  DuplexChannelBase.cs : Receive() should rather use TryReceive().
  It should not be in reverse order.

svn path=/trunk/mcs/; revision=150040

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/DuplexChannelBase.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/PeerDuplexChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs

index bb701295ce8e14a546e1b18ed71c99f565e2e0ae..06da990b9aee120866b8cf0a1d3edbb5d26815e9 100755 (executable)
@@ -1,3 +1,9 @@
+2010-01-22  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * TcpDuplexSessionChannel.cs, PeerDuplexChannel.cs,
+         DuplexChannelBase.cs : Receive() should rather use TryReceive().
+         It should not be in reverse order.
+
 2010-01-22  Atsushi Enomoto  <atsushi@ximian.com>
 
        * HttpReplyChannel.cs, HttpListenerManager.cs :
index 75149f816f4a7225d0058f33066084d6b5f762fd..f38c6382e0c3df135435dab5b22ee5a86e23f409 100644 (file)
@@ -166,7 +166,13 @@ namespace System.ServiceModel.Channels
                        return Receive (this.DefaultReceiveTimeout);
                }
 
-               public abstract Message Receive (TimeSpan timeout);
+               public virtual Message Receive (TimeSpan timeout)
+               {
+                       Message msg;
+                       if (!TryReceive (timeout, out msg))
+                               throw new TimeoutException ();
+                       return msg;
+               }
 
                // TryReceive
 
@@ -184,16 +190,7 @@ namespace System.ServiceModel.Channels
                        return try_receive_handler.EndInvoke (out message, result);
                }
                
-               public virtual bool TryReceive (TimeSpan timeout, out Message message)
-               {
-                       try {
-                               message = Receive (timeout);
-                               return true;
-                       } catch (TimeoutException) {
-                               message = null;
-                               return false;
-                       }
-               }
+               public abstract bool TryReceive (TimeSpan timeout, out Message message);
 
                // WaitForMessage
 
index 85207a3a2198b64fa836d02c4ad66b3729d28340..21f63bb794295570edbe83642f03b12a9b900533 100755 (executable)
@@ -256,15 +256,18 @@ namespace System.ServiceModel.Channels
                Queue<Message> queue = new Queue<Message> ();
                AutoResetEvent receive_handle = new AutoResetEvent (false);
 
-               public override Message Receive (TimeSpan timeout)
+               public override bool TryReceive (TimeSpan timeout, out Message message)
                {
                        ThrowIfDisposedOrNotOpen ();
                        DateTime start = DateTime.Now;
 
-                       if (queue.Count > 0)
-                               return queue.Dequeue ();
-                       receive_handle.WaitOne ();
-                       return queue.Dequeue ();
+                       if (queue.Count > 0 || receive_handle.WaitOne (timeout)) {
+                               message = queue.Dequeue ();
+                               return message == null;
+                       } else {
+                               message = null;
+                               return false;
+                       }
                }
 
                public override bool WaitForMessage (TimeSpan timeout)
index 0ffcf8837e27802fe0bc6632ec95c37f5b814fb6..f9f7e38f942d1080b0e5112ae2c8cf0c26fbd6dd 100644 (file)
@@ -153,37 +153,20 @@ namespace System.ServiceModel.Channels
                        frame.WriteSizedMessage (message);
                }
                
-               public override Message Receive ()
-               {
-                       return Receive (DefaultReceiveTimeout);
-               }
-               
-               public override Message Receive (TimeSpan timeout)
+               public override bool TryReceive (TimeSpan timeout, out Message message)
                {
                        ThrowIfDisposedOrNotOpen ();
 
                        if (timeout <= TimeSpan.Zero)
                                throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
                        client.ReceiveTimeout = (int) timeout.TotalMilliseconds;
-                       var ret = frame.ReadSizedMessage ();
+                       message = frame.ReadSizedMessage ();
                        // FIXME: this may not be precise, but connection might be reused for some weird socket state transition (that's what happens). So as a workaround, avoid closing the session by sending EndRecord from this channel at OnClose().
-                       if (ret == null)
+                       if (message == null) {
                                session = null;
-                       return ret;
-               }
-               
-               public override bool TryReceive (TimeSpan timeout, out Message message)
-               {
-                       try {
-                               DateTime start = DateTime.Now;
-                               message = Receive (timeout);
-                               if (message != null)
-                                       return true;
-                               return false;
-                       } catch (TimeoutException) {
-                               message = null;
                                return false;
                        }
+                       return true;
                }
                
                public override bool WaitForMessage (TimeSpan timeout)