diff options
author | eldritch horrors <pennae@lix.systems> | 2024-05-18 02:35:34 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-07-16 00:57:42 +0000 |
commit | a5d1f698417dff4e470eb94c38ad6c4e5ebf38ff (patch) | |
tree | 116b887a80fd96f9008bc55c872a24ef1955ca2f /src/libstore/serve-protocol.cc | |
parent | 5271424d14241ec5cbe7ab3bda85ddeb486cff76 (diff) |
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
Diffstat (limited to 'src/libstore/serve-protocol.cc')
-rw-r--r-- | src/libstore/serve-protocol.cc | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/src/libstore/serve-protocol.cc b/src/libstore/serve-protocol.cc index 603137c81..723a494a5 100644 --- a/src/libstore/serve-protocol.cc +++ b/src/libstore/serve-protocol.cc @@ -34,23 +34,22 @@ BuildResult ServeProto::Serialise<BuildResult>::read(const Store & store, ServeP return status; } -void ServeProto::Serialise<BuildResult>::write(const Store & store, ServeProto::WriteConn conn, const BuildResult & status) +WireFormatGenerator ServeProto::Serialise<BuildResult>::write(const Store & store, ServeProto::WriteConn conn, const BuildResult & status) { - conn.to - << status.status - << status.errorMsg; - - if (GET_PROTOCOL_MINOR(conn.version) >= 3) - conn.to - << status.timesBuilt - << status.isNonDeterministic - << status.startTime - << status.stopTime; + co_yield status.status; + co_yield status.errorMsg; + + if (GET_PROTOCOL_MINOR(conn.version) >= 3) { + co_yield status.timesBuilt; + co_yield status.isNonDeterministic; + co_yield status.startTime; + co_yield status.stopTime; + } if (GET_PROTOCOL_MINOR(conn.version) >= 6) { DrvOutputs builtOutputs; for (auto & [output, realisation] : status.builtOutputs) builtOutputs.insert_or_assign(realisation.id, realisation); - ServeProto::write(store, conn, builtOutputs); + co_yield ServeProto::write(store, conn, builtOutputs); } } @@ -80,21 +79,19 @@ UnkeyedValidPathInfo ServeProto::Serialise<UnkeyedValidPathInfo>::read(const Sto return info; } -void ServeProto::Serialise<UnkeyedValidPathInfo>::write(const Store & store, WriteConn conn, const UnkeyedValidPathInfo & info) +WireFormatGenerator ServeProto::Serialise<UnkeyedValidPathInfo>::write(const Store & store, WriteConn conn, const UnkeyedValidPathInfo & info) { - conn.to - << (info.deriver ? store.printStorePath(*info.deriver) : ""); + co_yield (info.deriver ? store.printStorePath(*info.deriver) : ""); - ServeProto::write(store, conn, info.references); + co_yield ServeProto::write(store, conn, info.references); // !!! Maybe we want compression? - conn.to - << info.narSize // downloadSize, lie a little - << info.narSize; - if (GET_PROTOCOL_MINOR(conn.version) >= 4) - conn.to - << info.narHash.to_string(Base32, true) - << renderContentAddress(info.ca) - << info.sigs; + co_yield info.narSize; // downloadSize, lie a little + co_yield info.narSize; + if (GET_PROTOCOL_MINOR(conn.version) >= 4) { + co_yield info.narHash.to_string(Base32, true); + co_yield renderContentAddress(info.ca); + co_yield info.sigs; + } } } |