diff --git a/sandboxed_api/sandbox2/comms.h b/sandboxed_api/sandbox2/comms.h index 8211519..db44282 100644 --- a/sandboxed_api/sandbox2/comms.h +++ b/sandboxed_api/sandbox2/comms.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "absl/base/attributes.h" #include "absl/status/status.h" @@ -86,6 +87,16 @@ class Comms { // When not specified the constructor uses abstract unix domain sockets. explicit Comms(const std::string& socket_name, bool abstract_uds = true); + Comms(Comms&& other) { *this = std::move(other); } + Comms& operator=(Comms&& other) { + if (this != &other) { + using std::swap; + swap(*this, other); + other.Terminate(); + } + return *this; + } + Comms(const Comms&) = delete; Comms& operator=(const Comms&) = delete; @@ -175,6 +186,20 @@ class Comms { bool RecvStatus(absl::Status* status); bool SendStatus(const absl::Status& status); + void Swap(Comms& other) { + if (this == &other) { + return; + } + using std::swap; + swap(socket_name_, other.socket_name_); + swap(abstract_uds_, other.abstract_uds_); + swap(connection_fd_, other.connection_fd_); + swap(bind_fd_, other.bind_fd_); + swap(state_, other.state_); + } + + friend void swap(Comms& x, Comms& y) { return x.Swap(y); } + private: friend class Client;