mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 15:02:42 +01:00
The short answer for why we need to do this is so we can consistently do `#include "nix/..."`. Without this change, there are ways to still make that work, but they are hacky, and they have downsides such as making it harder to make sure headers from the wrong Nix library (e..g. `libnixexpr` headers in `libnixutil`) aren't being used. The C API alraedy used `nix_api_*`, so its headers are *not* put in subdirectories accordingly. Progress on #7876 We resisted doing this for a while because it would be annoying to not have the header source file pairs close by / easy to change file path/name from one to the other. But I am ameliorating that with symlinks in the next commit.
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#pragma once
|
|
///@file
|
|
|
|
#include "nix/remote-store.hh"
|
|
#include "nix/worker-protocol.hh"
|
|
#include "nix/worker-protocol-connection.hh"
|
|
#include "nix/pool.hh"
|
|
|
|
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.
|
|
*/
|
|
struct RemoteStore::Connection : WorkerProto::BasicClientConnection,
|
|
WorkerProto::ClientHandshakeInfo
|
|
{
|
|
/**
|
|
* Time this connection was established.
|
|
*/
|
|
std::chrono::time_point<std::chrono::steady_clock> startTime;
|
|
};
|
|
|
|
/**
|
|
* 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) noexcept
|
|
: 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, bool block = true);
|
|
|
|
void withFramedSink(std::function<void(Sink & sink)> fun);
|
|
};
|
|
|
|
}
|