示例#1
0
        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 = 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 = 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 = 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),
                    ReceiveEx         = Marshal.GetDelegateForFunctionPointer <RIOReceiveEx>(rio.RIOReceiveEx),
                    Send   = Marshal.GetDelegateForFunctionPointer <RIOSend>(rio.RIOSend),
                    SendEx = Marshal.GetDelegateForFunctionPointer <RIOSendEx>(rio.RIOSendEx),
                    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);
            }
        }
示例#2
0
        internal static unsafe 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;
            }
        }