Example #1
0
        void DoReceive(bool slowOutgoing, bool slowIncoming)
        {
            Incoming.SlowConnection = slowIncoming;
            Outgoing.SlowConnection = slowOutgoing;

            int sent = 0;

            buffer = new byte [data.Length];

            var handle = new ManualResetEvent(false);

            NetworkIO.EnqueueReceive(Outgoing, buffer, 0, buffer.Length, null, null, null, (s, t, o) => {
                Assert.IsTrue(s, "#Receive successful");
                Assert.AreEqual(buffer.Length, t, "#data was all received");
                handle.Set();
            }, null);

            while (sent != buffer.Length)
            {
                int r = Incoming.Send(data, sent, data.Length - sent);
                Assert.AreNotEqual(0, r, "#Received data");
                sent += r;
            }

            Assert.IsTrue(handle.WaitOne(TimeSpan.FromSeconds(4)), "Data should be all received");
            for (int i = 0; i < buffer.Length; i++)
            {
                if (data[i] != buffer[i])
                {
                    Assert.Fail("Buffers differ at position " + i);
                }
            }
        }
Example #2
0
        void DoReceive(bool slowOutgoing, bool slowIncoming)
        {
            Incoming.SlowConnection = slowIncoming;
            Outgoing.SlowConnection = slowOutgoing;

            int sent = 0;

            buffer = new byte[data.Length];

            var task = NetworkIO.ReceiveAsync(Outgoing, buffer, 0, buffer.Length, null, null, null);

            while (sent != buffer.Length)
            {
                int r = Incoming.Send(data, sent, data.Length - sent);
                Assert.AreNotEqual(0, r, "#Received data");
                sent += r;
            }

            Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(10)), "Data should be all received");
            for (int i = 0; i < buffer.Length; i++)
            {
                if (data[i] != buffer[i])
                {
                    Assert.Fail("Buffers differ at position " + i);
                }
            }
        }