private void TestWith(PacketHeader header) { header.Length = (ushort)header.HeaderLength; var buffer = _bufferPool.Get(header.Length); header.WriteTo(buffer, 0); _bareSock.FakeReceive(buffer, 0, header.Length, new IPEndPoint(IPAddress.Loopback, 23452)); Utils.ReceiveAll(_sock); Assert.AreEqual(1, _bufferPool.Rented.Count); Assert.AreEqual(1, _bufferPool.Returned.Count); Assert.AreEqual(0, _bufferPool.Alien); }
public void ThreadSockSendConnected() { UdpClient udpClient = new UdpClient(23479); var sendEP = new IPEndPoint(IPAddress.Loopback, 23479); var receiveTask = udpClient.ReceiveAsync(); // Send to already connected EndPoint, get buffer from pool _sock.Connect(sendEP.Address, sendEP.Port); var buf = _bufferPool.Get(4); Array.Copy(BitConverter.GetBytes(123456789), buf, 4); _sock.Send(buf, 0, 4, true); receiveTask.Wait(1000); Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status); Assert.AreEqual(123456789, BitConverter.ToInt32(receiveTask.Result.Buffer, 0)); Assert.AreEqual(2, _bufferPool.Rented.Count); Utils.WaitOnSet(_bufferPool.Returned); Assert.AreEqual(1, _bufferPool.Returned.Count); Assert.AreEqual(0, _bufferPool.Alien); }