mirror of
https://github.com/google/cdc-file-transfer.git
synced 2026-09-13 09:32:30 +03:00
[cdc_rsync] Fix issue with IPV6 localhosts (#93)
Fixes an issue with port forwarding when localhost on the remote system maps to the IPV6 localhost. In that case the server would time out on accept() since it creates an IPV4 socket, so the connection is never established. Also allows passing in port 0, so that it will auto-detect an available port. This will be used in a future CL to remove the necessity of running netstat/ss.
This commit is contained in:
@@ -18,8 +18,11 @@
|
||||
#define CDC_RSYNC_SERVER_SERVER_SOCKET_H_
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "cdc_rsync/base/socket.h"
|
||||
|
||||
struct addrinfo;
|
||||
|
||||
namespace cdc_ft {
|
||||
|
||||
class ServerSocket : public Socket {
|
||||
@@ -28,7 +31,9 @@ class ServerSocket : public Socket {
|
||||
~ServerSocket();
|
||||
|
||||
// Starts listening for connections on |port|.
|
||||
absl::Status StartListening(int port);
|
||||
// Passing 0 as port will bind to any available port.
|
||||
// Returns the port that was bound to.
|
||||
absl::StatusOr<int> StartListening(int port);
|
||||
|
||||
// Stops listening for connections. No-op if already stopped/never started.
|
||||
void StopListening();
|
||||
@@ -50,6 +55,11 @@ class ServerSocket : public Socket {
|
||||
size_t* bytes_received) override;
|
||||
|
||||
private:
|
||||
// Called by StartListening() for a specific IPV4 or IPV6 |addr_info|.
|
||||
// Passing 0 as port will bind to any available port.
|
||||
// Returns the port that was bound to.
|
||||
absl::StatusOr<int> StartListeningInternal(int port, addrinfo* addr);
|
||||
|
||||
std::unique_ptr<struct ServerSocketInfo> socket_info_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user