2023-10-25 00:43:36 -04:00
|
|
|
#pragma once
|
|
|
|
///@file
|
|
|
|
|
2023-04-17 13:40:46 -04:00
|
|
|
#include "remote-store.hh"
|
|
|
|
#include "worker-protocol.hh"
|
2024-05-23 16:40:05 -04:00
|
|
|
#include "worker-protocol-connection.hh"
|
2023-04-17 12:14:15 -04:00
|
|
|
#include "pool.hh"
|
2023-04-17 13:40:46 -04:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bidirectional connection (send and receive) used by the Remote Store
|
|
|
|
* implementation.
|
|
|
|
*
|
|
|
|
* Contains `Source` and `Sink` for actual communication, along with
|
|
|
|
* other information learned when negotiating the connection.
|
|
|
|
*/
|
2024-05-23 16:40:05 -04:00
|
|
|
struct RemoteStore::Connection : WorkerProto::BasicClientConnection,
|
|
|
|
WorkerProto::ClientHandshakeInfo
|
2023-04-17 13:40:46 -04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Time this connection was established.
|
|
|
|
*/
|
|
|
|
std::chrono::time_point<std::chrono::steady_clock> startTime;
|
|
|
|
};
|
|
|
|
|
2023-04-17 12:14:15 -04:00
|
|
|
/**
|
|
|
|
* A wrapper around Pool<RemoteStore::Connection>::Handle that marks
|
|
|
|
* the connection as bad (causing it to be closed) if a non-daemon
|
|
|
|
* exception is thrown before the handle is closed. Such an exception
|
|
|
|
* causes a deviation from the expected protocol and therefore a
|
|
|
|
* desynchronization between the client and daemon.
|
|
|
|
*/
|
|
|
|
struct RemoteStore::ConnectionHandle
|
|
|
|
{
|
|
|
|
Pool<RemoteStore::Connection>::Handle handle;
|
|
|
|
bool daemonException = false;
|
|
|
|
|
|
|
|
ConnectionHandle(Pool<RemoteStore::Connection>::Handle && handle)
|
|
|
|
: handle(std::move(handle))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ConnectionHandle(ConnectionHandle && h)
|
|
|
|
: handle(std::move(h.handle))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~ConnectionHandle();
|
|
|
|
|
|
|
|
RemoteStore::Connection & operator * () { return *handle; }
|
|
|
|
RemoteStore::Connection * operator -> () { return &*handle; }
|
|
|
|
|
|
|
|
void processStderr(Sink * sink = 0, Source * source = 0, bool flush = true);
|
|
|
|
|
|
|
|
void withFramedSink(std::function<void(Sink & sink)> fun);
|
|
|
|
};
|
|
|
|
|
2023-04-17 13:40:46 -04:00
|
|
|
}
|