Ejemplo n.º 1
0
        public static void Update(this RouterServiceComponent self)
        {
            self.Recv();
            var nowtime = TimeHelper.ClientNowSeconds();

            if (self.CurrTimeSecond != nowtime)
            {
                self.CurrTimeSecond = nowtime;
                if (self.CurrTimeSecond % 3 == 0)
                {
                    self.RemoveConnectTimeoutIds();
                }
            }
        }
Ejemplo n.º 2
0
        public static void Awake(this RouterServiceComponent self, IPEndPoint ipEndPoint)
        {
            self.StartTime      = TimeHelper.ClientNow();
            self.CurrTimeSecond = TimeHelper.ClientNowSeconds();
            self.socket         = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                self.socket.SendBufferSize    = Kcp.OneM * 64;
                self.socket.ReceiveBufferSize = Kcp.OneM * 64;
            }

            self.socket.Bind(ipEndPoint);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                const uint IOC_IN            = 0x80000000;
                const uint IOC_VENDOR        = 0x18000000;
                uint       SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
                self.socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null);
            }
        }
Ejemplo n.º 3
0
        public static long GenerateId()
        {
            long time = TimeHelper.ClientNowSeconds();

            if (time != lastTime)
            {
                value    = 0;
                lastTime = time;
            }

            if (++value > ushort.MaxValue - 1)
            {
                Log.Error($"id is not enough! value: {value}");
            }

            if (time > int.MaxValue)
            {
                Log.Error($"time > int.MaxValue value: {time}");
            }

            IdStruct idStruct = new IdStruct(process, (uint)time, (ushort)value);

            return(idStruct.ToLong());
        }