mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-05-02 23:53:06 +03:00
[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:
@@ -26,6 +26,14 @@ class Socket {
|
||||
Socket() = default;
|
||||
virtual ~Socket() = default;
|
||||
|
||||
// Calls WSAStartup() on Windows, no-op on Linux.
|
||||
// Must be called before using sockets.
|
||||
static absl::Status Initialize();
|
||||
|
||||
// Calls WSACleanup() on Windows, no-op on Linux.
|
||||
// Must be called after using sockets.
|
||||
static absl::Status Shutdown();
|
||||
|
||||
// Send data to the socket.
|
||||
virtual absl::Status Send(const void* buffer, size_t size) = 0;
|
||||
|
||||
@@ -40,6 +48,12 @@ class Socket {
|
||||
size_t* bytes_received) = 0;
|
||||
};
|
||||
|
||||
// Convenience class that calls Shutdown() on destruction. Logs on errors.
|
||||
class SocketFinalizer {
|
||||
public:
|
||||
~SocketFinalizer();
|
||||
};
|
||||
|
||||
} // namespace cdc_ft
|
||||
|
||||
#endif // CDC_RSYNC_BASE_SOCKET_H_
|
||||
|
||||
Reference in New Issue
Block a user