mirror of
https://github.com/google/cdc-file-transfer.git
synced 2026-09-13 09:32:30 +03:00
[cdc_rsync] Use any available server port (#94)
Instead of calling netstat on the remote device to detect available ports, simply call bind with port 0 to bind to any available port. Since the port is not yet known when cdc_rsync_server.exe is called, port forwarding needs to be started AFTER the server reports its port.
This commit is contained in:
@@ -78,14 +78,9 @@ class CdcRsyncClient {
|
||||
absl::Status Run();
|
||||
|
||||
private:
|
||||
// Finds available local and remote ports for port forwarding.
|
||||
// May update |server_arch| by properly detecting the architecture and retry
|
||||
// if the architecture was guessed, i.e. if |server_arch|->IsGuess() is true.
|
||||
absl::StatusOr<int> FindAvailablePort(ServerArch* server_arch);
|
||||
|
||||
// Starts the server process. If the method returns a status with tag
|
||||
// |kTagDeployServer|, Run() calls DeployServer() and tries again.
|
||||
absl::Status StartServer(int port, const ServerArch& arch);
|
||||
absl::Status StartServer(const ServerArch& arch);
|
||||
|
||||
// Stops the server process.
|
||||
absl::Status StopServer();
|
||||
@@ -129,6 +124,9 @@ class CdcRsyncClient {
|
||||
// Stops the zstd compression stream.
|
||||
absl::Status StopCompressionStream();
|
||||
|
||||
// Returns true if the target is a remote target.
|
||||
bool IsRemoteConnection() const { return remote_util_ != nullptr; }
|
||||
|
||||
Options options_;
|
||||
std::vector<std::string> sources_;
|
||||
const std::string destination_;
|
||||
@@ -143,10 +141,11 @@ class CdcRsyncClient {
|
||||
std::unique_ptr<ZstdStream> compression_stream_;
|
||||
|
||||
std::unique_ptr<Process> server_process_;
|
||||
std::unique_ptr<Process> port_forwarding_process_;
|
||||
std::string server_output_; // Written in a background thread. Do not access
|
||||
std::string server_error_; // while the server process is active.
|
||||
int server_exit_code_ = 0;
|
||||
std::atomic_bool is_server_listening_{false};
|
||||
std::atomic_int server_listen_port_{0};
|
||||
bool is_server_error_ = false;
|
||||
|
||||
// All source files found on the client.
|
||||
|
||||
Reference in New Issue
Block a user