Example #1
0
        public void execute()
        {
            try
            {
                //查看连接状态
                if (!kcp.isActive())
                {
                    return;
                }

                //从发送缓冲区到kcp缓冲区
                var         writeQueue = kcp.WriteQueue;
                IByteBuffer byteBuf    = null;
                while (kcp.canSend(false))
                {
                    if (!writeQueue.TryDequeue(out byteBuf))
                    {
                        break;
                    }
                    try
                    {
                        this.kcp.send(byteBuf);
                        byteBuf.Release();
                    }
                    catch (IOException e)
                    {
                        kcp.getKcpListener().handleException(e, kcp);
                        return;
                    }
                }

                //如果有发送 则检测时间
                if (kcp.canSend(false) && (!kcp.checkFlush() || !kcp.isFastFlush()))
                {
                    return;
                }

                long now  = kcp.currentMs();
                long next = kcp.flush(now);
                //System.out.println(next);
                //System.out.println("耗时"+(System.currentTimeMillis()-now));
                kcp.setTsUpdate(now + next);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                release();
            }
        }