Explicit Comms constructor with default params

This is to abstract the FD number away, so that we can change the way the FD number is chosen/communicated.

PiperOrigin-RevId: 479282707
Change-Id: Ic6726bcd0a17e97bde60804476ecbca2ffbf6525
This commit is contained in:
Wiktor Garbacz 2022-10-06 04:55:22 -07:00 committed by Copybara-Service
parent 5b61445de9
commit 3198ff06d3

View File

@ -44,6 +44,8 @@ namespace sandbox2 {
class Comms {
public:
struct DefaultConnectionTag {};
// Default tags, custom tags should be <0x80000000.
static constexpr uint32_t kTagBool = 0x80000001;
static constexpr uint32_t kTagInt8 = 0x80000002;
@ -73,6 +75,8 @@ class Comms {
// sandbox2::Comms object at the server-side).
static constexpr int kSandbox2ClientCommsFD = 1023;
static constexpr DefaultConnectionTag kDefaultConnection = {};
// This object will have to be connected later on.
explicit Comms(const std::string& socket_name);
@ -83,6 +87,9 @@ class Comms {
// Takes ownership over fd, which will be closed on object's destruction.
explicit Comms(int fd);
// Instantiates a pre-connected object using the default connection params.
explicit Comms(DefaultConnectionTag) : Comms(kSandbox2ClientCommsFD) {}
~Comms();
// Binds to an address and make it listen to connections.