libstore: asyncify RemoteStore::openConnection
Change-Id: Icc7e705314b9a099687c37859700959139840631
This commit is contained in:
@@ -55,21 +55,23 @@ RemoteStore::RemoteStore(const RemoteStoreConfig & config)
|
||||
}
|
||||
|
||||
|
||||
ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper()
|
||||
{
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> RemoteStore::openConnectionWrapper()
|
||||
try {
|
||||
if (failed)
|
||||
throw Error("opening a connection to remote store '%s' previously failed", getUri());
|
||||
try {
|
||||
return openConnection();
|
||||
co_return TRY_AWAIT(openConnection());
|
||||
} catch (...) {
|
||||
failed = true;
|
||||
throw;
|
||||
}
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> RemoteStore::openAndInitConnection()
|
||||
try {
|
||||
auto conn = openConnection();
|
||||
auto conn = TRY_AWAIT(openConnection());
|
||||
try {
|
||||
TRY_AWAIT(initConnection(*conn));
|
||||
co_return conn;
|
||||
|
||||
@@ -178,11 +178,11 @@ public:
|
||||
|
||||
struct Connection;
|
||||
|
||||
ref<Connection> openConnectionWrapper();
|
||||
kj::Promise<Result<ref<Connection>>> openConnectionWrapper();
|
||||
|
||||
protected:
|
||||
|
||||
virtual ref<Connection> openConnection() = 0;
|
||||
virtual kj::Promise<Result<ref<Connection>>> openConnection() = 0;
|
||||
|
||||
kj::Promise<Result<ref<Connection>>> openAndInitConnection();
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
ref<RemoteStore::Connection> openConnection() override;
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> openConnection() override;
|
||||
|
||||
std::string host;
|
||||
|
||||
@@ -119,8 +119,8 @@ protected:
|
||||
};
|
||||
};
|
||||
|
||||
ref<RemoteStore::Connection> SSHStore::openConnection()
|
||||
{
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> SSHStore::openConnection()
|
||||
try {
|
||||
auto conn = make_ref<Connection>();
|
||||
|
||||
std::string command = config_.remoteProgram + " --stdio";
|
||||
@@ -128,7 +128,9 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
|
||||
command += " --store " + shellEscape(config_.remoteStore.get());
|
||||
|
||||
conn->sshConn = ssh.startCommand(command);
|
||||
return conn;
|
||||
return {conn};
|
||||
} catch (...) {
|
||||
return {result::current_exception()};
|
||||
}
|
||||
|
||||
void registerSSHStore() {
|
||||
|
||||
@@ -78,8 +78,8 @@ static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list<
|
||||
throw Error("could not connect to any lix socket (tried %s)", concatStringsSep(", ", paths));
|
||||
}
|
||||
|
||||
ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
||||
{
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> UDSRemoteStore::openConnection()
|
||||
try {
|
||||
auto conn = make_ref<Connection>();
|
||||
|
||||
/* Connect to a daemon that does the privileged work for us. */
|
||||
@@ -109,7 +109,9 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
||||
|
||||
conn->startTime = std::chrono::steady_clock::now();
|
||||
|
||||
return conn;
|
||||
co_return conn;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
ref<RemoteStore::Connection> openConnection() override;
|
||||
kj::Promise<Result<ref<RemoteStore::Connection>>> openConnection() override;
|
||||
std::optional<std::string> path;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -531,7 +531,7 @@ daemonInstance(AsyncIoRoot & aio, std::optional<TrustedFlag> forceTrustClientOpt
|
||||
*/
|
||||
static void forwardStdioConnection(AsyncIoRoot & aio, RemoteStore & store)
|
||||
{
|
||||
auto conn = store.openConnectionWrapper();
|
||||
auto conn = aio.blockOn(store.openConnectionWrapper());
|
||||
auto connSocket = AIO().lowLevelProvider.wrapSocketFd(conn->getFD());
|
||||
auto asyncStdin = AIO().lowLevelProvider.wrapInputFd(STDIN_FILENO);
|
||||
auto asyncStdout = AIO().lowLevelProvider.wrapOutputFd(STDOUT_FILENO);
|
||||
|
||||
Reference in New Issue
Block a user