From a5d1f698417dff4e470eb94c38ad6c4e5ebf38ff Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 18 May 2024 02:35:34 +0200 Subject: libstore: generatorize protocol serializers this is cursed. deeply and profoundly cursed. under NO CIRCUMSTANCES must protocol serializer helpers be applied to temporaries! doing so will inevitably cause dangling references and cause the entire thing to crash. we need to do this even so to get rid of boost coroutines, and likewise to encapsulate the serializers we suffer today at least a little bit to allow a gradual migration to an actual IPC protocol. (this isn't a problem that's unique to generators. c++ coroutines in general cannot safely take references to arbitrary temporaries since c++ does not have a lifetime system that can make this safe. -sigh-) Change-Id: I2921ba451e04d86798752d140885d3c5cc08e146 --- src/libstore/daemon.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/libstore/daemon.cc') diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index cae5b54fd..46500e7d3 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -291,7 +291,7 @@ static void performOp(TunnelLogger * logger, ref store, } auto res = store->queryValidPaths(paths, substitute); logger->stopWork(); - WorkerProto::write(*store, wconn, res); + wconn.to << WorkerProto::write(*store, wconn, res); break; } @@ -300,7 +300,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); auto res = store->querySubstitutablePaths(paths); logger->stopWork(); - WorkerProto::write(*store, wconn, res); + wconn.to << WorkerProto::write(*store, wconn, res); break; } @@ -365,7 +365,7 @@ static void performOp(TunnelLogger * logger, ref store, #pragma GCC diagnostic pop logger->stopWork(); - WorkerProto::write(*store, wconn, paths); + wconn.to << WorkerProto::write(*store, wconn, paths); break; } @@ -385,7 +385,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); auto outputs = store->queryPartialDerivationOutputMap(path); logger->stopWork(); - WorkerProto::write(*store, wconn, outputs); + wconn.to << WorkerProto::write(*store, wconn, outputs); break; } @@ -432,7 +432,7 @@ static void performOp(TunnelLogger * logger, ref store, }(); logger->stopWork(); - WorkerProto::Serialise::write(*store, wconn, *pathInfo); + wconn.to << WorkerProto::Serialise::write(*store, wconn, *pathInfo); } else { HashType hashAlgo; std::string baseName; @@ -565,7 +565,7 @@ static void performOp(TunnelLogger * logger, ref store, auto results = store->buildPathsWithResults(drvs, mode); logger->stopWork(); - WorkerProto::write(*store, wconn, results); + wconn.to << WorkerProto::write(*store, wconn, results); break; } @@ -643,7 +643,7 @@ static void performOp(TunnelLogger * logger, ref store, auto res = store->buildDerivation(drvPath, drv, buildMode); logger->stopWork(); - WorkerProto::write(*store, wconn, res); + wconn.to << WorkerProto::write(*store, wconn, res); break; } @@ -777,7 +777,7 @@ static void performOp(TunnelLogger * logger, ref store, else { to << 1 << (i->second.deriver ? store->printStorePath(*i->second.deriver) : ""); - WorkerProto::write(*store, wconn, i->second.references); + wconn.to << WorkerProto::write(*store, wconn, i->second.references); to << i->second.downloadSize << i->second.narSize; } @@ -800,7 +800,7 @@ static void performOp(TunnelLogger * logger, ref store, for (auto & i : infos) { to << store->printStorePath(i.first) << (i.second.deriver ? store->printStorePath(*i.second.deriver) : ""); - WorkerProto::write(*store, wconn, i.second.references); + wconn.to << WorkerProto::write(*store, wconn, i.second.references); to << i.second.downloadSize << i.second.narSize; } break; @@ -810,7 +810,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); auto paths = store->queryAllValidPaths(); logger->stopWork(); - WorkerProto::write(*store, wconn, paths); + wconn.to << WorkerProto::write(*store, wconn, paths); break; } @@ -827,7 +827,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->stopWork(); if (info) { to << 1; - WorkerProto::write(*store, wconn, static_cast(*info)); + wconn.to << WorkerProto::write(*store, wconn, static_cast(*info)); } else { to << 0; } @@ -922,9 +922,9 @@ static void performOp(TunnelLogger * logger, ref store, uint64_t downloadSize, narSize; store->queryMissing(targets, willBuild, willSubstitute, unknown, downloadSize, narSize); logger->stopWork(); - WorkerProto::write(*store, wconn, willBuild); - WorkerProto::write(*store, wconn, willSubstitute); - WorkerProto::write(*store, wconn, unknown); + wconn.to << WorkerProto::write(*store, wconn, willBuild); + wconn.to << WorkerProto::write(*store, wconn, willSubstitute); + wconn.to << WorkerProto::write(*store, wconn, unknown); to << downloadSize << narSize; break; } @@ -952,11 +952,11 @@ static void performOp(TunnelLogger * logger, ref store, if (GET_PROTOCOL_MINOR(clientVersion) < 31) { std::set outPaths; if (info) outPaths.insert(info->outPath); - WorkerProto::write(*store, wconn, outPaths); + wconn.to << WorkerProto::write(*store, wconn, outPaths); } else { std::set realisations; if (info) realisations.insert(*info); - WorkerProto::write(*store, wconn, realisations); + wconn.to << WorkerProto::write(*store, wconn, realisations); } break; } @@ -1037,7 +1037,7 @@ void processConnection( ? store->isTrustedClient() : std::optional { NotTrusted }; WorkerProto::WriteConn wconn {to, clientVersion}; - WorkerProto::write(*store, wconn, temp); + wconn.to << WorkerProto::write(*store, wconn, temp); } /* Send startup error messages to the client. */ -- cgit v1.2.3