[common] Add support for ClientSocket on Linux (#97)

Uses the abstractions written for ServerSocket in ClientSocket, so
that it builds on Linux. Also adds a method to poll for connections
and uses that in cdc_rsync. Similar code will be used in cdc_fuse_fs
to wait for a connection in a future CL.
This commit is contained in:
Lutz Justen
2023-05-27 21:18:13 +02:00
committed by GitHub
parent 26ff93489e
commit 678ee0ffaf
6 changed files with 185 additions and 143 deletions

View File

@@ -300,24 +300,9 @@ absl::Status CdcRsyncClient::StartServer(const ServerArch& arch) {
"Failed to start cdc_rsync_server process");
}
// Poll the connection to the socket with port |local_port| until the port
// forwarding connection is set up.
timeout_timer.Reset();
for (;;) {
assert(local_port != 0);
status = socket_.Connect(local_port);
if (status.ok()) {
break;
}
if (timeout_timer.ElapsedSeconds() > options_.connection_timeout_sec) {
return SetTag(
absl::DeadlineExceededError("Timeout while connecting to server"),
Tag::kConnectionTimeout);
}
Util::Sleep(10);
}
// Wait for port forwarding to be up.
RETURN_IF_ERROR(ClientSocket::WaitForConnection(
local_port, absl::Seconds(options_.connection_timeout_sec)));
server_process_ = std::move(srv_process);
port_forwarding_process_ = std::move(fwd_process);