public void ThreadSockSend() { UdpClient udpClient = new UdpClient(23477); var receiveTask = udpClient.ReceiveAsync(); // Send to specified EndPoint, don't put buffer to pool var sendEP = new IPEndPoint(IPAddress.Loopback, 23477); _sock.Send(sendEP, BitConverter.GetBytes(123456789), 0, 4, false); receiveTask.Wait(1000); Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status); Assert.AreEqual(123456789, BitConverter.ToInt32(receiveTask.Result.Buffer, 0)); Assert.AreEqual(0, _bufferPool.Rented.Count); Assert.AreEqual(0, _bufferPool.Returned.Count); Assert.AreEqual(0, _bufferPool.Alien); }
public void ThreadSockSend() { UdpClient udpClient = new UdpClient(23477); var receiveTask = udpClient.ReceiveAsync(); // Send to specified EndPoint, don't put buffer to pool var sendEP = new IPEndPoint(IPAddress.Loopback, 23477); _sock.Send(sendEP, BitConverter.GetBytes(123456789), 0, 4, false); receiveTask.Wait(1000); Assert.AreEqual(TaskStatus.RanToCompletion, receiveTask.Status); Assert.AreEqual(123456789, BitConverter.ToInt32(receiveTask.Result.Buffer, 0)); Assert.AreEqual(0, _bufferPool.Rented.Count); Assert.AreEqual(0, _bufferPool.Returned.Count); Assert.AreEqual(0, _bufferPool.Alien); 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); }