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;
54 public bool AsyncWriteAll;
56 public WebAsyncResult (AsyncCallback cb, object state)
62 public WebAsyncResult (HttpWebRequest request, AsyncCallback cb, object state)
68 public WebAsyncResult (AsyncCallback cb, object state, byte [] buffer, int offset, int size)
77 internal void SetCompleted (bool synch, Exception e)
88 internal void Reset ()
102 internal void SetCompleted (bool synch, int nbytes)
105 this.nbytes = nbytes;
114 internal void SetCompleted (bool synch, Stream writeStream)
117 this.writeStream = writeStream;
126 internal void SetCompleted (bool synch, HttpWebResponse response)
129 this.response = response;
138 internal void DoCallback ()
140 if (!callbackDone && cb != null) {
146 internal void WaitUntilComplete ()
151 AsyncWaitHandle.WaitOne ();
154 internal bool WaitUntilComplete (int timeout, bool exitContext)
159 return AsyncWaitHandle.WaitOne (timeout, exitContext);
162 public object AsyncState {
163 get { return state; }
166 public WaitHandle AsyncWaitHandle {
170 handle = new ManualResetEvent (isCompleted);
177 public bool CompletedSynchronously {
178 get { return synch; }
181 public bool IsCompleted {
189 internal bool GotException {
190 get { return (exc != null); }
193 internal Exception Exception {
197 internal int NBytes {
198 get { return nbytes; }
199 set { nbytes = value; }
202 internal IAsyncResult InnerAsyncResult {
203 get { return innerAsyncResult; }
204 set { innerAsyncResult = value; }
207 internal Stream WriteStream {
208 get { return writeStream; }
211 internal HttpWebResponse Response {
212 get { return response; }
215 internal byte [] Buffer {
216 get { return buffer; }
219 internal int Offset {
220 get { return offset; }