private void OnRecvTimeSyn(Packet packet) { #if DEBUG Logs.Info("Recived TimeSyn:" + packet.PacketID.ToString()); #endif TimeSynPacket p = packet as TimeSynPacket; m_Ping = (int)(m_SynTimer.ElapsedMilliseconds - p.ClinetTimeStamp); m_TimeSpanWithServer = (long)((DateTime.FromBinary(p.ServerTimeStamp) - DateTime.Now).TotalMilliseconds); //����,��Ϊֱ�������ﴦ���� this.PacketCreatorMgr_Recived.GetPacketCreator(TimeSynPacket._PacketID).RecylePacket(p); }
protected override void HandleReceviedPackets(NetClientBase client, NetIOCPClient.NetWork.Packet recivedPacket) { //关联包处理 ProfInstance pi = Profile.StartProf(); //ToDo:读取内容 if (PacketHandles[recivedPacket.PacketID] != null) { PacketHandles[recivedPacket.PacketID](0L, recivedPacket); } else { //Debug.Assert(false, p.ToString() + "没有相应的解析委托"); Console.WriteLine("包" + recivedPacket.PacketID + "没有相应的解析委托"); } pi.EndProf(recivedPacket.ToString(), 1f); }
/// <summary> /// 创建的 与回收的 packetid必须一样,通过ID来关联创建器与 packet对象 /// 自动回收Packet.Buffer以及清理packet的内部关联数据 /// </summary> /// <param name="p"></param> public abstract void RecylePacket(Packet p);
public PacketWriteException(Packet p, PacketErrorLevel errLevel, Exception inner) : base("写Packet错误", inner) { ErrPacket = p; ErrLevel = errLevel; }
public PacketReadException(Packet p, PacketErrorLevel errLevel, Exception inner) : base("读packet错误", inner) { ErrPacket = p; ErrLevel = errLevel; }
static void nc_OnSend(NetClientBase sender, Packet p) { Console.WriteLine("send:"+(p==null?"byte[]":p.ToString())); }
static void nc_OnRecvData(NetClientBase sender, Packet p) { Console.WriteLine("recived packet:" + p.ToString()); }
public override void RecylePacket(Packet p) { _initPacketPool(); p.Buffer.DecrementUsage(); if (p.Buffer.Uses == 0) { p.Buffer = null; } p.ClearContent(); _packetPool.ReleaseContent(p as CustomPacket); }
public override void RecylePacket(Packet p) { _initPacketPool(); System.Diagnostics.Debug.Assert(p.Buffer.Uses == 1); p.Buffer.DecrementUsage(); if (p.Buffer.Uses == 0) { p.Buffer = null; } p.ClearContent();//防止内存溢出 _packetPool.ReleaseContent(p as TimeSynPacket); }