Esempio n. 1
0
        private void OctetQueueChanged(OctetQueue queue)
        {
            // log.Debug("OctetQueue changed {0}", queue);
            lastReceivedPacketTime = Timestamp.Now();
            var tempBuf = new byte[32 * 1024];

            while (true)
            {
                var octetCount = queue.Peek(tempBuf, 0, tempBuf.Length);

                if (octetCount <= 0)
                {
                    return;
                }
                int octetsUsed = 0;
                var packet     = PacketDecoder.Decode(tempBuf, 0, octetCount, out octetsUsed, log);

                if (packet == null)
                {
                    return;
                }
                queue.Skip(octetsUsed);
                try
                {
                    OnPacketRead(packet);
                }
                catch (Exception e)
                {
                    log.Exception(e);
                    throw e;
                }
            }
        }
Esempio n. 2
0
        public void Add(byte[] octets)
        {
            // log.Debug("Adding to receive stream:{0:X}", octets);
            queue.Enqueue(octets, 0, octets.Length);
            HastyPacket packet = null;

            do
            {
                var octetCount = queue.Peek(targetBuffer, 0, targetBuffer.Length);

                if (octetCount == 0)
                {
                    // log.Debug("octetCount zero");
                    return;
                }
                int newOffset;
                packet = PacketDecoder.Decode(targetBuffer, 0, octetCount, out newOffset, log);

                if (packet != null)
                {
                    // log.Debug("Got packet!");
                    queue.Skip(newOffset);
                    packetReceiver.ReceivePacket(packet);
                }
                else
                {
                    // log.Debug("No packet so far");
                }
            } while (packet != null);
        }