libstore: asyncify RemoteStore connection setup
without this processStderr cannot be turned into a promise. Change-Id: Ia8ee44e9e2344f61c2c63b787b42f867864c7119
This commit is contained in:
@@ -66,7 +66,7 @@ kj::Promise<Result<ref<RemoteStore::Connection>>> RemoteStore::openAndInitConnec
|
||||
try {
|
||||
auto conn = openConnection();
|
||||
try {
|
||||
initConnection(*conn);
|
||||
TRY_AWAIT(initConnection(*conn));
|
||||
co_return conn;
|
||||
} catch (...) {
|
||||
failed = true;
|
||||
@@ -76,8 +76,8 @@ try {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void RemoteStore::initConnection(Connection & conn)
|
||||
{
|
||||
kj::Promise<Result<void>> RemoteStore::initConnection(Connection & conn)
|
||||
try {
|
||||
/* Send the magic greeting, check for the reply. */
|
||||
try {
|
||||
conn.store = this;
|
||||
@@ -112,12 +112,14 @@ void RemoteStore::initConnection(Connection & conn)
|
||||
throw Error("cannot open connection to remote store '%s': %s", getUri(), e.what());
|
||||
}
|
||||
|
||||
setOptions(conn);
|
||||
TRY_AWAIT(setOptions(conn));
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::setOptions(Connection & conn)
|
||||
{
|
||||
kj::Promise<Result<void>> RemoteStore::setOptions(Connection & conn)
|
||||
try {
|
||||
StringSink command;
|
||||
|
||||
command << WorkerProto::Op::SetOptions
|
||||
@@ -157,9 +159,11 @@ void RemoteStore::setOptions(Connection & conn)
|
||||
conn.to.flush();
|
||||
auto ex = conn.processStderr();
|
||||
if (ex) std::rethrow_exception(ex);
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
|
||||
RemoteStore::ConnectionHandle::~ConnectionHandle()
|
||||
{
|
||||
if (!daemonException && std::uncaught_exceptions()) {
|
||||
@@ -187,7 +191,7 @@ try {
|
||||
|
||||
kj::Promise<Result<void>> RemoteStore::setOptions()
|
||||
try {
|
||||
setOptions(*(TRY_AWAIT(getConnection()).handle));
|
||||
TRY_AWAIT(setOptions(*(TRY_AWAIT(getConnection()).handle)));
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
|
||||
@@ -181,11 +181,11 @@ protected:
|
||||
|
||||
kj::Promise<Result<ref<Connection>>> openAndInitConnection();
|
||||
|
||||
void initConnection(Connection & conn);
|
||||
kj::Promise<Result<void>> initConnection(Connection & conn);
|
||||
|
||||
ref<Pool<Connection>> connections;
|
||||
|
||||
virtual void setOptions(Connection & conn);
|
||||
virtual kj::Promise<Result<void>> setOptions(Connection & conn);
|
||||
|
||||
kj::Promise<Result<void>> setOptions() override;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "lix/libstore/worker-protocol.hh"
|
||||
#include "lix/libutil/pool.hh"
|
||||
#include "lix/libstore/ssh.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/strings.hh"
|
||||
|
||||
namespace nix {
|
||||
@@ -77,7 +78,7 @@ protected:
|
||||
|
||||
SSH ssh;
|
||||
|
||||
void setOptions(RemoteStore::Connection & conn) override
|
||||
kj::Promise<Result<void>> setOptions(RemoteStore::Connection & conn) override
|
||||
{
|
||||
/* TODO Add a way to explicitly ask for some options to be
|
||||
forwarded. One option: A way to query the daemon for its
|
||||
@@ -85,6 +86,7 @@ protected:
|
||||
forward-cores or forward-overridden-cores that only
|
||||
override the requested settings.
|
||||
*/
|
||||
return {result::success()};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user