Overlapped.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // System.Threading.Overlapped.cs
  3. //
  4. // Authors:
  5. // Dick Porter ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected]);
  7. //
  8. // (C) Ximian, Inc. http://www.ximian.com
  9. // (C) 2004 Novell, Inc. (http://www.novell.com)
  10. //
  11. using System.Runtime.InteropServices;
  12. namespace System.Threading
  13. {
  14. public class Overlapped
  15. {
  16. IAsyncResult ares;
  17. int offsetL;
  18. int offsetH;
  19. int evt;
  20. public Overlapped ()
  21. {
  22. }
  23. public Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar)
  24. {
  25. offsetL = offsetLo;
  26. offsetH = offsetHi;
  27. evt = hEvent;
  28. ares = ar;
  29. }
  30. [CLSCompliant(false)]
  31. unsafe public static void Free (NativeOverlapped *nativeOverlappedPtr)
  32. {
  33. if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
  34. throw new ArgumentNullException ("nativeOverlappedPtr");
  35. Marshal.FreeHGlobal ((IntPtr) nativeOverlappedPtr);
  36. }
  37. [CLSCompliant(false)]
  38. unsafe public static Overlapped Unpack (NativeOverlapped *nativeOverlappedPtr)
  39. {
  40. if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
  41. throw new ArgumentNullException ("nativeOverlappedPtr");
  42. Overlapped result = new Overlapped ();
  43. result.offsetL = nativeOverlappedPtr->OffsetLow;
  44. result.offsetH = nativeOverlappedPtr->OffsetHigh;
  45. result.evt = nativeOverlappedPtr->EventHandle;
  46. return result;
  47. }
  48. [CLSCompliant(false)]
  49. unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb)
  50. {
  51. NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped)));
  52. result->OffsetLow = offsetL;
  53. result->OffsetHigh = offsetH;
  54. result->EventHandle = evt;
  55. return result;
  56. }
  57. [CLSCompliant(false)]
  58. unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb)
  59. {
  60. return Pack (iocb);
  61. }
  62. public IAsyncResult AsyncResult {
  63. get { return ares; }
  64. set { ares = value; }
  65. }
  66. public int EventHandle {
  67. get { return evt; }
  68. set { evt = value; }
  69. }
  70. public int OffsetHigh {
  71. get { return offsetH; }
  72. set { offsetH = value; }
  73. }
  74. public int OffsetLow {
  75. get { return offsetL; }
  76. set { offsetL = value; }
  77. }
  78. }
  79. }