コード例 #1
0
        private static void initThrift(IGateway gw)
        {
            G.DefaultGateway = gw;
            var cp          = new ClientProcessor(gw);
            var t_processor = new Client.GW.Processor(cp);
            var transport   = new Thrift.Transport.TServerSocket(6325, 100000, true);

            System.Threading.ThreadPool.SetMinThreads(1, 0);
            var tps = new Thrift.Server.TThreadPoolServer(t_processor, transport);

            Task.Run(() =>
            {
                Console.WriteLine($"{gw.GetPrimaryKeyString()}:Task: thrift started");
                System.Threading.ThreadPool.GetMaxThreads(out var wt, out var cpt);
                Console.WriteLine($"ThreadPool maxwt:{wt} maxcpt:{cpt}");
                tps.Serve();
            });
            Task.Run(() =>
            {//心跳检测,如果客户端长时间没有发起thrift请求,那么回收token,类似udp判断玩家是否断线
                while (true)
                {
                    cp.CheckHeartbeat(); Thread.Sleep(1000);
                }
            });
        }