/// <summary> /// Creates and starts the ClousotPulse server /// </summary> public ClousotPulseServer(Func <ClousotAnalysisState> GetClousotCurrentAnalysisState) { Contract.Requires(GetClousotCurrentAnalysisState != null); this.GetClousotCurrentAnalysisState = GetClousotCurrentAnalysisState; this.callbackNames = new Set <string>(); this.namedPipeServer = new NamedPipeServerStream(CommonNames.GetPipeNameForCCCheckPulse(), PipeDirection.InOut, 254); // Start the server this.server = new Thread(MainProcess); //this.server.IsBackground = true; // If we set it to true, then the server will die when the main one will. However, this is bad as it may cause the server to be killed while it is still sending the info back to the clients this.server.Start(); }
public void Kill() { // We send ourself a shutdown message, to deblock the wait above // Should interrupt the WaitForConnection in a better way? // see: http://stackoverflow.com/questions/607872/what-is-a-good-way-to-shutdown-threads-blocked-on-namedpipeserverwaitforconnect try { var client = new NamedPipeClientStream(".", CommonNames.GetPipeNameForCCCheckPulse(), PipeDirection.InOut); client.Connect(); // we know we succed? new PipeStreamSimple(client).WriteIfConnected("shutdown"); } catch { } }
private void MainProcess(object data) { #if DEBUG && DEBUG_PRINT Console.WriteLine("[DEBUG] Pulse Clousot at named channel {0}", CommonNames.GetPipeNameForCCCheckPulse()); #endif while (true) { try { this.namedPipeServer.WaitForConnection(); // wait for connection var stream = new PipeStreamSimple(namedPipeServer); string obj; if (stream.TryRead(out obj)) { if (obj == "shutdown") { goto done; } this.callbackNames.AddIfNotNull(obj); } // Write what Clousot is doing now stream.WriteIfConnected(GetClousotCurrentAnalysisState().ToList()); this.namedPipeServer.Disconnect(); } catch { // just swallow the error } } done: ; }
private void UpdateGrids() { // Clear the pulse grid this.clousotPulseGrid.Rows.Clear(); var ClousotProcesses = Process.GetProcessesByName("Clousot").Union(Process.GetProcessesByName("cccheck")); foreach (var proc in ClousotProcesses) { var pipeName = CommonNames.GetPipeNameForCCCheckPulse(proc.Id); var namedPipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut); try { InsertOrUpdateRowToProcessesGrid(proc); namedPipeClient.Connect(20); var stream = new PipeStreamSimple(namedPipeClient); stream.WriteIfConnected(this.myCallBackPipe); List <Tuple <string, object> > result; if (stream.TryRead(out result)) { var obj = new ClousotAnalysisState(result); AddRowToPulseGrid(proc.Id, obj); } else { Trace.TraceWarning("failed to get a meaningfull answer from proc id {0}", proc.Id); } } catch { // does nothing } namedPipeClient.Close(); } }