Пример #1
0
 public void Get_Events()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) {
         Assert.AreEqual(Udt.SocketEvents.None, socket.Events);
         Assert.AreEqual(Udt.SocketEvents.None, socket.GetSocketOption(Udt.SocketOptionName.Events));
         AssertReadOnly(socket, Udt.SocketOptionName.Events);
     }
 }
Пример #2
0
 public void Get_SendDataSize()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         Assert.AreEqual(0, socket.SendDataSize);
         Assert.AreEqual(0, socket.GetSocketOption(Udt.SocketOptionName.SendData));
         AssertReadOnly(socket, Udt.SocketOptionName.SendData);
     }
 }
Пример #3
0
        public void Get_set_BlockingReceive()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.IsTrue(socket.BlockingReceive);
                socket.BlockingReceive = false;
                Assert.IsFalse(socket.BlockingReceive);

                Assert.IsFalse((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, true);
                Assert.IsTrue((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, 0);
                Assert.IsFalse(socket.BlockingReceive);
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, 10L);
                Assert.IsTrue(socket.BlockingReceive);
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, (object)false);
                Assert.IsFalse((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
            }
        }
Пример #4
0
        public void Get_set_MaxBandwidth()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                // MaxBandwidth
                Assert.AreEqual(-1L, socket.MaxBandwidth);
                socket.MaxBandwidth = 50L;
                Assert.AreEqual(50L, socket.MaxBandwidth);

                Assert.AreEqual(50L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, (object)1);
                Assert.AreEqual(1L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, 2);
                Assert.AreEqual(2L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, -1L);
                Assert.AreEqual(-1L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, false);
                Assert.AreEqual(0L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, (object)10L);
                Assert.AreEqual(10L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));
            }
        }
Пример #5
0
        public void Get_State()
        {
            ManualResetEvent serverDoneEvent = new ManualResetEvent(false);
            ManualResetEvent clientDoneEvent = new ManualResetEvent(false);
            int port = _portNum++;

            var serverTask = Task.Factory.StartNew(() => {
                using (Udt.Socket server = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) {
                    server.Bind(IPAddress.Loopback, port);
                    Assert.AreEqual(Udt.SocketState.Open, server.State);
                    server.Listen(1);
                    Assert.AreEqual(Udt.SocketState.Listening, server.State);

                    using (Udt.Socket accept = server.Accept()) {
                        Assert.AreEqual(Udt.SocketState.Open, server.State);
                        serverDoneEvent.Set();
                        Assert.IsTrue(clientDoneEvent.WaitOne(1000));
                    }
                }
            });

            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.AreEqual(Udt.SocketState.Initial, socket.State);
                Assert.AreEqual(Udt.SocketState.Initial, socket.GetSocketOption(Udt.SocketOptionName.State));
                AssertReadOnly(socket, Udt.SocketOptionName.State);

                socket.Connect(IPAddress.Loopback, port);
                Assert.AreEqual(Udt.SocketState.Connected, socket.State);

                serverDoneEvent.WaitOne(1000);
                clientDoneEvent.Set();

                socket.Close();
                Assert.AreEqual(Udt.SocketState.Closed, socket.State);
                Assert.AreEqual(Udt.SocketState.Closed, socket.GetSocketOption(Udt.SocketOptionName.State));
            }
        }
Пример #6
0
        public void Get_set_ReceiveTimeout()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.AreEqual(-1, socket.ReceiveTimeout);
                socket.ReceiveTimeout = 50;
                Assert.AreEqual(50, socket.ReceiveTimeout);

                Assert.AreEqual(50, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, -1);
                Assert.AreEqual(-1, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, 5L);
                Assert.AreEqual(5, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, true);
                Assert.AreEqual(1, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, (object)10);
                Assert.AreEqual(10, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));
            }
        }
Пример #7
0
        public void Get_set_LingerState()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                LingerOption opt = socket.LingerState;
                Assert.IsTrue(opt.Enabled);
                Assert.AreEqual(180, opt.LingerTime);

                socket.LingerState = new LingerOption(false, 500);
                opt = socket.LingerState;
                Assert.IsFalse(opt.Enabled);
                Assert.AreEqual(500, opt.LingerTime);

                opt = (LingerOption)socket.GetSocketOption(Udt.SocketOptionName.Linger);
                Assert.IsFalse(opt.Enabled);
                Assert.AreEqual(500, opt.LingerTime);

                socket.SetSocketOption(Udt.SocketOptionName.Linger, new LingerOption(true, 180));
                opt = (LingerOption)socket.GetSocketOption(Udt.SocketOptionName.Linger);
                Assert.IsTrue(opt.Enabled);
                Assert.AreEqual(180, opt.LingerTime);
            }
        }
Пример #8
0
        public void Get_set_CongestionControl()
        {
            var mock1 = new Mock <Udt.ICongestionControlFactory>();
            var mock2 = new Mock <Udt.ICongestionControlFactory>();

            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.IsNull(socket.CongestionControl);
                socket.CongestionControl = mock1.Object;
                Assert.AreSame(mock1.Object, socket.CongestionControl);
                Assert.AreSame(mock1.Object, socket.GetSocketOption(Udt.SocketOptionName.CongestionControl));

                socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, mock2.Object);
                Assert.AreSame(mock2.Object, socket.CongestionControl);
                socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, mock2.Object);
                Assert.AreSame(mock2.Object, socket.CongestionControl);
            }
        }
