⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udtsocket.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    int[] numArray8 = new int[0];
                    int[] numArray9 = new int[] { this.Handle };
                    Select(numArray7, numArray8, numArray9, timeOutMicroSeconds);
                    return (numArray9[0] == this.Handle);
                }
            }
            return false;
        }

        public int Receive(byte[] buffer, int length, SocketFlags socketFlags)
        {
            return this.Receive(buffer, 0, length, socketFlags);
        }

        public int Receive(byte[] buffer, int offset, int length, SocketFlags socketFlags)
        {
            try
            {
                if (this._socketType == SocketType.Dgram)
                {
                    return API_Recvmsg(this._handle, buffer, offset, length);
                }
                int num = API_Receive(this._handle, buffer, offset, length, (int) socketFlags);
                if (num < 0)
                {
                    return 0;
                }
                return num;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return 0;
            }
        }

        public static void Select(int[] readHandles, int[] writeHandles, int[] exceptionHandles, int timeOutMicroSeconds)
        {
            if (UDT_ERROR == API_UDTSelect(readHandles, readHandles.Length, writeHandles, writeHandles.Length, exceptionHandles, timeOutMicroSeconds))
            {
                throw new UDTSocketException();
            }
        }

        public int Send(byte[] buffer)
        {
            return this.Send(buffer, SocketFlags.None);
        }

        public int Send(byte[] buffer, SocketFlags socketFlags)
        {
            return this.Send(buffer, buffer.Length, socketFlags);
        }

        public int Send(byte[] buffer, int length, SocketFlags socketFlags)
        {
            if (this._socketType == SocketType.Dgram)
            {
                return API_Sendmsg(this._handle, buffer, length, -1, true);
            }
            return API_Send(this._handle, buffer, length, (int) socketFlags);
        }

        public int Send(byte[] buffer, int offset, int length, SocketFlags socketFlags)
        {
            if (offset < 1)
            {
                return this.Send(buffer, length, socketFlags);
            }
            byte[] destinationArray = new byte[buffer.Length - offset];
            Array.Copy(buffer, offset, destinationArray, 0, buffer.Length - offset);
            return this.Send(destinationArray, length, socketFlags);
        }

        public void SetSocketOption(SocketOptionLevel optionLevel, UDTSocketOptionName optionName, int optionValue)
        {
            this.SetSocketOption(optionLevel, optionName, optionValue);
        }

        public void SetSocketOption(SocketOptionLevel optionLevel, UDTSocketOptionName optionName, object optionValue)
        {
            int optlen = -1;
            if (optionValue is int)
            {
                optlen = 4;
            }
            else if (optionValue is long)
            {
                optlen = 8;
            }
            else
            {
                if (optionValue is LingerOption)
                {
                    return;
                }
                throw new NotImplementedException();
            }
            try
            {
                API_Setsockopt(this._handle, (int) optionLevel, optionName, ref optionValue, optlen);
            }
            catch (Exception exception)
            {
                Console.Write(exception.Message);
            }
        }

        public void Shutdown(SocketShutdown how)
        {
            API_Shutdown(this._handle, (int) how);
        }

        public static void ShutDownUDT()
        {
            if (_processor != null)
            {
                lock (_processor)
                {
                    if (_udtThreadProcessing != null)
                    {
                        _udtThreadProcessing.Abort();
                        _udtThreadProcessing = null;
                    }
                    if (_processor != null)
                    {
                        _processor.Stop();
                        _processor = null;
                    }
                }
            }
        }

        private static void UDTEndSendCallback(IntPtr pointer)
        {
            AsyncSendRegistration command = (AsyncSendRegistration) GCHandle.FromIntPtr(pointer).Target;
            _processor.AddCommand(command);
        }

        private static void UDTThreadProcessing()
        {
            try
            {
                while (Thread.CurrentThread.IsAlive)
                {
                    for (int i = _acceptRegistrations.get_Count() - 1; i > -1; i--)
                    {
                        Monitor.Enter(_acceptRegistrations);
                        AsyncAcceptRegistration command = _acceptRegistrations.get_Item(i);
                        Monitor.Exit(_acceptRegistrations);
                        if (command.Socket.IsOnAccept)
                        {
                            lock (_acceptRegistrations)
                            {
                                _acceptRegistrations.RemoveAt(i);
                            }
                            _processor.AddCommand(command);
                        }
                    }
                    for (int j = _receiveRegistrations.get_Count() - 1; j > -1; j--)
                    {
                        Monitor.Enter(_receiveRegistrations);
                        AsyncReceiveRegistration registration2 = _receiveRegistrations.get_Item(j);
                        Monitor.Exit(_receiveRegistrations);
                        if (!registration2.Socket.Connected || registration2.Socket.IsOnRead)
                        {
                            lock (_receiveRegistrations)
                            {
                                _receiveRegistrations.RemoveAt(j);
                            }
                            _processor.AddCommand(registration2);
                        }
                    }
                    API_WaitForEvent();
                }
            }
            catch (ThreadInterruptedException)
            {
            }
        }

        [Conditional("UDT_TRACE")]
        private static void UDTTrace(string message)
        {
            Console.WriteLine(message);
        }

        public bool Connected
        {
            get
            {
                if (this._handle < 0)
                {
                    return false;
                }
                return API_IsConnected(this._handle);
            }
        }

        public int Handle
        {
            get
            {
                return this._handle;
            }
        }

        private bool IsAsynchronous
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
            }
        }

        public bool IsOnAccept
        {
            get
            {
                return API_IsOnAccept(this._handle);
            }
        }

        public bool IsOnError
        {
            get
            {
                return API_IsOnError(this._handle);
            }
        }

        public bool IsOnRead
        {
            get
            {
                return API_IsOnRead(this._handle);
            }
        }

        public bool IsOnWrite
        {
            get
            {
                return API_IsOnWrite(this._handle);
            }
        }

        public EndPoint LocalEndPoint
        {
            get
            {
                return this._localEndPoint;
            }
        }

        public int ReceiveTimeOut
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                this.SetSocketOption(SocketOptionLevel.IP, UDTSocketOptionName.UDT_RCVTIMEO, value);
            }
        }

        public EndPoint RemoteEndPoint
        {
            get
            {
                return this._remoteEndPoint;
            }
        }

        public int SendTimeOut
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                this.SetSocketOption(SocketOptionLevel.IP, UDTSocketOptionName.UDT_SNDTIMEO, value);
            }
        }

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate void EndOperationHandler(IntPtr pointer);

        [StructLayout(LayoutKind.Sequential)]
        internal struct TimeValue
        {
            public int Seconds;
            public int Microseconds;
        }

        [StructLayout(LayoutKind.Sequential)]
        internal struct UDTLinger
        {
            internal short OnOff;
            internal short Time;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -