WSASocket() private method

private WSASocket ( [ af, [ type, [ protocol, [ lpProtocolInfo, [ group, [ dwFlags ) : IntPtr
af [
type [
protocol [
lpProtocolInfo [
group [
dwFlags [
return System.IntPtr
Exemplo n.º 1
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
                           uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
                           ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
            {
                WinSock.ThrowLastWSAError();
            }

            SendBufferPool    = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;

            _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive, 1, maxOutstandingSend, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
            WinSock.ThrowLastWSAError();

            onIncommingSegmentWrapper = (socket, segment) =>
            {
                onIncommingSegmentSafe(segment);
                if (segment.CurrentContentLength > 0)
                {
                    socket.BeginReceive();
                }
                else
                {
                    socket.Dispose();
                }
                segment.Dispose();
            };
        }
Exemplo n.º 2
0
        public unsafe RioTcpListener(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, uint socketCount, uint maxOutstandingReceive = 2048, uint maxOutstandingSend = 2048)
            : base(sendPool, revicePool, socketCount, ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_STREAM, PROTOCOL.IPPROTO_TCP, maxOutstandingReceive, maxOutstandingSend)
        {
            if ((_listenerSocket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
            {
                WinSock.ThrowLastWSAError();
            }

            int  True    = 1;
            uint dwBytes = 0;

            if (WinSock.WSAIoctlGeneral2(_listenerSocket, WinSock.SIO_LOOPBACK_FAST_PATH, &True, sizeof(int), (void *)0, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero) != 0)
            {
                WinSock.ThrowLastWSAError();
            }
            if (WinSock.setsockopt(_listenerSocket, WinSock.IPPROTO_TCP, WinSock.TCP_NODELAY, &True, 4) != 0)
            {
                WinSock.ThrowLastWSAError();
            }

            if ((_listenIocp = Kernel32.CreateIoCompletionPort(_listenerSocket, _listenIocp, 0, 1)) == IntPtr.Zero)
            {
                Kernel32.ThrowLastError();
            }

            Thread AcceptIocpThread = new Thread(AcceptIocpComplete);

            AcceptIocpThread.IsBackground = true;
            AcceptIocpThread.Start();
        }
Exemplo n.º 3
0
        internal void ResetSocket()
        {
            //Debug.Assert(!inUse);
            if (Socket != IntPtr.Zero)
            {
                WinSock.closesocket(Socket);
            }

            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
            {
                WinSock.ThrowLastWSAError();
            }
            var error = 0;

            do
            {
                _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive / 2, 1, maxOutstandingSend / 2, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
                error         = WinSock.WSAGetLastError();
            } while (error == 10055);

            if (error != 0 && error != Kernel32.ERROR_IO_PENDING)
            {
                throw new Win32Exception(error);
            }
        }
Exemplo n.º 4
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
                           uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
                           ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
            {
                WinSock.ThrowLastWSAError();
            }

            SendBufferPool    = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;

            _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive, 1, maxOutstandingSend, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
            WinSock.ThrowLastWSAError();
        }
Exemplo n.º 5
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();
        }