예제 #1
0
        public CClashResponse Transact(CClashRequest req)
        {
            Connect();
            CClashResponse resp = null;

            req.pid = System.Diagnostics.Process.GetCurrentProcess().Id;
            var txbuf = req.Serialize();

            ncs.Write(txbuf, 0, txbuf.Length);
            ncs.Flush();

            var rx = new List <byte>();

            var rxbuf = new byte[8192];

            do
            {
                var rbytes = ncs.Read(rxbuf, 0, rxbuf.Length);
                rx.AddRange(rxbuf.Take(rbytes));
            } while (!ncs.IsMessageComplete);

            if (rx.Count > 0)
            {
                resp = CClashMessage.Deserialize <CClashResponse>(rx.ToArray());
                ncs.Close();
            }
            return(resp);
        }
예제 #2
0
        public CClashResponse ProcessRequest(CClashRequest req)
        {
            var rv = new CClashResponse()
            {
                supported = false
            };

            Logging.Emit("{0}", DateTime.Now.ToString("s"));
            Logging.Emit("server req: cmd = {0}, workdir = {1}",
                         req.cmd, req.workdir);

            switch (req.cmd)
            {
            case Command.GetStats:
                rv.exitcode = 0;
                cache.SetupStats();     // commits stats to disk
                rv.stdout = StatOutputs.GetStatsString(req.compiler, cache);
                break;

            case Command.DisableCache:
                DisableCaching = true;
                rv.supported   = true;
                break;

            case Command.ClearCache:
                DisableCaching = true;
                cache.SetupStats();
                cache.Lock(CacheLockType.ReadWrite);
                cache.OutputCache.ClearLocked();
                cache.IncludeCache.ClearLocked();
                cache.Unlock(CacheLockType.ReadWrite);
                rv.supported = true;
                break;

            case Command.EnableCache:
                DisableCaching = false;
                rv.supported   = true;
                break;

            case Command.Run:
                var stdout = new StringBuilder();
                var stderr = new StringBuilder();
                var comp   = cache.SetCompilerEx(req.pid, req.compiler, req.workdir, new Dictionary <string, string>(req.envs));
                cache.SetCaptureCallback(comp, (so) => { stdout.Append(so); }, (se) => { stderr.Append(se); });
                if (DisableCaching)
                {
                    rv.exitcode = comp.InvokeCompiler(req.argv, null, null, false, new List <string>());
                }
                else
                {
                    rv.exitcode = cache.CompileOrCache(comp, req.argv);
                }
                rv.supported = true;
                rv.stderr    = stderr.ToString();
                rv.stdout    = stdout.ToString();

                break;

            case Command.Quit:
                cache.SetupStats();
                Stop();
                break;
            }

            Logging.Emit("server resp: {0}", rv.exitcode);

            return(rv);
        }