Example #1
0
        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);
                ReceiveEx         = Marshal.GetDelegateForFunctionPointer <WinSock.RIOReceiveEx>(rio.RIOReceiveEx);
                Send   = Marshal.GetDelegateForFunctionPointer <WinSock.RIOSend>(rio.RIOSend);
                SendEx = Marshal.GetDelegateForFunctionPointer <WinSock.RIOSendEx>(rio.RIOSendEx);

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

                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();
        }