internal unsafe static RIO Initalize(IntPtr socket) { uint dwBytes = 0; RIO_EXTENSION_FUNCTION_TABLE rio = new RIO_EXTENSION_FUNCTION_TABLE(); Guid RioFunctionsTableId = new Guid("8509e081-96dd-4005-b165-9e2ee8c79e3f"); int True = -1; var result = setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *)&True, 4); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: setsockopt TCP_NODELAY returned {0}", error)); } result = WSAIoctlGeneral(socket, SIO_LOOPBACK_FAST_PATH, &True, 4, null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: WSAIoctl SIO_LOOPBACK_FAST_PATH returned {0}", error)); } result = WSAIoctl(socket, SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, ref RioFunctionsTableId, 16, ref rio, sizeof(RIO_EXTENSION_FUNCTION_TABLE), out dwBytes, IntPtr.Zero, IntPtr.Zero); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: RIOInitalize returned {0}", error)); } else { RIO rioFunctions = new RIO { RegisterBuffer = Marshal.GetDelegateForFunctionPointer <RIORegisterBuffer>(rio.RIORegisterBuffer), CreateCompletionQueue = Marshal.GetDelegateForFunctionPointer <RIOCreateCompletionQueue>(rio.RIOCreateCompletionQueue), CreateRequestQueue = Marshal.GetDelegateForFunctionPointer <RIOCreateRequestQueue>(rio.RIOCreateRequestQueue), Notify = Marshal.GetDelegateForFunctionPointer <RIONotify>(rio.RIONotify), DequeueCompletion = Marshal.GetDelegateForFunctionPointer <RIODequeueCompletion>(rio.RIODequeueCompletion), Receive = Marshal.GetDelegateForFunctionPointer <RIOReceive>(rio.RIOReceive), Send = Marshal.GetDelegateForFunctionPointer <RIOSend>(rio.RIOSend), CloseCompletionQueue = Marshal.GetDelegateForFunctionPointer <RIOCloseCompletionQueue>(rio.RIOCloseCompletionQueue), DeregisterBuffer = Marshal.GetDelegateForFunctionPointer <RIODeregisterBuffer>(rio.RIODeregisterBuffer), ResizeCompletionQueue = Marshal.GetDelegateForFunctionPointer <RIOResizeCompletionQueue>(rio.RIOResizeCompletionQueue), ResizeRequestQueue = Marshal.GetDelegateForFunctionPointer <RIOResizeRequestQueue>(rio.RIOResizeRequestQueue) }; return(rioFunctions); } }
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 );
internal unsafe static void Initalize() { IntPtr tempSocket; tempSocket = WinSock.WSASocket(ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_STREAM, PROTOCOL.IPPROTO_TCP, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED); WinSock.ThrowLastWSAError(); uint dwBytes = 0; Guid AcceptExId = new Guid("B5367DF1-CBAC-11CF-95CA-00805F48A192"); var acceptExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref AcceptExId, 16, ref acceptExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { AcceptEx = Marshal.GetDelegateForFunctionPointer <WinSock.AcceptEx>(acceptExptr); } Guid ConnectExId = new Guid("25A207B9-DDF3-4660-8EE9-76E58C74063E"); var ConnectExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref ConnectExId, 16, ref ConnectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { ConnectEx = Marshal.GetDelegateForFunctionPointer <WinSock.ConnectEx>(ConnectExptr); } Guid DisconnectExId = new Guid("7FDA2E11-8630-436F-A031-F536A6EEC157"); var DisconnectExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref DisconnectExId, 16, ref DisconnectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { DisconnectEx = Marshal.GetDelegateForFunctionPointer <WinSock.DisconnectEx>(DisconnectExptr); } var rio = new RIO_EXTENSION_FUNCTION_TABLE(); Guid RioFunctionsTableId = new Guid("8509e081-96dd-4005-b165-9e2ee8c79e3f"); if (WinSock.WSAIoctl(tempSocket, WinSock.SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, ref RioFunctionsTableId, 16, ref rio, sizeof(RIO_EXTENSION_FUNCTION_TABLE), out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { RegisterBuffer = Marshal.GetDelegateForFunctionPointer <WinSock.RIORegisterBuffer>(rio.RIORegisterBuffer); CreateCompletionQueue = Marshal.GetDelegateForFunctionPointer <WinSock.RIOCreateCompletionQueue>(rio.RIOCreateCompletionQueue); CreateRequestQueue = Marshal.GetDelegateForFunctionPointer <WinSock.RIOCreateRequestQueue>(rio.RIOCreateRequestQueue); Notify = Marshal.GetDelegateForFunctionPointer <WinSock.RIONotify>(rio.RIONotify); DequeueCompletion = Marshal.GetDelegateForFunctionPointer <WinSock.RIODequeueCompletion>(rio.RIODequeueCompletion); Receive = Marshal.GetDelegateForFunctionPointer <WinSock.RIOReceive>(rio.RIOReceive); Send = Marshal.GetDelegateForFunctionPointer <WinSock.RIOSend>(rio.RIOSend); CloseCompletionQueue = Marshal.GetDelegateForFunctionPointer <WinSock.RIOCloseCompletionQueue>(rio.RIOCloseCompletionQueue); DeregisterBuffer = Marshal.GetDelegateForFunctionPointer <WinSock.RIODeregisterBuffer>(rio.RIODeregisterBuffer); ResizeCompletionQueue = Marshal.GetDelegateForFunctionPointer <WinSock.RIOResizeCompletionQueue>(rio.RIOResizeCompletionQueue); ResizeRequestQueue = Marshal.GetDelegateForFunctionPointer <WinSock.RIOResizeRequestQueue>(rio.RIOResizeRequestQueue); } WinSock.closesocket(tempSocket); WinSock.ThrowLastWSAError(); }
internal unsafe static void Initalize() { IntPtr tempSocket; tempSocket = WinSock.WSASocket(ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_STREAM, PROTOCOL.IPPROTO_TCP, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED); WinSock.ThrowLastWSAError(); uint dwBytes = 0; Guid AcceptExId = new Guid("B5367DF1-CBAC-11CF-95CA-00805F48A192"); var acceptExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref AcceptExId, 16, ref acceptExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { AcceptEx = Marshal.GetDelegateForFunctionPointer<WinSock.AcceptEx>(acceptExptr); } Guid ConnectExId = new Guid("25A207B9-DDF3-4660-8EE9-76E58C74063E"); var ConnectExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref ConnectExId, 16, ref ConnectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { ConnectEx = Marshal.GetDelegateForFunctionPointer<WinSock.ConnectEx>(ConnectExptr); } Guid DisconnectExId = new Guid("7FDA2E11-8630-436F-A031-F536A6EEC157"); var DisconnectExptr = IntPtr.Zero; if (WinSock.WSAIoctl2(tempSocket, WinSock.SIO_GET_EXTENSION_FUNCTION_POINTER, ref DisconnectExId, 16, ref DisconnectExptr, IntPtr.Size, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { DisconnectEx = Marshal.GetDelegateForFunctionPointer<WinSock.DisconnectEx>(DisconnectExptr); } var rio = new RIO_EXTENSION_FUNCTION_TABLE(); Guid RioFunctionsTableId = new Guid("8509e081-96dd-4005-b165-9e2ee8c79e3f"); if (WinSock.WSAIoctl(tempSocket, WinSock.SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, ref RioFunctionsTableId, 16, ref rio, sizeof(RIO_EXTENSION_FUNCTION_TABLE), out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0) { WinSock.ThrowLastWSAError(); } else { RegisterBuffer = Marshal.GetDelegateForFunctionPointer<WinSock.RIORegisterBuffer>(rio.RIORegisterBuffer); CreateCompletionQueue = Marshal.GetDelegateForFunctionPointer<WinSock.RIOCreateCompletionQueue>(rio.RIOCreateCompletionQueue); CreateRequestQueue = Marshal.GetDelegateForFunctionPointer<WinSock.RIOCreateRequestQueue>(rio.RIOCreateRequestQueue); Notify = Marshal.GetDelegateForFunctionPointer<WinSock.RIONotify>(rio.RIONotify); DequeueCompletion = Marshal.GetDelegateForFunctionPointer<WinSock.RIODequeueCompletion>(rio.RIODequeueCompletion); Receive = Marshal.GetDelegateForFunctionPointer<WinSock.RIOReceive>(rio.RIOReceive); Send = Marshal.GetDelegateForFunctionPointer<WinSock.RIOSend>(rio.RIOSend); CloseCompletionQueue = Marshal.GetDelegateForFunctionPointer<WinSock.RIOCloseCompletionQueue>(rio.RIOCloseCompletionQueue); DeregisterBuffer = Marshal.GetDelegateForFunctionPointer<WinSock.RIODeregisterBuffer>(rio.RIODeregisterBuffer); ResizeCompletionQueue = Marshal.GetDelegateForFunctionPointer<WinSock.RIOResizeCompletionQueue>(rio.RIOResizeCompletionQueue); ResizeRequestQueue = Marshal.GetDelegateForFunctionPointer<WinSock.RIOResizeRequestQueue>(rio.RIOResizeRequestQueue); } WinSock.closesocket(tempSocket); WinSock.ThrowLastWSAError(); }
internal unsafe static RIO Initalize(IntPtr socket) { uint dwBytes = 0; RIO_EXTENSION_FUNCTION_TABLE rio = new RIO_EXTENSION_FUNCTION_TABLE(); Guid RioFunctionsTableId = new Guid("8509e081-96dd-4005-b165-9e2ee8c79e3f"); int True = -1; var result = setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char*)&True, 4); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: setsockopt TCP_NODELAY returned {0}", error)); } result = WSAIoctlGeneral(socket, SIO_LOOPBACK_FAST_PATH, &True, 4, null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: WSAIoctl SIO_LOOPBACK_FAST_PATH returned {0}", error)); } result = WSAIoctl(socket, SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, ref RioFunctionsTableId, 16, ref rio, sizeof(RIO_EXTENSION_FUNCTION_TABLE), out dwBytes, IntPtr.Zero, IntPtr.Zero); if (result != 0) { var error = WinSock.WSAGetLastError(); WinSock.WSACleanup(); throw new Exception(String.Format("ERROR: RIOInitalize returned {0}", error)); } else { RIO rioFunctions = new RIO { RegisterBuffer = Marshal.GetDelegateForFunctionPointer<RIORegisterBuffer>(rio.RIORegisterBuffer), CreateCompletionQueue = Marshal.GetDelegateForFunctionPointer<RIOCreateCompletionQueue>(rio.RIOCreateCompletionQueue), CreateRequestQueue = Marshal.GetDelegateForFunctionPointer<RIOCreateRequestQueue>(rio.RIOCreateRequestQueue), Notify = Marshal.GetDelegateForFunctionPointer<RIONotify>(rio.RIONotify), DequeueCompletion = Marshal.GetDelegateForFunctionPointer<RIODequeueCompletion>(rio.RIODequeueCompletion), Receive = Marshal.GetDelegateForFunctionPointer<RIOReceive>(rio.RIOReceive), Send = Marshal.GetDelegateForFunctionPointer<RIOSend>(rio.RIOSend), CloseCompletionQueue = Marshal.GetDelegateForFunctionPointer<RIOCloseCompletionQueue>(rio.RIOCloseCompletionQueue), DeregisterBuffer = Marshal.GetDelegateForFunctionPointer<RIODeregisterBuffer>(rio.RIODeregisterBuffer), ResizeCompletionQueue = Marshal.GetDelegateForFunctionPointer<RIOResizeCompletionQueue>(rio.RIOResizeCompletionQueue), ResizeRequestQueue = Marshal.GetDelegateForFunctionPointer<RIOResizeRequestQueue>(rio.RIOResizeRequestQueue) }; return rioFunctions; } }