2 // System.Threading.Overlapped.cs
5 // Dick Porter (dick@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com);
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2004 Novell, Inc. (http://www.novell.com)
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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.
35 using System.Runtime.InteropServices;
36 using System.Security.Permissions;
38 namespace System.Threading
41 public class Overlapped
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)
62 public Overlapped (int offsetLo, int offsetHi, IntPtr hEvent,
72 unsafe public static void Free (NativeOverlapped *nativeOverlappedPtr)
74 if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
75 throw new ArgumentNullException ("nativeOverlappedPtr");
77 Marshal.FreeHGlobal ((IntPtr) nativeOverlappedPtr);
81 unsafe public static Overlapped Unpack (NativeOverlapped *nativeOverlappedPtr)
83 if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
84 throw new ArgumentNullException ("nativeOverlappedPtr");
86 Overlapped result = new Overlapped ();
87 result.offsetL = nativeOverlappedPtr->OffsetLow;
88 result.offsetH = nativeOverlappedPtr->OffsetHigh;
89 result.evt = (int)nativeOverlappedPtr->EventHandle;
94 [Obsolete ("Use Pack(iocb, userData) instead")]
95 [MonoTODO ("Security - we need to propagate the call stack")]
96 unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb)
98 NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped)));
99 result->OffsetLow = offsetL;
100 result->OffsetHigh = offsetH;
101 result->EventHandle = (IntPtr)evt;
105 [CLSCompliant (false)]
107 [MonoTODO ("handle userData")]
108 unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb, object userData)
110 NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf(typeof(NativeOverlapped)));
111 result->OffsetLow = offsetL;
112 result->OffsetHigh = offsetH;
113 result->EventHandle = evt_ptr;
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)
122 // no need to propagate the call stack in the unsafe version
127 [CLSCompliant (false)]
128 unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb, object userData)
130 return Pack (iocb, userData);
133 public IAsyncResult AsyncResult {
135 set { ares = value; }
138 [Obsolete ("Not 64bit compatible. Use EventHandleIntPtr instead.")]
139 public int EventHandle {
145 public IntPtr EventHandleIntPtr
155 public int OffsetHigh {
156 get { return offsetH; }
157 set { offsetH = value; }
160 public int OffsetLow {
161 get { return offsetL; }
162 set { offsetL = value; }