Overlapped.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.Runtime.InteropServices;
  34. using System.Security.Permissions;
  35. namespace System.Threading
  36. {
  37. public class Overlapped
  38. {
  39. IAsyncResult ares;
  40. int offsetL;
  41. int offsetH;
  42. int evt;
  43. public Overlapped ()
  44. {
  45. }
  46. public Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar)
  47. {
  48. offsetL = offsetLo;
  49. offsetH = offsetHi;
  50. evt = hEvent;
  51. ares = ar;
  52. }
  53. [CLSCompliant(false)]
  54. unsafe public static void Free (NativeOverlapped *nativeOverlappedPtr)
  55. {
  56. if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
  57. throw new ArgumentNullException ("nativeOverlappedPtr");
  58. Marshal.FreeHGlobal ((IntPtr) nativeOverlappedPtr);
  59. }
  60. [CLSCompliant(false)]
  61. unsafe public static Overlapped Unpack (NativeOverlapped *nativeOverlappedPtr)
  62. {
  63. if ((IntPtr) nativeOverlappedPtr == IntPtr.Zero)
  64. throw new ArgumentNullException ("nativeOverlappedPtr");
  65. Overlapped result = new Overlapped ();
  66. result.offsetL = nativeOverlappedPtr->OffsetLow;
  67. result.offsetH = nativeOverlappedPtr->OffsetHigh;
  68. result.evt = nativeOverlappedPtr->EventHandle;
  69. return result;
  70. }
  71. [CLSCompliant(false)]
  72. [MonoTODO ("Security - we need to propagate the call stack")]
  73. unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb)
  74. {
  75. NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped)));
  76. result->OffsetLow = offsetL;
  77. result->OffsetHigh = offsetH;
  78. result->EventHandle = evt;
  79. return result;
  80. }
  81. [CLSCompliant(false)]
  82. [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
  83. unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb)
  84. {
  85. // no need to propagate the call stack in the unsafe version
  86. return Pack (iocb);
  87. }
  88. public IAsyncResult AsyncResult {
  89. get { return ares; }
  90. set { ares = value; }
  91. }
  92. public int EventHandle {
  93. get { return evt; }
  94. set { evt = value; }
  95. }
  96. public int OffsetHigh {
  97. get { return offsetH; }
  98. set { offsetH = value; }
  99. }
  100. public int OffsetLow {
  101. get { return offsetL; }
  102. set { offsetL = value; }
  103. }
  104. }
  105. }