2 // System.Net.WebAsyncResult
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Threading;
36 class WebAsyncResult : IAsyncResult
38 ManualResetEvent handle;
44 IAsyncResult innerAsyncResult;
47 HttpWebResponse response;
52 object locker = new object ();
53 public bool EndCalled;
55 public WebAsyncResult (AsyncCallback cb, object state)
61 public WebAsyncResult (HttpWebRequest request, AsyncCallback cb, object state)
67 public WebAsyncResult (AsyncCallback cb, object state, byte [] buffer, int offset, int size)
76 internal void SetCompleted (bool synch, Exception e)
87 internal void Reset ()
101 internal void SetCompleted (bool synch, int nbytes)
104 this.nbytes = nbytes;
113 internal void SetCompleted (bool synch, Stream writeStream)
116 this.writeStream = writeStream;
125 internal void SetCompleted (bool synch, HttpWebResponse response)
128 this.response = response;
137 internal void DoCallback ()
139 if (!callbackDone && cb != null) {
145 internal void WaitUntilComplete ()
150 AsyncWaitHandle.WaitOne ();
153 internal bool WaitUntilComplete (int timeout, bool exitContext)
158 return AsyncWaitHandle.WaitOne (timeout, exitContext);
161 public object AsyncState {
162 get { return state; }
165 public WaitHandle AsyncWaitHandle {
169 handle = new ManualResetEvent (isCompleted);
176 public bool CompletedSynchronously {
177 get { return synch; }
180 public bool IsCompleted {
188 internal bool GotException {
189 get { return (exc != null); }
192 internal Exception Exception {
196 internal int NBytes {
197 get { return nbytes; }
198 set { nbytes = value; }
201 internal IAsyncResult InnerAsyncResult {
202 get { return innerAsyncResult; }
203 set { innerAsyncResult = value; }
206 internal Stream WriteStream {
207 get { return writeStream; }
210 internal HttpWebResponse Response {
211 get { return response; }
214 internal byte [] Buffer {
215 get { return buffer; }
218 internal int Offset {
219 get { return offset; }