Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        private Udt.Socket SetupUdtSocket()
        {
            Logger.Debug("[" + Thread.CurrentThread.ManagedThreadId + "] Setting up new UDT socket");
            var udtSocket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream);

            udtSocket.SetSocketOption(Udt.SocketOptionName.SendBuffer, 16384);
            udtSocket.SetSocketOption(Udt.SocketOptionName.ReceiveBuffer, 16384);
            return(udtSocket);
        }
Exemplo n.º 3
0
 public void Set_LingerState_to_invalid_values()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         ArgumentException argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, 1));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, -10L));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, true));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws <ArgumentNullException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, null));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, "string value"));
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Exemplo n.º 4
0
        public void Set_CongestionControl_to_invalid_values()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                ArgumentException argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, "string value"));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, 10));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, 100L));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, true));
                Assert.AreEqual("value", argEx.ParamName);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
        private void AssertReadOnly(Udt.Socket socket, Udt.SocketOptionName name)
        {
            String message = "Socket option " + name + " is read only";

            ArgumentException ex = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(name, true));

            Assert.AreEqual("name", ex.ParamName);
            StringAssert.StartsWith(message, ex.Message);

            ex = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(name, 1));
            Assert.AreEqual("name", ex.ParamName);
            StringAssert.StartsWith(message, ex.Message);

            ex = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(name, 1L));
            Assert.AreEqual("name", ex.ParamName);
            StringAssert.StartsWith(message, ex.Message);

            ex = Assert.Throws <ArgumentException>(() => socket.SetSocketOption(name, (Object)1));
            Assert.AreEqual("name", ex.ParamName);
            StringAssert.StartsWith(message, ex.Message);
        }
Exemplo n.º 8
0
        static Udt.Socket PeerConnect(Socket socket, string remoteAddr, int remotePort)
        {
            bool bConnected = false;
            int  retry      = 0;

            Udt.Socket client = null;

            while (!bConnected)
            {
                try
                {
                    DateTime now = InternetTime.Get();

                    int sleepTimeToSync = SleepTime(now);

                    Console.WriteLine("[{0}] - Waiting {1} sec to sync with other peer",
                                      now.ToLongTimeString(),
                                      sleepTimeToSync);
                    System.Threading.Thread.Sleep(sleepTimeToSync * 1000);

                    GetExternalEndPoint(socket);

                    if (client != null)
                    {
                        client.Close();
                    }

                    client = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream);

                    client.SetSocketOption(Udt.SocketOptionName.Rendezvous, true);

                    client.Bind(socket);

                    Console.Write("\r{0} - Trying to connect to {1}:{2}.  ",
                                  retry++, remoteAddr, remotePort);

                    client.Connect(remoteAddr, remotePort);

                    Console.WriteLine("Connected successfully to {0}:{1}",
                                      remoteAddr, remotePort);

                    bConnected = true;
                }
                catch (Exception e)
                {
                    Console.Write(e.Message.Replace(Environment.NewLine, ". "));
                }
            }

            return(client);
        }
Exemplo n.º 9
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));
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
 private Udt.Socket SetupUdtSocket()
 {
     Logger.Debug("[" + Thread.CurrentThread.ManagedThreadId + "] Setting up new UDT socket");
     var udtSocket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream);
     udtSocket.SetSocketOption(Udt.SocketOptionName.SendBuffer, 16384);
     udtSocket.SetSocketOption(Udt.SocketOptionName.ReceiveBuffer, 16384);
     return udtSocket;
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 13
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));
            }
        }
Exemplo n.º 14
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));
            }
        }
Exemplo n.º 15
0
        public void Set_CongestionControl_to_invalid_values()
        {
            using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
            {
                ArgumentException argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, "string value"));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, 10));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, 100L));
                Assert.AreEqual("value", argEx.ParamName);

                argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.CongestionControl, true));
                Assert.AreEqual("value", argEx.ParamName);
            }
        }
Exemplo n.º 16
0
 public void Set_LingerState_to_invalid_values()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         ArgumentException argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, 1));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, -10L));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, true));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws<ArgumentNullException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, null));
         Assert.AreEqual("value", argEx.ParamName);
         argEx = Assert.Throws<ArgumentException>(() => socket.SetSocketOption(Udt.SocketOptionName.Linger, "string value"));
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
0
 public void Set_MaxBandwidth_to_invalid_values()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         ArgumentException argEx = Assert.Throws<ArgumentNullException>(() => socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, null));
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Exemplo n.º 19
0
 public void Set_MaxBandwidth_to_invalid_values()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         ArgumentException argEx = Assert.Throws <ArgumentNullException>(() => socket.SetSocketOption(Udt.SocketOptionName.MaxBandwidth, null));
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Exemplo n.º 20
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));
            }
        }