From 351bafefc45727d6f45579397d71a542a84807d9 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 13 Jun 2024 15:30:09 +0200 Subject: Make ServeServerImpl a general class, not a singleton. --- src/buildtool/main/main.cpp | 53 ++++++++++----------------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) (limited to 'src/buildtool/main/main.cpp') diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 508d980e..4c8add19 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -283,39 +283,6 @@ void SetupExecutionServiceConfig(ServiceArguments const& args) { } } -void SetupServeServiceConfig(ServiceArguments const& args) { - if (args.port) { - if (!ServeServerImpl::SetPort(*args.port)) { - Logger::Log(LogLevel::Error, "Invalid port '{}'", *args.port); - std::exit(kExitFailure); - } - } - if (args.info_file) { - if (!ServeServerImpl::SetInfoFile(*args.info_file)) { - Logger::Log(LogLevel::Error, - "Invalid info-file '{}'", - args.info_file->string()); - std::exit(kExitFailure); - } - } - if (args.interface) { - if (!ServeServerImpl::SetInterface(*args.interface)) { - Logger::Log(LogLevel::Error, - "Invalid interface '{}'", - args.info_file->string()); - std::exit(kExitFailure); - } - } - if (args.pid_file) { - if (!ServeServerImpl::SetPidFile(*args.pid_file)) { - Logger::Log(LogLevel::Error, - "Invalid pid-file '{}'", - args.info_file->string()); - std::exit(kExitFailure); - } - } -} - void SetupHashFunction() { HashFunction::SetHashType(Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible @@ -865,15 +832,19 @@ auto main(int argc, char* argv[]) -> int { } if (arguments.cmd == SubCommand::kServe) { - SetupServeServiceConfig(arguments.service); - auto serve = ServeApi::Create(*serve_config); - if (!ServeServerImpl::Instance().Run( - *serve_config, - serve, - !RemoteExecutionConfig::RemoteAddress())) { - return kExitFailure; + auto serve_server = + ServeServerImpl::Create(arguments.service.interface, + arguments.service.port, + arguments.service.info_file, + arguments.service.pid_file); + if (serve_server) { + auto serve = ServeApi::Create(*serve_config); + bool with_execute = not RemoteExecutionConfig::RemoteAddress(); + return serve_server->Run(*serve_config, serve, with_execute) + ? kExitSuccess + : kExitFailure; } - return kExitSuccess; + return kExitFailure; } // If no execution endpoint was given, the client should default to the -- cgit v1.2.3