public override 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(kcp, e); return; } } //如果有发送 则检测时间 if (kcp.canSend(false) && (!kcp.checkFlush() || !kcp.isFastFlush())) { return; } long startTicks = DateTime.Now.Ticks; long now = kcp.currentMs(); long next = kcp.flush(now); //Console.WriteLine(next); long currentTicks = DateTime.Now.Ticks; //Console.WriteLine("耗时"+(currentTicks - startTicks) / TimeSpan.TicksPerMillisecond); kcp.setTsUpdate(now + next); } catch (Exception e) { Console.WriteLine(e); } finally { release(); } }
public override 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(); } }