예제 #1
0
        /// <summary>
        /// Add a P2PPacket to the queue
        /// </summary>
        public void Enqueue(P2Packet packet)
        {
            lock (_lock)    // Lock for thread safety
            {
                P2PPacketNode newNode = new P2PPacketNode(packet);

                _len++;

                if (_head == null)
                {
                    _head = newNode;
                    _tail = newNode;
                    return;
                }

                _tail.Next = newNode;
                _tail      = newNode;
            }
        }
예제 #2
0
        /// <summary>
        /// Clear all nodes from the queue
        /// </summary>
        public void Clear()
        {
            object clearLock = new object();

            lock (clearLock)
            {
                P2Packet?packet = Dequeue();

                while (packet != null)
                {
                    packet = Dequeue();
                }

                // Guarantee clearing of head, tail, and length
                _head = null;
                _tail = null;
                _len  = 0;
            }
        }
예제 #3
0
        /// <summary>
        /// Remove a P2PPacket from the queue
        /// </summary>
        public P2Packet?Dequeue()
        {
            lock (_lock)    // Lock for thread safety
            {
                // Only human; probably unnecessary, but safer or something
                if (_len > 0)
                {
                    _len--;
                }

                if (_head != null)
                {
                    P2PPacketNode node   = _head;
                    P2Packet      packet = _head.Packet;
                    _head = _head.Next;
                    node.Dispose();
                    return(packet);
                }

                return(null);
            }
        }
예제 #4
0
 public void Dispose()
 {
     _next = null;
 }