public void Wait_for_accept() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) { socket.Bind(IPAddress.Loopback, 0); socket.Listen(100); ManualResetEvent doneEvent = new ManualResetEvent(false); poller.AddSocket(socket); Task.Factory.StartNew(() => { using (Udt.Socket client = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) { client.Connect(IPAddress.Loopback, socket.LocalEndPoint.Port); doneEvent.WaitOne(1000); } }); Assert.IsTrue(poller.Wait(TimeSpan.FromSeconds(1))); CollectionAssert.AreEqual(new[] { socket }, poller.WriteSockets); CollectionAssert.AreEqual(new[] { socket }, poller.ReadSockets); Udt.Socket acceptedSocket = socket.Accept(); acceptedSocket.Dispose(); doneEvent.Set(); Assert.IsTrue(poller.Wait(TimeSpan.Zero)); CollectionAssert.AreEqual(new[] { socket }, poller.WriteSockets); CollectionAssert.IsEmpty(poller.ReadSockets); } }
public void Wait_with_no_sockets() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Assert.Throws <InvalidOperationException>(() => poller.Wait()); } }
public void Remove_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) { socket.Bind(IPAddress.Loopback, 0); socket.Listen(100); ManualResetEvent doneEvent = new ManualResetEvent(false); poller.AddSocket(socket); Assert.IsFalse(poller.Wait(TimeSpan.Zero)); poller.RemoveSocket(socket); Assert.Throws <InvalidOperationException>(() => poller.Wait(TimeSpan.Zero)); } }
public void Remove_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) { socket.Bind(IPAddress.Loopback, 0); socket.Listen(100); ManualResetEvent doneEvent = new ManualResetEvent(false); poller.AddSocket(socket); Assert.IsFalse(poller.Wait(TimeSpan.Zero)); poller.RemoveSocket(socket); Assert.Throws<InvalidOperationException>(() => poller.Wait(TimeSpan.Zero)); } }
public void Wait_when_disposed() { Udt.SocketPoller poller = new Udt.SocketPoller(); poller.Dispose(); Assert.Throws <ObjectDisposedException>(() => poller.Wait()); }
public void Wait_with_no_sockets() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Assert.Throws<InvalidOperationException>(() => poller.Wait()); } }
public void Wait_when_disposed() { Udt.SocketPoller poller = new Udt.SocketPoller(); poller.Dispose(); Assert.Throws<ObjectDisposedException>(() => poller.Wait()); }