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 Add_socket_to_disposed_poller() { Udt.SocketPoller poller = new Udt.SocketPoller(); poller.Dispose(); Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); Assert.Throws<ObjectDisposedException>(() => poller.AddSocket(socket)); socket.Dispose(); }
public void Add_socket_to_disposed_poller() { Udt.SocketPoller poller = new Udt.SocketPoller(); poller.Dispose(); Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); Assert.Throws <ObjectDisposedException>(() => poller.AddSocket(socket)); socket.Dispose(); }
public void Add_closed_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); socket.Dispose(); Assert.Throws <Udt.SocketException>(() => poller.AddSocket(socket)); } }
public void Add_closed_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); socket.Dispose(); Assert.Throws<Udt.SocketException>(() => poller.AddSocket(socket)); } }
public void Remove_closed_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); poller.AddSocket(socket); socket.Dispose(); poller.RemoveSocket(socket); } }
public void Remove_closed_socket() { using (Udt.SocketPoller poller = new Udt.SocketPoller()) { Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); poller.AddSocket(socket); socket.Dispose(); poller.RemoveSocket(socket); } }
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_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); } }