2010-04-06 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 6 Apr 2010 05:01:51 +0000 (05:01 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 6 Apr 2010 05:01:51 +0000 (05:01 -0000)
* HttpRequestChannel.cs: don't create the wait handle unless it is
really needed.

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

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpRequestChannel.cs

index 520a5a378b191c94a757b16821b994b66d857e57..bd445c6f77b8a2049312c60ae85b4bcdca889f89 100755 (executable)
@@ -1,3 +1,8 @@
+2010-04-06 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * HttpRequestChannel.cs: don't create the wait handle unless it is
+       really needed.
+
 2010-04-02  Atsushi Enomoto  <atsushi@ximian.com>
 
        * HttpRequestChannel.cs : use correct max buffer size.
index 42fb54e2279f47da959c8462af0a39b6dca2c77a..c6a9e6f80ff24aab26eb4f64632fb269a4b4bae3 100644 (file)
@@ -317,16 +317,15 @@ w.Close ();
                        AsyncCallback callback;
                        ManualResetEvent wait;
                        Exception error;
+                       object locker = new object ();
+                       bool is_completed;
 
                        public HttpChannelRequestAsyncResult (Message message, TimeSpan timeout, AsyncCallback callback, object state)
                        {
-                               CompletedSynchronously = true;
                                Message = message;
                                Timeout = timeout;
                                this.callback = callback;
                                AsyncState = state;
-
-                               wait = new ManualResetEvent (false);
                        }
 
                        public Message Response {
@@ -334,7 +333,13 @@ w.Close ();
                        }
 
                        public WaitHandle AsyncWaitHandle {
-                               get { return wait; }
+                               get {
+                                       lock (locker) {
+                                               if (wait == null)
+                                                       wait = new ManualResetEvent (is_completed);
+                                       }
+                                       return wait;
+                               }
                        }
 
                        public object AsyncState {
@@ -355,7 +360,6 @@ w.Close ();
                                error = error ?? ex;
 
                                IsCompleted = true;
-                               wait.Set ();
                                if (callback != null)
                                        callback (this);
                        }
@@ -365,7 +369,14 @@ w.Close ();
                        }
 
                        public bool IsCompleted {
-                               get; private set;
+                               get { return is_completed; }
+                               set {
+                                       is_completed = value;
+                                       lock (locker) {
+                                               if (is_completed && wait != null)
+                                                       wait.Set ();
+                                       }
+                               }
                        }
 
                        public void WaitEnd ()
@@ -376,9 +387,9 @@ w.Close ();
                                        // exception to the Complete () method and allow the result to complete 'normally'.
 #if NET_2_1
                                        // neither Moonlight nor MonoTouch supports contexts (WaitOne default to false)
-                                       bool result = wait.WaitOne (Timeout);
+                                       bool result = AsyncWaitHandle.WaitOne (Timeout);
 #else
-                                       bool result = wait.WaitOne (Timeout, true);
+                                       bool result = AsyncWaitHandle.WaitOne (Timeout, true);
 #endif
                                        if (!result)
                                                throw new TimeoutException ();