Exemplo n.º 1
0
        public bool SendNextPacket()
        {
            //check sending acks
            DateTime currentTime = DateTime.UtcNow;

            Monitor.Enter(_pendingPackets);
            ProcessQueuedPackets();

            //send
            PendingPacket currentPacket;
            bool          packetFound     = false;
            int           startQueueIndex = _queueIndex;

            do
            {
                currentPacket = _pendingPackets[_queueIndex];
                if (currentPacket.Packet != null)
                {
                    //check send time
                    if (currentPacket.TimeStamp.HasValue)
                    {
                        double packetHoldTime = (currentTime - currentPacket.TimeStamp.Value).TotalMilliseconds;
                        if (packetHoldTime > _peer.ResendDelay)
                        {
                            NetUtils.DebugWrite("[RC]Resend: {0} > {1}", (int)packetHoldTime, _peer.ResendDelay);
                            packetFound = true;
                        }
                    }
                    else //Never sended
                    {
                        packetFound = true;
                    }
                }

                _queueIndex = (_queueIndex + 1) % _windowSize;
            } while (!packetFound && _queueIndex != startQueueIndex);

            if (packetFound)
            {
                currentPacket.TimeStamp = DateTime.UtcNow;
                _peer.SendRawData(currentPacket.Packet);
                NetUtils.DebugWrite("[RR]Sended");
            }
            Monitor.Exit(_pendingPackets);
            return(packetFound);
        }
Exemplo n.º 2
0
        public bool SendNextPacket()
        {
            NetPacket packet;

            lock (_outgoingPackets)
            {
                if (_outgoingPackets.Count == 0)
                {
                    return(false);
                }
                packet = _outgoingPackets.Dequeue();
            }
            _peer.SendRawData(packet);
            _peer.Recycle(packet);
            return(true);
        }