Пример #9
0
        public void Get_State()
        {
            ManualResetEvent serverDoneEvent = new ManualResetEvent(false);
              ManualResetEvent clientDoneEvent = new ManualResetEvent(false);
              int port = _portNum++;

              var serverTask = Task.Factory.StartNew(() => {
            using (Udt.Socket server = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) {
              server.Bind(IPAddress.Loopback, port);
              Assert.AreEqual(Udt.SocketState.Open, server.State);
              server.Listen(1);
              Assert.AreEqual(Udt.SocketState.Listening, server.State);

              using (Udt.Socket accept = server.Accept()) {
            Assert.AreEqual(Udt.SocketState.Open, server.State);
            serverDoneEvent.Set();
            Assert.IsTrue(clientDoneEvent.WaitOne(1000));
              }
            }
              });

              using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
              {
            Assert.AreEqual(Udt.SocketState.Initial, socket.State);
            Assert.AreEqual(Udt.SocketState.Initial, socket.GetSocketOption(Udt.SocketOptionName.State));
            AssertReadOnly(socket, Udt.SocketOptionName.State);

            socket.Connect(IPAddress.Loopback, port);
            Assert.AreEqual(Udt.SocketState.Connected, socket.State);

            serverDoneEvent.WaitOne(1000);
            clientDoneEvent.Set();

            socket.Close();
            Assert.AreEqual(Udt.SocketState.Closed, socket.State);
            Assert.AreEqual(Udt.SocketState.Closed, socket.GetSocketOption(Udt.SocketOptionName.State));
              }
        }
Пример #10
0
        public void Get_set_MaxBandwidth()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                // MaxBandwidth
                Assert.AreEqual(-1L, socket.MaxBandwidth);
                socket.MaxBandwidth = 50L;
                Assert.AreEqual(50L, socket.MaxBandwidth);

                Assert.AreEqual(50L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, (object)1);
                Assert.AreEqual(1L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, 2);
                Assert.AreEqual(2L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, -1L);
                Assert.AreEqual(-1L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, false);
                Assert.AreEqual(0L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));

                socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, (object)10L);
                Assert.AreEqual(10L, socket.GetSocketOption(Udt.SocketOptionName.MaxBandwidth));
            }
        }
Пример #11
0
        public void Get_set_ReceiveTimeout()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.AreEqual(-1, socket.ReceiveTimeout);
                socket.ReceiveTimeout = 50;
                Assert.AreEqual(50, socket.ReceiveTimeout);

                Assert.AreEqual(50, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, -1);
                Assert.AreEqual(-1, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, 5L);
                Assert.AreEqual(5, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, true);
                Assert.AreEqual(1, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));

                socket.SetSocketOption(Udt.SocketOptionName.ReceiveTimeout, (object)10);
                Assert.AreEqual(10, socket.GetSocketOption(Udt.SocketOptionName.ReceiveTimeout));
            }
        }
Пример #12
0
        public void Get_set_LingerState()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                LingerOption opt = socket.LingerState;
                Assert.IsTrue(opt.Enabled);
                Assert.AreEqual(180, opt.LingerTime);

                socket.LingerState = new LingerOption(false, 500);
                opt = socket.LingerState;
                Assert.IsFalse(opt.Enabled);
                Assert.AreEqual(500, opt.LingerTime);

                opt = (LingerOption)socket.GetSocketOption(Udt.SocketOptionName.Linger);
                Assert.IsFalse(opt.Enabled);
                Assert.AreEqual(500, opt.LingerTime);

                socket.SetSocketOption(Udt.SocketOptionName.Linger, new LingerOption(true, 180));
                opt = (LingerOption)socket.GetSocketOption(Udt.SocketOptionName.Linger);
                Assert.IsTrue(opt.Enabled);
                Assert.AreEqual(180, opt.LingerTime);
            }
        }
Пример #13
0
        public void Get_set_CongestionControl()
        {
            var mock1 = new Mock<Udt.ICongestionControlFactory>();
            var mock2 = new Mock<Udt.ICongestionControlFactory>();

            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.IsNull(socket.CongestionControl);
                socket.CongestionControl = mock1.Object;
                Assert.AreSame(mock1.Object, socket.CongestionControl);
                Assert.AreSame(mock1.Object, socket.GetSocketOption(Udt.SocketOptionName.CongestionControl));

                socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, mock2.Object);
                Assert.AreSame(mock2.Object, socket.CongestionControl);
                socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, mock2.Object);
                Assert.AreSame(mock2.Object, socket.CongestionControl);
            }
        }
Пример #14
0
        public void Get_set_BlockingReceive()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                Assert.IsTrue(socket.BlockingReceive);
                socket.BlockingReceive = false;
                Assert.IsFalse(socket.BlockingReceive);

                Assert.IsFalse((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, true);
                Assert.IsTrue((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, 0);
                Assert.IsFalse(socket.BlockingReceive);
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, 10L);
                Assert.IsTrue(socket.BlockingReceive);
                socket.SetSocketOption(Udt.SocketOptionName.BlockingReceive, (object)false);
                Assert.IsFalse((bool)socket.GetSocketOption(Udt.SocketOptionName.BlockingReceive));
            }
        }
Пример #15
0
 public void Get_SendDataSize()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
       {
     Assert.AreEqual(0, socket.SendDataSize);
     Assert.AreEqual(0, socket.GetSocketOption(Udt.SocketOptionName.SendData));
     AssertReadOnly(socket, Udt.SocketOptionName.SendData);
       }
 }
Пример #16
0
 public void Get_Events()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) {
     Assert.AreEqual(Udt.SocketEvents.None, socket.Events);
     Assert.AreEqual(Udt.SocketEvents.None, socket.GetSocketOption(Udt.SocketOptionName.Events));
     AssertReadOnly(socket, Udt.SocketOptionName.Events);
       }
 }