Esempio n. 1
0
        public void MultiplePacketsSent()
        {
            UdpClient udpClient   = new UdpClient(23450);
            var       receiveTask = udpClient.ReceiveAsync();

            var bufferPool = new ByteBufferPool();
            var sock       = new BareSock(bufferPool, AddressFamily.InterNetwork, new LoggerStub());

            sock.Connect(IPAddress.Loopback, 23450);
            sock.Send(BitConverter.GetBytes(1), 0, 4, false);
            sock.Send(BitConverter.GetBytes(2), 0, 4, false);
            sock.Send(BitConverter.GetBytes(3), 0, 4, false);

            receiveTask.Wait(2000);
            Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status);
            Assert.LessOrEqual(1, BitConverter.ToInt32(receiveTask.Result.Buffer, 0));

            receiveTask = udpClient.ReceiveAsync();
            receiveTask.Wait(2000);
            Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status);
            Assert.LessOrEqual(2, BitConverter.ToInt32(receiveTask.Result.Buffer, 0));

            // This test is flaky...
            receiveTask = udpClient.ReceiveAsync();
            receiveTask.Wait(2000);
            Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status);
            Assert.AreEqual(3, BitConverter.ToInt32(receiveTask.Result.Buffer, 0));

            sock.Close();
        }
Esempio n. 2
0
        public void SendMoreThanMTUDroppedOnReceiveByBareSock()
        {
            var bufferPool = new ByteBufferPool();
            var sock       = new BareSock(bufferPool, AddressFamily.InterNetwork, new LoggerStub());

            sock.Listen(23459);

            UdpClient udpClient = new UdpClient();

            udpClient.Connect(IPAddress.Loopback, 23459);
            udpClient.Send(new byte[BareSock.MTU + 1], BareSock.MTU + 1);

            var receivedPacket = Utils.WaitOnReceive(sock);

            Assert.IsNull(receivedPacket.Buffer);
            Assert.AreEqual(0, receivedPacket.Offset);
            Assert.AreEqual(0, receivedPacket.Length);

            sock.Close();
        }
Esempio n. 3
0
 public void TearDown()
 {
     _sock.Close();
 }