[cdc_rsync] Add support for ServerSocket on Windows (#48)

Makes ServerSocket multi-platform, mainly by working around some small
API differences. The code is largely the same, there should be no
differences on Linux.

Also moves WSAStartup() and WSACleanup() up to the Socket level as
static methods because it's used by both ClientSocket and ServerSocket,
and because it doesn't make sense to do that in the socket class as
that would prevent one from using several sockets.
This commit is contained in:
Lutz Justen
2022-12-19 23:02:36 +01:00
committed by GitHub
parent d8c2b5906e
commit a138fb55c4
13 changed files with 242 additions and 84 deletions

View File

@@ -148,10 +148,7 @@ PathFilter::Rule::Type ToInternalType(
CdcRsyncServer::CdcRsyncServer() = default;
CdcRsyncServer::~CdcRsyncServer() {
message_pump_.reset();
socket_.reset();
}
CdcRsyncServer::~CdcRsyncServer() = default;
bool CdcRsyncServer::CheckComponents(
const std::vector<GameletComponent>& components) {
@@ -173,8 +170,14 @@ bool CdcRsyncServer::CheckComponents(
}
absl::Status CdcRsyncServer::Run(int port) {
absl::Status status = Socket::Initialize();
if (!status.ok()) {
return WrapStatus(status, "Failed to initialize sockets");
}
socket_finalizer_ = std::make_unique<SocketFinalizer>();
socket_ = std::make_unique<ServerSocket>();
absl::Status status = socket_->StartListening(port);
status = socket_->StartListening(port);
if (!status.ok()) {
return WrapStatus(status, "Failed to start listening on port %i", port);
}
@@ -563,7 +566,7 @@ absl::Status CdcRsyncServer::HandleSendMissingFileData() {
// Verify that there is no directory existing with the same name.
if (path::Exists(filepath) && path::DirExists(filepath)) {
assert(!diff_.extraneous_dirs.empty());
absl::Status status = path::RemoveFile(filepath);
status = path::RemoveFile(filepath);
if (!status.ok()) {
return WrapStatus(
status, "Failed to remove folder '%s' before creating file '%s'",