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 ()
76 internal void SetCompleted (bool synch, int nbytes)
82 ((ManualResetEvent) AsyncWaitHandle).Set ();
85 internal void SetCompleted (bool synch, Stream writeStream)
89 this.writeStream = writeStream;
91 ((ManualResetEvent) AsyncWaitHandle).Set ();
94 internal void SetCompleted (bool synch, HttpWebResponse response)
98 this.response = response;
100 ((ManualResetEvent) AsyncWaitHandle).Set ();
103 internal void DoCallback ()
105 if (!callbackDone && cb != null) {
111 internal void WaitUntilComplete ()
116 AsyncWaitHandle.WaitOne ();
119 internal bool WaitUntilComplete (int timeout, bool exitContext)
124 return AsyncWaitHandle.WaitOne (timeout, exitContext);
127 public object AsyncState {
128 get { return state; }
131 public WaitHandle AsyncWaitHandle {
133 if (handle == null) {
136 handle = new ManualResetEvent (isCompleted);
144 public bool CompletedSynchronously {
145 get { return synch; }
148 public bool IsCompleted {
149 get { return isCompleted; }
152 internal bool GotException {
153 get { return (exc != null); }
156 internal Exception Exception {
160 internal int NBytes {
161 get { return nbytes; }
162 set { nbytes = value; }
165 internal IAsyncResult InnerAsyncResult {
166 get { return innerAsyncResult; }
167 set { innerAsyncResult = value; }
170 internal Stream WriteStream {
171 get { return writeStream; }
174 internal HttpWebResponse Response {
175 get { return response; }
178 internal byte [] Buffer {
179 get { return buffer; }
182 internal int Offset {
183 get { return offset; }