[cdc_rsync] Use ephemeral port on client (#96)

Instead of calling netstat locally to find out available ports in a
tight range, call bind() with port zero to find an available ephemeral
port. This is faster and much simpler, and will eventually help
getting rid of PortManager.

Also fixes issues with running SSH commands on Windows when the remote
shell is Powershell (aka Backslash Bingo).
This commit is contained in:
Lutz Justen
2023-04-08 20:19:01 +02:00
committed by GitHub
parent 09cee120b2
commit 26ff93489e
10 changed files with 39 additions and 134 deletions

View File

@@ -125,6 +125,12 @@ ServerSocket::~ServerSocket() {
StopListening();
}
// static
absl::StatusOr<int> ServerSocket::FindAvailablePort() {
ServerSocket socket;
return socket.StartListening(0);
}
absl::StatusOr<int> ServerSocket::StartListening(int port) {
if (socket_info_->listen_sock != kInvalidSocket) {
return MakeStatus("Already listening");
@@ -246,7 +252,7 @@ absl::StatusOr<int> ServerSocket::StartListeningInternal(int port,
void ServerSocket::StopListening() {
Close(&socket_info_->listen_sock);
LOG_INFO("Stopped listening.");
LOG_DEBUG("Stopped listening.");
}
absl::Status ServerSocket::WaitForConnection() {
@@ -268,7 +274,7 @@ absl::Status ServerSocket::WaitForConnection() {
void ServerSocket::Disconnect() {
Close(&socket_info_->conn_sock);
LOG_INFO("Disconnected");
LOG_DEBUG("Disconnected");
}
absl::Status ServerSocket::ShutdownSendingEnd() {