Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ThreadPool.SetMinThreads(18, 18);
            ThreadPool.SetMaxThreads(18, 18);
            var tp = ThreadDispatcher.GetInstance();

            tp.Add(new Load());
            tp.Add(new Load());
            //tp.Run();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var tp = ThreadDispatcher.GetInstance();

            tp.Run();
            var fs = new FileServer(@"C:\Users\m9cko", 8080);

            tp.AddInQueue(fs);
            tp.AddInQueue(new CliServer(fs, 8081));
            tp.SetPoolSize(1);
            tp.SetPoolSize(10);
        }
Ejemplo n.º 3
0
        public void Run()
        {
            var tq   = TaskQueue.GetInstance();
            var sock = new Socket(SocketType.Stream, ProtocolType.Tcp);

            sock.Bind(new IPEndPoint(IPAddress.Any, _port));
            sock.Listen();

            while (true)
            {
                var socket = sock.Accept();
                var text   = ReceiveAllText(socket);

                if (text.StartsWith("list"))
                {
                    socket.Send(GetFileNames());
                }
                else if (text.StartsWith("hash"))
                {
                    socket.Send(GetHash(text));
                }
                else if (text.StartsWith("size"))
                {
                    socket.Send(GetFileSize(text));
                }
                else if (text.StartsWith("status"))
                {
                    socket.Send(_fs.isRunning
                        ? Encoding.UTF8.GetBytes("active")
                        : Encoding.UTF8.GetBytes("stopped"));
                }
                else if (text.StartsWith("stop"))
                {
                    _fs.isRunning = false;
                    socket.Send(Encoding.UTF8.GetBytes("stopped"));
                }
                else if (text.StartsWith("start"))
                {
                    if (!_fs.isRunning)
                    {
                        _fs.isRunning = true;
                        ThreadDispatcher.GetInstance().AddInQueue(_fs);
                    }

                    socket.Send(Encoding.UTF8.GetBytes("started"));
                }
            }
        }