2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / WebClientAsyncResult.cs
index 0102fb93ce500d8ed0e797d04dbaf921db470b19..476f87ac6170677e6decaff03e5fb6732472affb 100644 (file)
@@ -3,9 +3,31 @@
 //\r
 // Author:\r
 //   Tim Coleman (tim@timcoleman.com)\r
+//   Lluis Sanchez Gual (lluis@ximian.com)\r
 //\r
 // Copyright (C) Tim Coleman, 2002\r
 //\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 \r
 using System.Net;\r
 using System.Threading;\r
@@ -15,24 +37,26 @@ namespace System.Web.Services.Protocols {
 \r
                #region Fields\r
 \r
-               WaitHandle waitHandle;\r
-\r
-               WebClientProtocol protocol;\r
-               WebRequest request;\r
-               AsyncCallback callback;\r
-               object asyncState;\r
-\r
+               AsyncCallback _callback;\r
+               object _asyncState;\r
+\r
+               bool _completedSynchronously;\r
+               bool _done;\r
+               ManualResetEvent _waitHandle;\r
+               \r
+               internal object Result;\r
+               internal Exception Exception;\r
+               internal WebRequest Request;\r
+                       \r
                #endregion // Fields\r
 \r
                #region Constructors \r
 \r
-               [MonoTODO ("Figure out what this does.")]\r
-               internal WebClientAsyncResult (WebClientProtocol protocol, object x, WebRequest request, AsyncCallback callback, object asyncState, int y)\r
+               internal WebClientAsyncResult (WebRequest request, AsyncCallback callback, object asyncState)\r
                {\r
-                       this.protocol = protocol;\r
-                       this.request = request;\r
-                       this.callback = callback; \r
-                       this.asyncState = asyncState;\r
+                       _callback = callback; \r
+                       Request = request;\r
+                       _asyncState = asyncState;\r
                }\r
 \r
                #endregion // Constructors\r
@@ -40,21 +64,29 @@ namespace System.Web.Services.Protocols {
                #region Properties\r
 \r
                public object AsyncState {\r
-                       get { return asyncState; }\r
+                       get { return _asyncState; }\r
                }\r
 \r
-               public WaitHandle AsyncWaitHandle {\r
-                       get { return waitHandle; }\r
+               public WaitHandle AsyncWaitHandle \r
+               {\r
+                       get\r
+                       {\r
+                               lock (this) {\r
+                                       if (_waitHandle != null) return _waitHandle;\r
+                                       _waitHandle = new ManualResetEvent (_done);\r
+                                       return _waitHandle;\r
+                               }\r
+                       }\r
                }\r
 \r
-               public bool CompletedSynchronously {\r
-                       [MonoTODO]\r
-                       get { throw new NotImplementedException (); }\r
+               public bool CompletedSynchronously \r
+               {\r
+                       get { return _completedSynchronously; }\r
                }\r
 \r
-               public bool IsCompleted {\r
-                       [MonoTODO]\r
-                       get { throw new NotImplementedException (); }\r
+               public bool IsCompleted \r
+               {\r
+                       get { lock (this) { return _done; } }\r
                }\r
 \r
                #endregion // Properties\r
@@ -63,9 +95,31 @@ namespace System.Web.Services.Protocols {
 \r
                public void Abort ()\r
                {\r
-                       request.Abort ();\r
+                       Request.Abort ();\r
+               }\r
+\r
+               internal void SetCompleted (object result, Exception exception, bool async)\r
+               {\r
+                       lock (this)\r
+                       {\r
+                               Exception = exception;\r
+                               Result = result;\r
+                               _done = true;\r
+                               _completedSynchronously = async;\r
+                               if (_waitHandle != null) _waitHandle.Set ();\r
+                               Monitor.PulseAll (this);\r
+                       }\r
+                       if (_callback != null) _callback (this);\r
+               }\r
+\r
+               internal void WaitForComplete ()\r
+               {\r
+                       lock (this)\r
+                       {\r
+                               Monitor.Wait (this);\r
+                       }\r
                }\r
 \r
                #endregion // Methods\r
        }\r
-}\r
+}