Beispiel #1
0
        public void Send_AllInOrder_CorrectOrder()
        {
            var loopback = new Loopback(LoopbackTypes.AllInOrder);
            var lhs      = new UnreliableOrderedConnection(loopback.RhsUpdSend, 1, new NullTrace());
            var rhs      = new UnreliableOrderedConnection(loopback.LhsUdpSend, 1, new NullTrace());

            loopback.RhsUpdSend.Sink = rhs;
            loopback.LhsUdpSend.Sink = lhs;
            var list = new List <Paket>();

            rhs.NewPaket += (p1, p2) => { list.Add(p2); };
            for (int i = 0; i < 100000; i++)
            {
                var paket = lhs.CreatePaket();
                SimpleTypeWriter.Write(i + "Test" + i, paket);
                SimpleTypeWriter.Write(i, paket);
                lhs.Send(paket);
            }
            Assert.Equal(100000, list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                var paket   = list[i];
                var message = SimpleTypeReader.ReadString(paket);
                var number  = SimpleTypeReader.ReadInt(paket);
                Assert.Equal(i, number);
                Assert.Equal(message, i + "Test" + i);
            }
        }
Beispiel #2
0
        public override void MessageReceived(Paket paket)
        {
            var sequenceId = (ushort)(paket.Array[2] + (paket.Array[3] << 8));

            paket.SeqId = sequenceId;
#if UID
            paket.Offset = 8;
            paket.Uid    = (uint)SimpleTypeReader.ReadInt(paket);
#else
            paket.Offset = 8;
#endif
            // TODO: playoutBuffer calls Playout into user code while having this lock. High deadlock danger when user calls back into send while the lock is held here
            lock (_lock)
            {
                Trace.Debug(">>> Received: {0}", paket);
                var sendAck = (paket.Array[1] & RequireAck) != 0;
                if ((paket.Array[1] & Empty) == 0)
                {
                    _messageReceivedCounter++;
                    var ackResult = _receivedOrderedAcknowledgePlayoutBuffers.Add(paket.SeqId, paket);
                    // not sure whether lateAck is a reason to send acks. Following scenario:
                    // 001
                    // 101 early ack
                    // 111 late ack
                    var ack = ackResult == AckResult.AlreadyAcked || ackResult == AckResult.EarlyAck || ackResult == AckResult.OutOfWindow;
                    if (_messageReceivedCounter++ == 4)
                    {
                        _messageReceivedCounter = 0;
                        _lastAckResult          = AckResult.Unknown;
                    }
                    // Avoid flooding with empty packages. This could happen when for example a paket is missing but pakets
                    // keep on arriving they all would come back here with "EarlyAck". However after 4 pakets we reset.
                    if (ackResult != _lastAckResult)
                    {
                        sendAck |= ack;
                    }
                    _lastAckResult = ackResult;
                    if (sendAck)
                    {
                        Trace.Debug("SendingAck because AckResult: {0}", ackResult);
                    }
                }
                else
                {
                    Trace.Debug("Received empty paket. Not adding to acks");
                }
                if (ResendUnconfirmed(paket))
                {
                    sendAck = false;
                }
                if (sendAck)
                {
                    SendEmptyPaket(Empty);
                }
                Trace.Debug("<<< Received: {0}", paket);
                Monitor.Pulse(_lock);
            }
        }
        public void WriteReadInt_12345678()
        {
            var paket = new Paket();

            paket.Offset = 5;
            SimpleTypeWriter.Write(12345678, paket);
            paket.Offset = 5;
            Assert.Equal(12345678, SimpleTypeReader.ReadInt(paket));
        }
        public void WriteReadInt_1()
        {
            var paket = new Paket();

            paket.Offset = 8;
            SimpleTypeWriter.Write(1, paket);
            paket.Offset = 8;
            Assert.Equal(1, SimpleTypeReader.ReadInt(paket));
        }
Beispiel #5
0
 public void Deserialize(Paket paket)
 {
     TestString = SimpleTypeReader.ReadString(paket);
     TestNumber = SimpleTypeReader.ReadInt(paket);
 }
Beispiel #6
0
 public void Deserialize(Paket paket)
 {
     ClientVersion = SimpleTypeReader.ReadInt(paket);
 }
Beispiel #7
0
 public void Deserialize(Paket paket)
 {
     ServerName    = SimpleTypeReader.ReadString(paket);
     ServerVersion = SimpleTypeReader.ReadInt(paket);
     RunningId     = SimpleTypeReader.ReadInt(paket);
 }