Skip to content

Commit

Permalink
bp/LSSHandler: move code from DoSpawn() to Handle()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 2, 2024
1 parent c9bc6ed commit 9c89b13
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/bp/LSSHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,7 @@ DoSpawn(SpawnService &service, const char *name,
SocketDescriptor socket,
const TranslateResponse &response)
{
if (response.status != HttpStatus{}) {
if (response.message != nullptr)
throw FmtRuntimeError("Status {} from translation server: {}",
static_cast<unsigned>(response.status),
response.message);

throw FmtRuntimeError("Status {} from translation server",
static_cast<unsigned>(response.status));
}

if (response.execute == nullptr)
throw std::runtime_error("No EXECUTE from translation server");
assert(response.execute != nullptr);

PreparedChildProcess p;
p.stdin_fd = socket.ToFileDescriptor();
Expand All @@ -75,6 +64,17 @@ BpListenStreamStockHandler::Handle(const char *socket_path,
const TranslateResponse &response,
ListenStreamReadyHandler &handler)
{
auto process = DoSpawn(spawn_service, socket_path, socket, response);
return ToDeletePointer(new Process(handler, std::move(process)));
if (response.status != HttpStatus{}) {
if (response.message != nullptr)
throw FmtRuntimeError("Status {} from translation server: {}",
static_cast<unsigned>(response.status),
response.message);

throw FmtRuntimeError("Status {} from translation server",
static_cast<unsigned>(response.status));
} else if (response.execute != nullptr) {
auto process = DoSpawn(spawn_service, socket_path, socket, response);
return ToDeletePointer(new Process(handler, std::move(process)));
} else
throw std::runtime_error("No EXECUTE from translation server");
}

0 comments on commit 9c89b13

Please sign in to comment.