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;
33 public WebAsyncResult (AsyncCallback cb, object state)
39 public WebAsyncResult (HttpWebRequest request, AsyncCallback cb, object state)
41 this.request = request;
46 public WebAsyncResult (AsyncCallback cb, object state, byte [] buffer, int offset, int size)
55 internal void SetCompleted (bool synch, Exception e)
60 ((ManualResetEvent) AsyncWaitHandle).Set ();
63 internal void Reset ()
78 internal void SetCompleted (bool synch, int nbytes)
84 ((ManualResetEvent) AsyncWaitHandle).Set ();
87 internal void SetCompleted (bool synch, Stream writeStream)
91 this.writeStream = writeStream;
93 ((ManualResetEvent) AsyncWaitHandle).Set ();
96 internal void SetCompleted (bool synch, HttpWebResponse response)
100 this.response = response;
102 ((ManualResetEvent) AsyncWaitHandle).Set ();
105 internal void DoCallback ()
107 if (!callbackDone && cb != null) {
113 internal void WaitUntilComplete ()
118 AsyncWaitHandle.WaitOne ();
121 internal bool WaitUntilComplete (int timeout, bool exitContext)
126 return AsyncWaitHandle.WaitOne (timeout, exitContext);
129 public object AsyncState {
130 get { return state; }
133 public WaitHandle AsyncWaitHandle {
135 if (handle == null) {
138 handle = new ManualResetEvent (isCompleted);
146 public bool CompletedSynchronously {
147 get { return synch; }
150 public bool IsCompleted {
151 get { return isCompleted; }
154 internal bool GotException {
155 get { return (exc != null); }
158 internal Exception Exception {
162 internal int NBytes {
163 get { return nbytes; }
164 set { nbytes = value; }
167 internal IAsyncResult InnerAsyncResult {
168 get { return innerAsyncResult; }
169 set { innerAsyncResult = value; }
172 internal Stream WriteStream {
173 get { return writeStream; }
176 internal HttpWebResponse Response {
177 get { return response; }
180 internal byte [] Buffer {
181 get { return buffer; }
184 internal int Offset {
185 get { return offset; }