You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
6.2 KiB

4 years ago
  1. #if MYSQL_6_10
  2. // Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using System;
  24. using System.Runtime.InteropServices;
  25. using System.Threading;
  26. namespace Externals.MySql.Data.Common
  27. {
  28. internal class NativeMethods
  29. {
  30. // Keep the compiler from generating a default ctor
  31. private NativeMethods()
  32. {
  33. }
  34. //Constants for dwDesiredAccess:
  35. public const UInt32 GENERIC_READ = 0x80000000;
  36. public const UInt32 GENERIC_WRITE = 0x40000000;
  37. //Constants for return value:
  38. public const Int32 INVALIDpipeHandle_VALUE = -1;
  39. //Constants for dwFlagsAndAttributes:
  40. public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000;
  41. public const UInt32 FILE_FLAG_NO_BUFFERING = 0x20000000;
  42. //Constants for dwCreationDisposition:
  43. public const UInt32 OPEN_EXISTING = 3;
  44. [StructLayout(LayoutKind.Sequential)]
  45. internal class SecurityAttributes
  46. {
  47. public SecurityAttributes()
  48. {
  49. Length = Marshal.SizeOf<SecurityAttributes>();
  50. }
  51. public int Length;
  52. public IntPtr securityDescriptor = IntPtr.Zero;
  53. public bool inheritHandle;
  54. }
  55. [DllImport("Kernel32", CharSet = CharSet.Unicode)]
  56. static extern public IntPtr CreateFile(
  57. String fileName,
  58. uint desiredAccess,
  59. uint shareMode,
  60. SecurityAttributes securityAttributes,
  61. uint creationDisposition,
  62. uint flagsAndAttributes,
  63. uint templateFile);
  64. [return: MarshalAs(UnmanagedType.Bool)]
  65. [DllImport("kernel32.dll", EntryPoint = "PeekNamedPipe", SetLastError = true)]
  66. static extern public bool PeekNamedPipe(IntPtr handle,
  67. byte[] buffer,
  68. uint nBufferSize,
  69. ref uint bytesRead,
  70. ref uint bytesAvail,
  71. ref uint BytesLeftThisMessage);
  72. [return: MarshalAs(UnmanagedType.Bool)]
  73. [DllImport("kernel32.dll", SetLastError = true)]
  74. static extern public bool ReadFile(IntPtr hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead,
  75. out uint lpNumberOfBytesRead, IntPtr lpOverlapped);
  76. [return: MarshalAs(UnmanagedType.Bool)]
  77. [DllImport("Kernel32")]
  78. public static extern bool WriteFile(IntPtr hFile, [In] byte[] buffer,
  79. uint numberOfBytesToWrite, out uint numberOfBytesWritten, IntPtr lpOverlapped);
  80. [return: MarshalAs(UnmanagedType.Bool)]
  81. [DllImport("kernel32.dll", SetLastError = true)]
  82. public static extern bool CloseHandle(IntPtr handle);
  83. [return: MarshalAs(UnmanagedType.Bool)]
  84. [DllImport("kernel32.dll", SetLastError = true)]
  85. public static extern bool CancelIo(IntPtr handle);
  86. [return: MarshalAs(UnmanagedType.Bool)]
  87. [DllImport("kernel32.dll", SetLastError = true)]
  88. public static extern bool FlushFileBuffers(IntPtr handle);
  89. [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
  90. public static extern IntPtr OpenEvent(uint dwDesiredAccess,
  91. [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
  92. string lpName);
  93. [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
  94. public static extern IntPtr OpenFileMapping(uint dwDesiredAccess,
  95. [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
  96. string lpName);
  97. [DllImport("kernel32.dll")]
  98. public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
  99. dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
  100. IntPtr dwNumberOfBytesToMap);
  101. [DllImport("kernel32.dll")]
  102. [return: MarshalAs(UnmanagedType.Bool)]
  103. public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
  104. [DllImport("kernel32.dll", SetLastError = true)]
  105. public static extern int FlushViewOfFile(IntPtr address, uint numBytes);
  106. [DllImport("kernel32.dll", SetLastError = true)]
  107. public static extern bool WaitNamedPipe(string namedPipeName, uint timeOut);
  108. #region Winsock functions
  109. // SOcket routines
  110. [DllImport("ws2_32.dll", SetLastError = true)]
  111. static extern public IntPtr socket(int af, int type, int protocol);
  112. [DllImport("ws2_32.dll", SetLastError = true)]
  113. static extern public int ioctlsocket(IntPtr socket, uint cmd, ref UInt32 arg);
  114. [DllImport("ws2_32.dll", SetLastError = true)]
  115. public static extern int WSAIoctl(IntPtr s, uint dwIoControlCode, byte[] inBuffer, uint cbInBuffer,
  116. byte[] outBuffer, uint cbOutBuffer, IntPtr lpcbBytesReturned, IntPtr lpOverlapped,
  117. IntPtr lpCompletionRoutine);
  118. [DllImport("ws2_32.dll", SetLastError = true)]
  119. static extern public int WSAGetLastError();
  120. [DllImport("ws2_32.dll", SetLastError = true)]
  121. static extern public int connect(IntPtr socket, byte[] addr, int addrlen);
  122. [DllImport("ws2_32.dll", SetLastError = true)]
  123. static extern public int recv(IntPtr socket, byte[] buff, int len, int flags);
  124. [DllImport("ws2_32.Dll", SetLastError = true)]
  125. static extern public int send(IntPtr socket, byte[] buff, int len, int flags);
  126. #endregion
  127. }
  128. }
  129. #endif