protected virtual int RunServerCore(string pipeName, IClientConnectionHost connectionHost, IDiagnosticListener listener, TimeSpan? keepAlive, CancellationToken cancellationToken) { CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAlive?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(connectionHost, listener); dispatcher.ListenAndDispatchConnections(keepAlive, cancellationToken); return CommonCompiler.Succeeded; }
public static void Main(string[] args) { var ipAddress = IPAddress.Parse("127.0.0.1"); var endPoint = new IPEndPoint(ipAddress, port: 12000); var clientDirectory = AppContext.BaseDirectory; var compilerHost = new CoreClrCompilerServerHost(clientDirectory); var connectionHost = new TcpClientConnectionHost(compilerHost, endPoint); var serverDispatcher = new ServerDispatcher(connectionHost); serverDispatcher.ListenAndDispatchConnections(keepAlive: null, cancellationToken: CancellationToken.None); }
private static int RunCore( IClientConnectionHost connectionHost, IDiagnosticListener listener, TimeSpan?keepAliveTimeout, CancellationToken cancellationToken) { CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(connectionHost, listener); dispatcher.ListenAndDispatchConnections(keepAliveTimeout, cancellationToken); return(CommonCompiler.Succeeded); }
/// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); TimeSpan?keepAliveTimeout = null; // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the // location of the response files. var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory; try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections( BuildProtocolConstants.GetPipeName(compilerExeDirectory), keepAliveTimeout, watchAnalyzerFiles: true); return(0); }
/// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); TimeSpan?keepAliveTimeout = null; try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the // location of the response files. var responseFileDirectory = CommonCompiler.GetResponseFileDirectory(); var dispatcher = new ServerDispatcher(new CompilerRequestHandler(responseFileDirectory), new EmptyDiagnosticListener()); // Add the process ID onto the pipe name so each process gets a semi-unique and predictable pipe // name. The client must use this algorithm too to connect. string pipeName = BuildProtocolConstants.PipeName + Process.GetCurrentProcess().Id.ToString(); dispatcher.ListenAndDispatchConnections(pipeName, keepAliveTimeout, watchAnalyzerFiles: true); return(0); }
internal int RunServer( string pipeName, ICompilerServerHost?compilerServerHost = null, IClientConnectionHost?clientConnectionHost = null, IDiagnosticListener?listener = null, TimeSpan?keepAlive = null, CancellationToken cancellationToken = default ) { keepAlive ??= GetKeepAliveTimeout(); listener ??= new EmptyDiagnosticListener(); compilerServerHost ??= CreateCompilerServerHost(_logger); clientConnectionHost ??= CreateClientConnectionHost(pipeName, _logger); // Grab the server mutex to prevent multiple servers from starting with the same // pipename and consuming excess resources. If someone else holds the mutex // exit immediately with a non-zero exit code var mutexName = BuildServerConnection.GetServerMutexName(pipeName); bool createdNew; using ( var serverMutex = BuildServerConnection.OpenOrCreateMutex( name: mutexName, createdNew: out createdNew ) ) { if (!createdNew) { return(CommonCompiler.Failed); } compilerServerHost.Logger.Log( "Keep alive timeout is: {0} milliseconds.", keepAlive?.TotalMilliseconds ?? 0 ); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher( compilerServerHost, clientConnectionHost, listener ); dispatcher.ListenAndDispatchConnections(keepAlive, cancellationToken); return(CommonCompiler.Succeeded); } }
private const int DefaultServerKeepAlive = 100; // Minimal timeout /// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); int keepaliveMs; // First try to get the die timeout from an environment variable, // then try to get the die timeout from the app.config file. // Set to default if any failures try { string keepaliveStr; if ((keepaliveStr = ConfigurationManager.AppSettings["keepalive"]) != null && int.TryParse(keepaliveStr, out keepaliveMs) && keepaliveMs > 0) { // The die timeout settings are stored in seconds, not // milliseconds keepaliveMs *= 1000; } else { keepaliveMs = DefaultServerKeepAlive; } CompilerServerLogger.Log("Die timeout is: " + keepaliveMs + "milliseconds."); } catch (ConfigurationErrorsException e) { keepaliveMs = DefaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerFatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(BuildProtocolConstants.PipeName, new CompilerRequestHandler(), keepaliveMs); dispatcher.ListenAndDispatchConnections(); return(0); }
private const int DefaultServerDieTimeout = 1; // Minimal timeout /// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); int dieTimeout; // Try to get the die timeout from the app.config file. // Set to default if any failures try { string dieTimeoutStr = ConfigurationManager.AppSettings["dieTimeout"]; if (!int.TryParse(dieTimeoutStr, out dieTimeout)) { dieTimeout = DefaultServerDieTimeout; } else if (dieTimeout > 0) { // The die timeout in the app.config file is stored in // seconds, not milliseconds dieTimeout *= 1000; } CompilerServerLogger.Log("Die timeout is: " + dieTimeout + "milliseconds."); } catch (ConfigurationErrorsException e) { dieTimeout = DefaultServerDieTimeout; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerFatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(BuildProtocolConstants.PipeName, new CompilerRequestHandler(), dieTimeout); //Debugger.Launch(); dispatcher.ListenAndDispatchConnections(); return 0; }
private static int Run(TimeSpan?keepAliveTimeout, string compilerExeDirectory, string pipeName) { try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections( pipeName, keepAliveTimeout); return(CommonCompiler.Succeeded); }
private const int DefaultServerDieTimeout = 3 * 60 * 60 * 1000; // 3 hours /// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { int dieTimeout; // Try to get the die timeout from the app.config file. // Set to default if any failures try { string dieTimeoutStr = ConfigurationManager.AppSettings["dieTimeout"]; if (!int.TryParse(dieTimeoutStr, out dieTimeout)) { dieTimeout = DefaultServerDieTimeout; } else if (dieTimeout > 0) { // The die timeout in the app.config file is stored in // seconds, not milliseconds dieTimeout *= 1000; } } catch (ConfigurationErrorsException) { dieTimeout = DefaultServerDieTimeout; } CompilerFatalError.Handler = FailFast.OnFatalException; CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); var dispatcher = new ServerDispatcher(BuildProtocolConstants.PipeName, new CompilerRequestHandler(), dieTimeout); //Debugger.Launch(); dispatcher.ListenAndDispatchConnections(); return(0); }
private static int Run(TimeSpan? keepAliveTimeout, string compilerExeDirectory, string pipeName) { try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = ServerDispatcher.DefaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = ServerDispatcher.DefaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var compilerServerHost = new DesktopCompilerServerHost(pipeName); var dispatcher = new ServerDispatcher( compilerServerHost, new CompilerRequestHandler(compilerServerHost, compilerExeDirectory), new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections(keepAliveTimeout); return CommonCompiler.Succeeded; }
/// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); TimeSpan? keepAliveTimeout = null; try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the // location of the response files. var responseFileDirectory = CommonCompiler.GetResponseFileDirectory(); var dispatcher = new ServerDispatcher(new CompilerRequestHandler(responseFileDirectory), new EmptyDiagnosticListener()); // Add the process ID onto the pipe name so each process gets a semi-unique and predictable pipe // name. The client must use this algorithm too to connect. string pipeName = BuildProtocolConstants.PipeName + Process.GetCurrentProcess().Id.ToString(); dispatcher.ListenAndDispatchConnections(pipeName, keepAliveTimeout, watchAnalyzerFiles: true); return 0; }
public AnalyzerWatcher(ServerDispatcher dispatcher) { this.dispatcher = dispatcher; AnalyzerFileReference.AssemblyLoad += AnalyzerFileReference_AssemblyLoad; }
/// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); TimeSpan?keepAliveTimeout = null; // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the // location of the response files. var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory; // Pipename should be passed as the first and only argument to the server process // and it must have the form "-pipename:name". Otherwise, exit with a non-zero // exit code const string pipeArgPrefix = "-pipename:"; if (args.Length != 1 || args[0].Length <= pipeArgPrefix.Length || !args[0].StartsWith(pipeArgPrefix)) { return(CommonCompiler.Failed); } var pipeName = args[0].Substring(pipeArgPrefix.Length); try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections( pipeName, keepAliveTimeout, watchAnalyzerFiles: true); return(CommonCompiler.Succeeded); }
private static int RunCore(IClientConnectionHost connectionHost, TimeSpan? keepAliveTimeout) { CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(connectionHost, new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections(keepAliveTimeout); return CommonCompiler.Succeeded; }
/// <summary> /// Main entry point for the process. Initialize the server dispatcher /// and wait for connections. /// </summary> public static int Main(string[] args) { CompilerServerLogger.Initialize("SRV"); CompilerServerLogger.Log("Process started"); TimeSpan? keepAliveTimeout = null; // VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the // location of the response files. var compilerExeDirectory = AppDomain.CurrentDomain.BaseDirectory; // Pipename should be passed as the first and only argument to the server process // and it must have the form "-pipename:name". Otherwise, exit with a non-zero // exit code const string pipeArgPrefix = "-pipename:"; if (args.Length != 1 || args[0].Length <= pipeArgPrefix.Length || !args[0].StartsWith(pipeArgPrefix)) { return CommonCompiler.Failed; } var pipeName = args[0].Substring(pipeArgPrefix.Length); try { int keepAliveValue; string keepAliveStr = ConfigurationManager.AppSettings["keepalive"]; if (int.TryParse(keepAliveStr, NumberStyles.Integer, CultureInfo.InvariantCulture, out keepAliveValue) && keepAliveValue >= 0) { if (keepAliveValue == 0) { // This is a one time server entry. keepAliveTimeout = null; } else { keepAliveTimeout = TimeSpan.FromSeconds(keepAliveValue); } } else { keepAliveTimeout = s_defaultServerKeepAlive; } } catch (ConfigurationErrorsException e) { keepAliveTimeout = s_defaultServerKeepAlive; CompilerServerLogger.LogException(e, "Could not read AppSettings"); } CompilerServerLogger.Log("Keep alive timeout is: {0} milliseconds.", keepAliveTimeout?.TotalMilliseconds ?? 0); FatalError.Handler = FailFast.OnFatalException; var dispatcher = new ServerDispatcher(new CompilerRequestHandler(compilerExeDirectory), new EmptyDiagnosticListener()); dispatcher.ListenAndDispatchConnections( pipeName, keepAliveTimeout); return CommonCompiler.Succeeded; }