/// <summary> /// Add a TCPInPacket instance to the pool. /// </summary> /// <param name="item">TCPInPacket instance to add to the pool.</param> internal void Push(TCPInPacket item) { if (item == null) { throw new ArgumentNullException("添加到TCPInPacketPool 的item不能是空(null)"); } lock (this.pool) { item.Reset(); this.pool.Push(item); } }
/// <summary> /// Removes a TCPInPacket instance from the pool. /// </summary> /// <returns>TCPInPacket removed from the pool.</returns> internal TCPInPacket Pop(TMSKSocket s, TCPCmdPacketEventHandler TCPCmdPacketEvent) { lock (this.pool) { TCPInPacket tcpInPacket = null; if (this.pool.Count <= 0) { //临时分配 tcpInPacket = new TCPInPacket() { CurrentSocket = s }; tcpInPacket.TCPCmdPacketEvent += TCPCmdPacketEvent; return(tcpInPacket); } tcpInPacket = this.pool.Pop(); tcpInPacket.CurrentSocket = s; return(tcpInPacket); } }
internal TCPInPacket Pop(TMSKSocket s, TCPCmdPacketEventHandler TCPCmdPacketEvent) { TCPInPacket result; lock (this.pool) { if (this.pool.Count <= 0) { TCPInPacket tcpInPacket = new TCPInPacket(6144) { CurrentSocket = s }; tcpInPacket.TCPCmdPacketEvent += TCPCmdPacketEvent; result = tcpInPacket; } else { TCPInPacket tcpInPacket = this.pool.Dequeue(); tcpInPacket.CurrentSocket = s; result = tcpInPacket; } } return(result); }
public void Dispose() { this.Reset(); TCPInPacket.DecInstanceCount(); }
public TCPInPacket(int recvBufferSize = 6144) { this.PacketBytes = new byte[recvBufferSize]; TCPInPacket.IncInstanceCount(); }