lalala
[mono.git] / mcs / class / corlib / System.IO / StreamAsyncResult.cs
1 //
2 // System.IO/StreamAsyncResult.cs
3 //
4 // Authors:
5 //   Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) 2004 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System.Threading;
11
12 namespace System.IO
13 {
14         class StreamAsyncResult : IAsyncResult {
15                 object state;
16                 bool completed;
17                 bool done;
18                 Exception exc;
19                 int nbytes = -1;
20                 ManualResetEvent wh;
21
22                 public StreamAsyncResult (object state)
23                 {
24                         this.state = state;
25                 }
26
27                 public void SetComplete (Exception e)
28                 {
29                         exc = e;
30                         completed = true;
31                         lock (this) {
32                                 if (wh != null)
33                                         wh.Set ();
34                         }
35                 }
36                 
37                 public void SetComplete (Exception e, int nbytes)
38                 {
39                         this.nbytes = nbytes;
40                         SetComplete (e);
41                 }
42
43                 public object AsyncState {
44                         get { return state; }
45                 }
46
47                 public WaitHandle AsyncWaitHandle {
48                         get {
49                                 lock (this) {
50                                         if (wh == null)
51                                                 wh = new ManualResetEvent (completed);
52
53                                         return wh;
54                                 }
55                         }
56                 }
57
58                 public virtual bool CompletedSynchronously {
59                         get { return true; }
60                 }
61
62                 public bool IsCompleted {
63                         get { return completed; }
64                 }
65
66                 public Exception Exception {
67                         get { return exc; }
68                 }
69
70                 public int NBytes {
71                         get { return nbytes; }
72                 }
73
74                 public bool Done {
75                         get { return done; }
76                         set { done = value; }
77                 }
78         }
79 }
80