Merge pull request #1529 from alistair/xmlreader_read_to_next_sibling_bug
[mono.git] / mcs / class / corlib / System.Threading / Overlapped.cs
1 //
2 // System.Threading.Overlapped.cs
3 //
4 // Authors:
5 //      Dick Porter (dick@ximian.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com);
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // (C) 2004 Novell, Inc. (http://www.novell.com)
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System.Runtime.InteropServices;
36 using System.Security.Permissions;
37
38 namespace System.Threading
39 {
40         [ComVisible (true)]
41         public class Overlapped
42         {
43                 IAsyncResult ares;
44                 int offsetL;
45                 int offsetH;
46                 int evt;
47                 IntPtr evt_ptr;
48
49                 public Overlapped ()
50                 {
51                 }
52
53                 [Obsolete ("Not 64bit compatible.  Please use the constructor that takes IntPtr for the event handle")]
54                 public Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar)
55                 {
56                         offsetL = offsetLo;
57                         offsetH = offsetHi;
58                         evt = hEvent;
59                         ares = ar;
60                 }
61
62                 public Overlapped (int offsetLo, int offsetHi, IntPtr hEvent,
63                                    IAsyncResult ar)
64                 {
65                         offsetL = offsetLo;
66                         offsetH = offsetHi;
67                         evt_ptr = hEvent;
68                         ares = ar;
69                 }
70
71                 [CLSCompliant(false)]
72                 unsafe public static void Free (NativeOverlapped *nativeOverlappedPtr)
73                 {
74                         if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
75                                 throw new ArgumentNullException ("nativeOverlappedPtr");
76
77                         Marshal.FreeHGlobal ((IntPtr) nativeOverlappedPtr);
78                 }
79
80                 [CLSCompliant(false)]
81                 unsafe public static Overlapped Unpack (NativeOverlapped *nativeOverlappedPtr)
82                 {
83                         if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
84                                 throw new ArgumentNullException ("nativeOverlappedPtr");
85
86                         Overlapped result = new Overlapped ();
87                         result.offsetL = nativeOverlappedPtr->OffsetLow;
88                         result.offsetH = nativeOverlappedPtr->OffsetHigh;
89                         result.evt = (int)nativeOverlappedPtr->EventHandle;
90                         return result;
91                 }
92
93                 [CLSCompliant(false)]
94                 [Obsolete ("Use Pack(iocb, userData) instead")]
95                 [MonoTODO ("Security - we need to propagate the call stack")]
96                 unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb)
97                 {
98                         NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped)));
99                         result->OffsetLow = offsetL;
100                         result->OffsetHigh = offsetH;
101                         result->EventHandle = (IntPtr)evt;
102                         return result;
103                 }
104
105                 [CLSCompliant (false)]
106                 [ComVisible (false)]
107                 [MonoTODO ("handle userData")]
108                 unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb, object userData)
109                 {
110                         NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf(typeof(NativeOverlapped)));
111                         result->OffsetLow = offsetL;
112                         result->OffsetHigh = offsetH;
113                         result->EventHandle = evt_ptr;
114                         return(result);
115                 }
116                 
117                 [CLSCompliant(false)]
118                 [Obsolete ("Use UnsafePack(iocb, userData) instead")]
119                 [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
120                 unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb)
121                 {
122                         // no need to propagate the call stack in the unsafe version
123                         return Pack (iocb);
124                 }
125
126                 [ComVisible (false)]
127                 [CLSCompliant (false)]
128                 unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb, object userData)
129                 {
130                         return Pack (iocb, userData);
131                 }
132
133                 public IAsyncResult AsyncResult {
134                         get { return ares; }
135                         set { ares = value; }
136                 }
137
138                 [Obsolete ("Not 64bit compatible.  Use EventHandleIntPtr instead.")]
139                 public int EventHandle {
140                         get { return evt; }
141                         set { evt = value; }
142                 }
143
144                 [ComVisible (false)]
145                 public IntPtr EventHandleIntPtr 
146                 {
147                         get{
148                                 return(evt_ptr);
149                         }
150                         set{
151                                 evt_ptr = value;
152                         }
153                 }
154
155                 public int OffsetHigh {
156                         get { return offsetH; }
157                         set { offsetH = value; }
158                 }
159
160                 public int OffsetLow {
161                         get { return offsetL; }
162                         set { offsetL = value; }
163                 }
164         }
165 }
166