示例#1
0
        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);
                }
        }
示例#2
0
 public void Wait_with_no_sockets()
 {
     using (Udt.SocketPoller poller = new Udt.SocketPoller())
     {
         Assert.Throws <InvalidOperationException>(() => poller.Wait());
     }
 }
示例#3
0
        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));
                }
        }
示例#4
0
        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));
            }
        }
示例#5
0
 public void Wait_when_disposed()
 {
     Udt.SocketPoller poller = new Udt.SocketPoller();
     poller.Dispose();
     Assert.Throws <ObjectDisposedException>(() => poller.Wait());
 }
示例#6
0
        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);
            }
        }
示例#7
0
 public void Wait_with_no_sockets()
 {
     using (Udt.SocketPoller poller = new Udt.SocketPoller())
     {
         Assert.Throws<InvalidOperationException>(() => poller.Wait());
     }
 }
示例#8
0
 public void Wait_when_disposed()
 {
     Udt.SocketPoller poller = new Udt.SocketPoller();
     poller.Dispose();
     Assert.Throws<ObjectDisposedException>(() => poller.Wait());
 }