mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Remove deprecated comms functions
PiperOrigin-RevId: 567239465 Change-Id: Ic890404fa8b7e9797b2399a3b346c1339fbe133a
This commit is contained in:
parent
9a985f91a7
commit
4ae281b6a2
|
@ -109,9 +109,6 @@ socklen_t CreateSockaddrUn(const std::string& socket_name, bool abstract_uds,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Comms::Comms(const std::string& socket_name, bool abstract_uds)
|
|
||||||
: name_(socket_name), abstract_uds_(abstract_uds) {}
|
|
||||||
|
|
||||||
Comms::Comms(int fd, absl::string_view name) : connection_fd_(fd) {
|
Comms::Comms(int fd, absl::string_view name) : connection_fd_(fd) {
|
||||||
// Generate a unique and meaningful socket name for this FD.
|
// Generate a unique and meaningful socket name for this FD.
|
||||||
// Note: getpid()/gettid() are non-blocking syscalls.
|
// Note: getpid()/gettid() are non-blocking syscalls.
|
||||||
|
@ -163,23 +160,6 @@ absl::Status ListeningComms::Listen() {
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Comms::Listen() {
|
|
||||||
if (IsConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::StatusOr<ListeningComms> listening_comms =
|
|
||||||
ListeningComms::Create(name_, abstract_uds_);
|
|
||||||
if (!listening_comms.ok()) {
|
|
||||||
SAPI_RAW_LOG(ERROR, "Listening failed: %s",
|
|
||||||
std::string(listening_comms.status().message()).c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
listening_comms_ =
|
|
||||||
std::make_unique<ListeningComms>(*std::move(listening_comms));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::StatusOr<Comms> ListeningComms::Accept() {
|
absl::StatusOr<Comms> ListeningComms::Accept() {
|
||||||
sockaddr_un suc;
|
sockaddr_un suc;
|
||||||
socklen_t len = sizeof(suc);
|
socklen_t len = sizeof(suc);
|
||||||
|
@ -197,25 +177,6 @@ absl::StatusOr<Comms> ListeningComms::Accept() {
|
||||||
return Comms(connection_fd, socket_name_);
|
return Comms(connection_fd, socket_name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Comms::Accept() {
|
|
||||||
if (IsConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listening_comms_ == nullptr) {
|
|
||||||
SAPI_RAW_LOG(ERROR, "Comms::Listen needs to be called first");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::StatusOr<Comms> comms = listening_comms_->Accept();
|
|
||||||
if (!comms.ok()) {
|
|
||||||
SAPI_RAW_LOG(ERROR, "%s", std::string(comms.status().message()).c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*this = *std::move(comms);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::StatusOr<Comms> Comms::Connect(const std::string& socket_name,
|
absl::StatusOr<Comms> Comms::Connect(const std::string& socket_name,
|
||||||
bool abstract_uds) {
|
bool abstract_uds) {
|
||||||
FDCloser connection_fd(socket(AF_UNIX, SOCK_STREAM, 0)); // Non-blocking
|
FDCloser connection_fd(socket(AF_UNIX, SOCK_STREAM, 0)); // Non-blocking
|
||||||
|
@ -240,21 +201,6 @@ absl::StatusOr<Comms> Comms::Connect(const std::string& socket_name,
|
||||||
return Comms(connection_fd.Release(), socket_name);
|
return Comms(connection_fd.Release(), socket_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Comms::Connect() {
|
|
||||||
if (IsConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::StatusOr<Comms> connected = Connect(name_, abstract_uds_);
|
|
||||||
if (!connected.ok()) {
|
|
||||||
SAPI_RAW_LOG(ERROR, "%s",
|
|
||||||
std::string(connected.status().message()).c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*this = *std::move(connected);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Comms::Terminate() {
|
void Comms::Terminate() {
|
||||||
state_ = State::kTerminated;
|
state_ = State::kTerminated;
|
||||||
|
|
||||||
|
|
|
@ -98,12 +98,6 @@ class Comms {
|
||||||
static absl::StatusOr<Comms> Connect(const std::string& socket_name,
|
static absl::StatusOr<Comms> Connect(const std::string& socket_name,
|
||||||
bool abstract_uds = true);
|
bool abstract_uds = true);
|
||||||
|
|
||||||
// This object will have to be connected later on.
|
|
||||||
// When not specified the constructor uses abstract unix domain sockets.
|
|
||||||
ABSL_DEPRECATED(
|
|
||||||
"Use ListeningComms or absl::StatusOr<Comms> Connect() instead")
|
|
||||||
explicit Comms(const std::string& socket_name, bool abstract_uds = true);
|
|
||||||
|
|
||||||
Comms(Comms&& other) { *this = std::move(other); }
|
Comms(Comms&& other) { *this = std::move(other); }
|
||||||
Comms& operator=(Comms&& other) {
|
Comms& operator=(Comms&& other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
|
@ -126,20 +120,6 @@ class Comms {
|
||||||
|
|
||||||
~Comms();
|
~Comms();
|
||||||
|
|
||||||
// Binds to an address and make it listen to connections.
|
|
||||||
ABSL_DEPRECATED("Use ListeningComms::Create() instead")
|
|
||||||
bool Listen();
|
|
||||||
|
|
||||||
// Accepts the connection.
|
|
||||||
ABSL_DEPRECATED("Use ListeningComms::Accept() instead")
|
|
||||||
bool Accept();
|
|
||||||
|
|
||||||
// Connects to a remote socket.
|
|
||||||
ABSL_DEPRECATED(
|
|
||||||
"Use absl::StatusOr<Comms> Comms::Connect(std::string& socket_name, bool "
|
|
||||||
"abstract_uds) instead")
|
|
||||||
bool Connect();
|
|
||||||
|
|
||||||
// Terminates all underlying file descriptors, and sets the status of the
|
// Terminates all underlying file descriptors, and sets the status of the
|
||||||
// Comms object to TERMINATED.
|
// Comms object to TERMINATED.
|
||||||
void Terminate();
|
void Terminate();
|
||||||
|
|
|
@ -371,12 +371,4 @@ TEST(CommsTest, TestSendRecvBytes) {
|
||||||
HandleCommunication(a, b);
|
HandleCommunication(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We cannot test this in the Client or Server tests, as the endpoint needs to
|
|
||||||
// be unconnected.
|
|
||||||
TEST(CommsTest, TestMsgSize) {
|
|
||||||
// There will be no actual connection to this socket.
|
|
||||||
const std::string socket_name = "sandbox2_comms_msg_size_test";
|
|
||||||
Comms c(socket_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sandbox2
|
} // namespace sandbox2
|
||||||
|
|
Loading…
Reference in New Issue
Block a user