/// <summary> /// 清除数据 /// </summary> public void Clear() { //回收所以数据 for (int i = 0; i < SendBuffer.Count; i++) { QueuePool.Roll(SendBuffer[i].Data); } SendBuffer.Clear(); }
/// <summary> /// 接收确认包 /// </summary> /// <param name="package"></param> public void AddAck(ACKPackage package) { var seqPack = SendBuffer.Find(x => x.PackSeq == package.PackSeq); if (seqPack != null) { SendBuffer.Remove(seqPack); QueuePool.Roll(seqPack.Data);//回收数据 } }
public void Send(byte[] data, int offset, int length, string host, int port) { int seq = 0; int len = length; short curentSize = 0; //分包 while (len > 0) { byte[] buf = QueuePool.GetBuffers(); if (len > buf.Length) { len = len - buf.Length; curentSize = (short)buf.Length; } else { curentSize = (short)len; len = 0; } Array.Copy(data, offset + seq * curentSize, buf, 0, curentSize); DATAPackage package = new DATAPackage { Length = length, PackID = Uilt.GlobID, PackSeq = seq, PackLength = curentSize, PackSize = PackageControl.PackSize - BasePackage.PackSum, Data = buf, DestHost = host, DestPort = port }; seq++; senderSession.Add(package); } }