Beispiel #1
0
 /// <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);
     }
 }
Beispiel #2
0
        /// <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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 public void Dispose()
 {
     this.Reset();
     TCPInPacket.DecInstanceCount();
 }
Beispiel #5
0
 public TCPInPacket(int recvBufferSize = 6144)
 {
     this.PacketBytes = new byte[recvBufferSize];
     TCPInPacket.IncInstanceCount();
 }