internal static extern int WSAIoctl([In] IntPtr socket, [In] uint dwIoControlCode, [In] ref Guid lpvInBuffer, [In] uint cbInBuffer, [In, Out] ref RIO_EXTENSION_FUNCTION_TABLE lpvOutBuffer, [In] int cbOutBuffer, [Out] out uint lpcbBytesReturned, [In] IntPtr lpOverlapped, [In] IntPtr lpCompletionRoutine);
private static void Initialize() { var version = new Version(2, 2); WSAData data; var result = WSAStartup((short)version.Raw, out data); if (result != 0 && CaptureInitializationWsaError()) { return; } var tempSocket = WSASocket(AddressFamilies.AF_INET, SocketType.SOCK_STREAM, Protocol.IPPROTO_TCP, IntPtr.Zero, 0, SocketFlags.WSA_FLAG_REGISTERED_IO | SocketFlags.WSA_FLAG_OVERLAPPED); if (CaptureInitializationWsaError()) { return; } uint dwBytes; var acceptExId = new Guid("B5367DF1-CBAC-11CF-95CA-00805F48A192"); var acceptExptr = IntPtr.Zero; var acceptExIoctlResult = WSAIoctl2(tempSocket, Consts.SIO_GET_EXTENSION_FUNCTION_POINTER, ref acceptExId, 16, ref acceptExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (acceptExIoctlResult != 0 && CaptureInitializationWsaError()) { return; } Extensions.AcceptEx = Marshal.GetDelegateForFunctionPointer <Extensions.AcceptExFunc>(acceptExptr); var connectExId = new Guid("25A207B9-DDF3-4660-8EE9-76E58C74063E"); var connectExptr = IntPtr.Zero; var connectExIoctlResult = WSAIoctl2(tempSocket, Consts.SIO_GET_EXTENSION_FUNCTION_POINTER, ref connectExId, 16, ref connectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (connectExIoctlResult != 0 && CaptureInitializationWsaError()) { return; } Extensions.ConnectEx = Marshal.GetDelegateForFunctionPointer <Extensions.ConnectExFunc>(connectExptr); var disconnectExId = new Guid("7FDA2E11-8630-436F-A031-F536A6EEC157"); var disconnectExptr = IntPtr.Zero; var disconnectIoctlResult = WSAIoctl2(tempSocket, Consts.SIO_GET_EXTENSION_FUNCTION_POINTER, ref disconnectExId, 16, ref disconnectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (disconnectIoctlResult != 0 && CaptureInitializationWsaError()) { return; } Extensions.DisconnectEx = Marshal.GetDelegateForFunctionPointer <Extensions.DisconnectExFunc>(disconnectExptr); var rio = new RIO_EXTENSION_FUNCTION_TABLE(); var rioFunctionsTableId = new Guid("8509e081-96dd-4005-b165-9e2ee8c79e3f"); var rioIoctlResult = WSAIoctl(tempSocket, Consts.SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, ref rioFunctionsTableId, 16, ref rio, sizeof(RIO_EXTENSION_FUNCTION_TABLE), out dwBytes, IntPtr.Zero, IntPtr.Zero); if (rioIoctlResult != 0 && CaptureInitializationWsaError()) { return; } Extensions.RegisterBuffer = Marshal.GetDelegateForFunctionPointer <Extensions.RIORegisterBufferFunc>(rio.RIORegisterBuffer); Extensions.CreateCompletionQueue = Marshal.GetDelegateForFunctionPointer <Extensions.RIOCreateCompletionQueueFunc>(rio.RIOCreateCompletionQueue); Extensions.CreateRequestQueue = Marshal.GetDelegateForFunctionPointer <Extensions.RIOCreateRequestQueueFunc>(rio.RIOCreateRequestQueue); Extensions.Notify = Marshal.GetDelegateForFunctionPointer <Extensions.RIONotifyFunc>(rio.RIONotify); Extensions.DequeueCompletion = Marshal.GetDelegateForFunctionPointer <Extensions.RIODequeueCompletionFunc>(rio.RIODequeueCompletion); Extensions.Receive = Marshal.GetDelegateForFunctionPointer <Extensions.RIOReceiveFunc>(rio.RIOReceive); Extensions.Send = Marshal.GetDelegateForFunctionPointer <Extensions.RIOSendFunc>(rio.RIOSend); Extensions.CloseCompletionQueue = Marshal.GetDelegateForFunctionPointer <Extensions.RIOCloseCompletionQueueAction>(rio.RIOCloseCompletionQueue); Extensions.DeregisterBuffer = Marshal.GetDelegateForFunctionPointer <Extensions.RIODeregisterBufferAction>(rio.RIODeregisterBuffer); Extensions.ResizeCompletionQueue = Marshal.GetDelegateForFunctionPointer <Extensions.RIOResizeCompletionQueueFunc>(rio.RIOResizeCompletionQueue); Extensions.ResizeRequestQueue = Marshal.GetDelegateForFunctionPointer <Extensions.RIOResizeRequestQueueFunc>(rio.RIOResizeRequestQueue); closesocket(tempSocket); CaptureInitializationWsaError(); }