CClash.CClashServer.Listen C# (CSharp) Method

Listen() public method

public Listen ( string cachedir ) : void
cachedir string
return void
        public void Listen(string cachedir)
        {
            Environment.CurrentDirectory = cdto;
            Logging.Emit("creating direct cache server..");
            cache = new DirectCompilerCacheServer(cachedir);
            Logging.Emit("starting server threads..");

            while (serverThreads.Count < MaxServerThreads)
            {
                NewServerThread(cachedir);
            }

            // maintain the threadpool
            while (!quitnow)
            {
                foreach (var t in serverThreads.ToArray())
                {
                    if (busyThreads > 0)
                        Logging.Emit("{0} busy threads", busyThreads);
                    if (t.Join(1000))
                    {
                        serverThreads.Remove(t);
                        Logging.Emit("replacing thread");
                        NewServerThread(cachedir);
                    }
                }
                if (busyThreads < 1) {
                    Logging.Emit("server is idle..");
                }
                if (DateTime.Now.Subtract(lastRequest).TotalMinutes > QuitAfterIdleMinutes)
                {
                    quitnow = true;
                }
            }
            Logging.Emit("waiting for threads to finish");
            foreach (var t in serverThreads)
            {
                Logging.Emit("joining thread {0}", t.ManagedThreadId);
                if (!t.Join(2000)) {
                    Logging.Emit("thread still running..");
                }
            }

            Logging.Emit("commiting stats");
            cache.SetupStats();
            Logging.Emit("server quitting");
            serverMutex.ReleaseMutex();
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            //Environment.SetEnvironmentVariable("CCLASH_HARDLINK", "yes");
            Environment.SetEnvironmentVariable("CCLASH_SERVER", "yes");
            Environment.SetEnvironmentVariable("CCLASH_MISSES", System.IO.Path.Combine( Environment.CurrentDirectory, "misses.txt"));
            Settings.CacheDirectory = System.IO.Path.Combine( Environment.CurrentDirectory, "cclash-unittest");

            try
            {
                if (System.IO.Directory.Exists(Settings.CacheDirectory))
                    System.IO.Directory.Delete(Settings.CacheDirectory, true);
            }
            catch { }
            var serv = new CClashServer();
            serv.Listen(Settings.CacheDirectory);
        }
All Usage Examples Of CClash.CClashServer::Listen