-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
166 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "nixd-config.h" | ||
|
||
#include "EvalClient.h" | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/util/ForkPiped.h" | ||
|
||
#include <bc/Read.h> | ||
#include <bc/Write.h> | ||
|
||
namespace nixd { | ||
|
||
using namespace rpc; | ||
using namespace nixd::util; | ||
|
||
template <class T> using M = Message<T>; | ||
|
||
std::unique_ptr<EvalClient> EvalClient::create(int &Fail) { | ||
int In; | ||
int Out; | ||
int Err; | ||
|
||
pid_t Child = forkPiped(In, Out, Err); | ||
if (Child == 0) { | ||
execl(NIXD_LIBEXEC "/nix-node-eval", "nix-node-eval", nullptr); | ||
exit(-1); | ||
} else if (Child < 0) { | ||
// Error. | ||
Fail = Child; | ||
return nullptr; | ||
} | ||
|
||
Fail = 0; | ||
// Parent process. | ||
auto Proc = std::make_unique<PipedProc>(Child, In, Out, Err); | ||
return std::make_unique<EvalClient>(Out, In, std::move(Proc)); | ||
} | ||
|
||
void EvalClient::registerBC(const RegisterBCParams &Params) { | ||
sendPacket<M<RegisterBCParams>>({RPCKind::RegisterBC, Params}); | ||
} | ||
|
||
ExprValueResponse EvalClient::exprValue(const ExprValueParams &Params) { | ||
sendPacket<M<ExprValueParams>>({RPCKind::ExprValue, Params}); | ||
return recvPacket<ExprValueResponse>(); | ||
} | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/rpc/Transport.h" | ||
#include "nixd/util/PipedProc.h" | ||
|
||
#include <memory> | ||
|
||
namespace nixd { | ||
|
||
class EvalClient : public rpc::Transport { | ||
// Owned process of the evaluator | ||
std::unique_ptr<util::PipedProc> Proc; | ||
void handleInbound(const std::vector<char> &Buf) override{}; | ||
|
||
public: | ||
EvalClient(int InboundFD, int OutboundFD, | ||
std::unique_ptr<util::PipedProc> Proc) | ||
: rpc::Transport(InboundFD, OutboundFD), Proc(std::move(Proc)) {} | ||
|
||
virtual ~EvalClient() = default; | ||
|
||
/// Lanch nix-node-eval, with properly handled file descriptors. | ||
/// System-wide errno will be written into "Fail" variable and thus cannot be | ||
/// discarded. | ||
static std::unique_ptr<EvalClient> create(int &Fail); | ||
|
||
void registerBC(const rpc::RegisterBCParams &Params); | ||
|
||
rpc::ExprValueResponse exprValue(const rpc::ExprValueParams &Params); | ||
|
||
util::PipedProc *proc() { return Proc.get(); } | ||
}; | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters