Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider();

            try
            {
                if (args.Length == 0 ||
                    !Enum.TryParse(args[0], true, out ServerType serverType))
                {
                    serverType = ServerType.Tcp;
                }

                RunLoop(serverType);

                loop.Dispose();
                loop = null;
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Echo client error {exception}");
            }

            Console.WriteLine("Press any key to terminate the client");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider(LogLevel.Debug);

            try
            {
                eventLoop = new EventLoop();
                Task task = Task.Run(async() => await RunLoopAsync());

                eventLoop.Schedule(loop => loop
                                   .CreateTcp()
                                   .SimultaneousAccepts(true)
                                   .Listen(EndPoint, OnConnection));

                Console.WriteLine("Waiting for loop to complete.");
                task.Wait();
                Console.WriteLine("Loop completed.");
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Loop thread error {exception}.");
            }
            finally
            {
                eventLoop?.Dispose();
            }

            Console.WriteLine("Press any key to terminate the program.");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            processorCount = Environment.ProcessorCount;
            Console.WriteLine(
                $" {RuntimeInformation.OSArchitecture} {RuntimeInformation.OSDescription}\n"
                + $" {RuntimeInformation.ProcessArchitecture} {RuntimeInformation.FrameworkDescription}\n"
                + $" Processor Count : {Environment.ProcessorCount} \n");

            ParseFlags(args);

            string category = GetCategory(args);
            string name     = GetTestName(args);

            if (isDebug)
            {
                LogFactory.AddConsoleProvider();
            }

            Console.WriteLine($"\nNative version {Loop.NativeVersion}\n");
            Run(category, name);

            if (!shouldPause)
            {
                return;
            }

            Console.WriteLine("Press any key to terminate the application");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider();

            try
            {
                if (args.Length == 0 ||
                    !Enum.TryParse(args[0], true, out ServerType serverType))
                {
                    serverType = ServerType.Tcp;
                }

                StartServer(serverType);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Echo server error {exception}.");
            }
            finally
            {
                loop.Dispose();
            }

            Console.WriteLine("Press any key to terminate echo server.");
            Console.ReadLine();
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider(LogLevel.Trace);
            connections = new List <Tcp>();
            try
            {
                StartServer();
                loop.Dispose();
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Echo server error {exception}.");
            }

            Console.WriteLine("Press any key to terminate echo server.");
            Console.ReadLine();
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider(LogLevel.Trace);

            try
            {
                RunLoop();

                loop.Dispose();
                loop = null;
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Echo client error {exception}");
            }

            Console.WriteLine("Press any key to terminate the client");
            Console.ReadLine();
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            LogFactory.AddConsoleProvider(LogLevel.Debug);

            try
            {
                eventLoop = new EventLoop();

                Task startTask = eventLoop.ExecuteAsync(state => ((Loop)state)
                                                        .CreateTcp()
                                                        .SimultaneousAccepts(true)
                                                        .Listen(EndPoint, OnConnection),
                                                        eventLoop.Loop);

                Task completion;
                if (!startTask.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Tcp listen timed out.");
                    completion = eventLoop.ShutdownGracefullyAsync();
                }
                else
                {
                    Console.WriteLine("Tcp listen completed.");
                    completion = eventLoop.TerminationCompletion;
                }

                completion.Wait(TimeSpan.FromSeconds(10));
                Console.WriteLine("EventLoop completed.");
            }
            catch (Exception exception)
            {
                Console.WriteLine($"Loop thread error {exception}.");
            }

            Console.WriteLine("Press any key to terminate the program.");
            Console.ReadLine();
        }
Exemplo n.º 8
0
        static int Run(IReadOnlyCollection <string> list, bool debug, bool pause)
        {
            Console.WriteLine(
                $"\n{RuntimeInformation.OSArchitecture} {RuntimeInformation.OSDescription}"
                + $"\n{RuntimeInformation.ProcessArchitecture} {RuntimeInformation.FrameworkDescription}"
                + $"\nProcessor Count : {processorCount}\n");

            if (debug)
            {
                LogFactory.AddConsoleProvider();
            }
            else
            {
                ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Disabled;
            }

            Console.WriteLine($"\nLibuv Native version {Loop.NativeVersion}");
            Console.WriteLine($"Buffer leak detection : {nameof(ResourceLeakDetector)}.{ResourceLeakDetector.Level}\n");

            if (list.Contains("loop", StringComparer.OrdinalIgnoreCase))
            {
                RunLoopBenchmark();
            }
            if (list.Contains("timer", StringComparer.OrdinalIgnoreCase))
            {
                RunTimerBenchmark();
            }

            List <string> names = list.Contains("async", StringComparer.OrdinalIgnoreCase)
                ? new List <string> {
                "asyncHandles", "asyncSend", "asyncPummel"
            }
                : list.Where(x => x.StartsWith("async")).ToList();

            if (names.Count > 0)
            {
                RunAsyncBenchmark(names);
            }

            names = list.Contains("tcp", StringComparer.OrdinalIgnoreCase)
                ? new List <string> {
                "tcpWriteBatch", "tcpPingPong", "tcpPump", "tcpPound"
            }
                : list.Where(x => x.StartsWith("tcp")).ToList();
            if (names.Count > 0)
            {
                RunTcpBenchmark(names);
            }

            names = list.Contains("pipe", StringComparer.OrdinalIgnoreCase)
                ? new List <string> {
                "pipePump", "pipePound"
            }
                : list.Where(x => x.StartsWith("pipe")).ToList();
            if (names.Count > 0)
            {
                RunPipeBenchmark(names);
            }

            if (list.Contains("udp", StringComparer.OrdinalIgnoreCase))
            {
                RunUdpBenchmark();
            }

            if (list.Contains("addrinfo", StringComparer.OrdinalIgnoreCase))
            {
                RunAddrInfoBenchmark();
            }

            if (pause)
            {
                Console.WriteLine("Press any key to terminate the application");
                Console.ReadLine();
            }

            return(0);
        }