2 // System.Net.WebAsyncResult
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 using System.Threading;
15 class WebAsyncResult : IAsyncResult
17 ManualResetEvent handle;
23 IAsyncResult innerAsyncResult;
26 HttpWebRequest request;
27 HttpWebResponse response;
32 object locker = new object ();
34 public WebAsyncResult (AsyncCallback cb, object state)
40 public WebAsyncResult (HttpWebRequest request, AsyncCallback cb, object state)
42 this.request = request;
47 public WebAsyncResult (AsyncCallback cb, object state, byte [] buffer, int offset, int size)
56 internal void SetCompleted (bool synch, Exception e)
67 internal void Reset ()
82 internal void SetCompleted (bool synch, int nbytes)
94 internal void SetCompleted (bool synch, Stream writeStream)
97 this.writeStream = writeStream;
106 internal void SetCompleted (bool synch, HttpWebResponse response)
109 this.response = response;
118 internal void DoCallback ()
120 if (!callbackDone && cb != null) {
126 internal void WaitUntilComplete ()
131 AsyncWaitHandle.WaitOne ();
134 internal bool WaitUntilComplete (int timeout, bool exitContext)
139 return AsyncWaitHandle.WaitOne (timeout, exitContext);
142 public object AsyncState {
143 get { return state; }
146 public WaitHandle AsyncWaitHandle {
150 handle = new ManualResetEvent (isCompleted);
157 public bool CompletedSynchronously {
158 get { return synch; }
161 public bool IsCompleted {
169 internal bool GotException {
170 get { return (exc != null); }
173 internal Exception Exception {
177 internal int NBytes {
178 get { return nbytes; }
179 set { nbytes = value; }
182 internal IAsyncResult InnerAsyncResult {
183 get { return innerAsyncResult; }
184 set { innerAsyncResult = value; }
187 internal Stream WriteStream {
188 get { return writeStream; }
191 internal HttpWebResponse Response {
192 get { return response; }
195 internal byte [] Buffer {
196 get { return buffer; }
199 internal int Offset {
200 get { return offset; }