From 09cee120b28da9b88b7a7072fa14943a746dcc73 Mon Sep 17 00:00:00 2001 From: Lutz Justen Date: Fri, 10 Mar 2023 09:17:27 +0100 Subject: [PATCH] [cdc_rsync] Move sockets to common (#95) There are no real changes, just moving files around. Sockets will be used in the future to find available ports in cdc_stream. Therefore, they need to be in common. --- all_files.vcxitems | 28 +++---- cdc_rsync/BUILD | 29 ++----- cdc_rsync/base/BUILD | 29 +------ cdc_rsync/base/cdc_interface_test.cc | 2 +- cdc_rsync/base/message_pump.cc | 2 +- cdc_rsync/base/message_pump_test.cc | 2 +- cdc_rsync/cdc_rsync_client.cc | 2 +- cdc_rsync/cdc_rsync_client.h | 2 +- cdc_rsync/file_finder_and_sender_test.cc | 2 +- cdc_rsync/zstd_stream.h | 2 +- cdc_rsync/zstd_stream_test.cc | 2 +- cdc_rsync_server/BUILD | 26 +------ cdc_rsync_server/cdc_rsync_server.cc | 2 +- .../file_deleter_and_sender_test.cc | 2 +- cdc_rsync_server/unzstd_stream.cc | 2 +- common/BUILD | 78 +++++++++++++++++-- {cdc_rsync => common}/client_socket.cc | 2 +- {cdc_rsync => common}/client_socket.h | 8 +- {cdc_rsync/base => common}/fake_socket.cc | 2 +- {cdc_rsync/base => common}/fake_socket.h | 6 +- {cdc_rsync_server => common}/server_socket.cc | 2 +- {cdc_rsync_server => common}/server_socket.h | 6 +- {cdc_rsync/base => common}/socket.cc | 2 +- {cdc_rsync/base => common}/socket.h | 6 +- tests_cdc_rsync/BUILD | 2 +- 25 files changed, 124 insertions(+), 124 deletions(-) rename {cdc_rsync => common}/client_socket.cc (99%) rename {cdc_rsync => common}/client_socket.h (90%) rename {cdc_rsync/base => common}/fake_socket.cc (98%) rename {cdc_rsync/base => common}/fake_socket.h (93%) rename {cdc_rsync_server => common}/server_socket.cc (99%) rename {cdc_rsync_server => common}/server_socket.h (94%) rename {cdc_rsync/base => common}/socket.cc (97%) rename {cdc_rsync/base => common}/socket.h (94%) diff --git a/all_files.vcxitems b/all_files.vcxitems index 985c78c..db938d2 100644 --- a/all_files.vcxitems +++ b/all_files.vcxitems @@ -16,7 +16,6 @@ - @@ -39,12 +38,6 @@ - - - - - - @@ -62,13 +55,19 @@ + + + + + + @@ -81,6 +80,8 @@ + + @@ -90,6 +91,8 @@ + + @@ -115,10 +118,8 @@ - - @@ -139,7 +140,6 @@ - @@ -195,9 +195,11 @@ + + @@ -211,6 +213,8 @@ + + @@ -230,12 +234,9 @@ - - - @@ -247,7 +248,6 @@ - diff --git a/cdc_rsync/BUILD b/cdc_rsync/BUILD index 6ac7f7f..f2f9ece 100644 --- a/cdc_rsync/BUILD +++ b/cdc_rsync/BUILD @@ -18,19 +18,6 @@ cc_library( hdrs = ["client_file_info.h"], ) -cc_library( - name = "client_socket", - srcs = ["client_socket.cc"], - hdrs = ["client_socket.h"], - target_compatible_with = ["@platforms//os:windows"], - deps = [ - "//cdc_rsync/base:socket", - "//common:log", - "//common:status", - "//common:util", - ], -) - cc_library( name = "file_finder_and_sender", srcs = ["file_finder_and_sender.cc"], @@ -54,8 +41,8 @@ cc_test( data = ["testdata/root.txt"] + glob(["testdata/file_finder_and_sender/**"]), deps = [ ":file_finder_and_sender", - "//cdc_rsync/base:fake_socket", "//cdc_rsync/protos:messages_cc_proto", + "//common:fake_socket", "//common:status_test_macros", "//common:test_main", "@com_google_googletest//:gtest", @@ -67,15 +54,8 @@ cc_library( name = "cdc_rsync_client", srcs = ["cdc_rsync_client.cc"], hdrs = ["cdc_rsync_client.h"], - linkopts = select({ - "//tools:windows": [ - "/DEFAULTLIB:Ws2_32.lib", # Sockets, e.g. recv, send, WSA*. - ], - "//conditions:default": [], - }), target_compatible_with = ["@platforms//os:windows"], deps = [ - ":client_socket", ":file_finder_and_sender", ":parallel_file_opener", ":progress_tracker", @@ -84,8 +64,8 @@ cc_library( "//cdc_rsync/base:cdc_interface", "//cdc_rsync/base:message_pump", "//cdc_rsync/base:server_exit_code", - "//cdc_rsync/base:socket", "//cdc_rsync/protos:messages_cc_proto", + "//common:client_socket", "//common:gamelet_component", "//common:log", "//common:path", @@ -94,6 +74,7 @@ cc_library( "//common:port_manager", "//common:process", "//common:remote_util", + "//common:socket", "//common:status", "//common:status_macros", "//common:threadpool", @@ -203,8 +184,8 @@ cc_library( srcs = ["zstd_stream.cc"], hdrs = ["zstd_stream.h"], deps = [ - ":client_socket", "//common:buffer", + "//common:client_socket", "//common:status", "//common:status_macros", "//common:stopwatch", @@ -217,8 +198,8 @@ cc_test( srcs = ["zstd_stream_test.cc"], deps = [ ":zstd_stream", - "//cdc_rsync/base:fake_socket", "//cdc_rsync_server:unzstd_stream", + "//common:fake_socket", "//common:status_test_macros", "//common:test_main", "@com_github_zstd//:zstd", diff --git a/cdc_rsync/base/BUILD b/cdc_rsync/base/BUILD index d68b392..e414330 100644 --- a/cdc_rsync/base/BUILD +++ b/cdc_rsync/base/BUILD @@ -28,31 +28,21 @@ cc_test( data = ["testdata/root.txt"] + glob(["testdata/cdc_interface/**"]), deps = [ ":cdc_interface", - ":fake_socket", + "//common:fake_socket", "//common:status_test_macros", "//common:test_main", "@com_google_googletest//:gtest", ], ) -cc_library( - name = "fake_socket", - srcs = ["fake_socket.cc"], - hdrs = ["fake_socket.h"], - deps = [ - "//cdc_rsync/base:socket", - "@com_google_absl//absl/status", - ], -) - cc_library( name = "message_pump", srcs = ["message_pump.cc"], hdrs = ["message_pump.h"], deps = [ - ":socket", "//common:buffer", "//common:log", + "//common:socket", "//common:status", "@com_google_absl//absl/status", "@com_google_absl//absl/strings:str_format", @@ -64,9 +54,9 @@ cc_test( name = "message_pump_test", srcs = ["message_pump_test.cc"], deps = [ - ":fake_socket", ":message_pump", "//cdc_rsync/protos:messages_cc_proto", + "//common:fake_socket", "//common:status_test_macros", "//common:test_main", "@com_google_googletest//:gtest", @@ -78,19 +68,6 @@ cc_library( hdrs = ["server_exit_code.h"], ) -cc_library( - name = "socket", - srcs = ["socket.cc"], - hdrs = ["socket.h"], - deps = [ - "//common:log", - "//common:platform", - "//common:status", - "//common:util", - "@com_google_absl//absl/status", - ], -) - filegroup( name = "all_test_sources", srcs = glob(["*_test.cc"]), diff --git a/cdc_rsync/base/cdc_interface_test.cc b/cdc_rsync/base/cdc_interface_test.cc index b8a480f..a57c5f2 100644 --- a/cdc_rsync/base/cdc_interface_test.cc +++ b/cdc_rsync/base/cdc_interface_test.cc @@ -17,8 +17,8 @@ #include #include -#include "cdc_rsync/base/fake_socket.h" #include "cdc_rsync/base/message_pump.h" +#include "common/fake_socket.h" #include "common/log.h" #include "common/path.h" #include "common/status_test_macros.h" diff --git a/cdc_rsync/base/message_pump.cc b/cdc_rsync/base/message_pump.cc index 08436f1..b44cf39 100644 --- a/cdc_rsync/base/message_pump.cc +++ b/cdc_rsync/base/message_pump.cc @@ -16,9 +16,9 @@ #include "absl/status/status.h" #include "absl/strings/str_format.h" -#include "cdc_rsync/base/socket.h" #include "common/buffer.h" #include "common/log.h" +#include "common/socket.h" #include "common/status.h" #include "google/protobuf/message_lite.h" diff --git a/cdc_rsync/base/message_pump_test.cc b/cdc_rsync/base/message_pump_test.cc index ac47d60..6a9fe72 100644 --- a/cdc_rsync/base/message_pump_test.cc +++ b/cdc_rsync/base/message_pump_test.cc @@ -14,8 +14,8 @@ #include "cdc_rsync/base/message_pump.h" -#include "cdc_rsync/base/fake_socket.h" #include "cdc_rsync/protos/messages.pb.h" +#include "common/fake_socket.h" #include "common/log.h" #include "common/status.h" #include "common/status_test_macros.h" diff --git a/cdc_rsync/cdc_rsync_client.cc b/cdc_rsync/cdc_rsync_client.cc index 276f9a8..1ff5fdb 100644 --- a/cdc_rsync/cdc_rsync_client.cc +++ b/cdc_rsync/cdc_rsync_client.cc @@ -20,13 +20,13 @@ #include "cdc_rsync/base/message_pump.h" #include "cdc_rsync/base/server_exit_code.h" #include "cdc_rsync/client_file_info.h" -#include "cdc_rsync/client_socket.h" #include "cdc_rsync/file_finder_and_sender.h" #include "cdc_rsync/parallel_file_opener.h" #include "cdc_rsync/progress_tracker.h" #include "cdc_rsync/protos/messages.pb.h" #include "cdc_rsync/server_arch.h" #include "cdc_rsync/zstd_stream.h" +#include "common/client_socket.h" #include "common/gamelet_component.h" #include "common/log.h" #include "common/path.h" diff --git a/cdc_rsync/cdc_rsync_client.h b/cdc_rsync/cdc_rsync_client.h index 911a87c..cd80c83 100644 --- a/cdc_rsync/cdc_rsync_client.h +++ b/cdc_rsync/cdc_rsync_client.h @@ -23,8 +23,8 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "cdc_rsync/base/message_pump.h" -#include "cdc_rsync/client_socket.h" #include "cdc_rsync/progress_tracker.h" +#include "common/client_socket.h" #include "common/path_filter.h" #include "common/process.h" diff --git a/cdc_rsync/file_finder_and_sender_test.cc b/cdc_rsync/file_finder_and_sender_test.cc index a6d5438..16f2db1 100644 --- a/cdc_rsync/file_finder_and_sender_test.cc +++ b/cdc_rsync/file_finder_and_sender_test.cc @@ -18,8 +18,8 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" -#include "cdc_rsync/base/fake_socket.h" #include "cdc_rsync/base/message_pump.h" +#include "common/fake_socket.h" #include "common/log.h" #include "common/path.h" #include "common/path_filter.h" diff --git a/cdc_rsync/zstd_stream.h b/cdc_rsync/zstd_stream.h index dbe7658..2b1a9bf 100644 --- a/cdc_rsync/zstd_stream.h +++ b/cdc_rsync/zstd_stream.h @@ -21,8 +21,8 @@ #include "absl/status/status.h" #include "absl/synchronization/mutex.h" -#include "cdc_rsync/base/socket.h" #include "common/buffer.h" +#include "common/socket.h" #include "lib/zstd.h" namespace cdc_ft { diff --git a/cdc_rsync/zstd_stream_test.cc b/cdc_rsync/zstd_stream_test.cc index 4657359..94914c6 100644 --- a/cdc_rsync/zstd_stream_test.cc +++ b/cdc_rsync/zstd_stream_test.cc @@ -14,8 +14,8 @@ #include "cdc_rsync/zstd_stream.h" -#include "cdc_rsync/base/fake_socket.h" #include "cdc_rsync_server/unzstd_stream.h" +#include "common/fake_socket.h" #include "common/status_test_macros.h" #include "gtest/gtest.h" diff --git a/cdc_rsync_server/BUILD b/cdc_rsync_server/BUILD index 28f22dd..8d19c02 100644 --- a/cdc_rsync_server/BUILD +++ b/cdc_rsync_server/BUILD @@ -22,7 +22,7 @@ cc_test( srcs = ["file_deleter_and_sender_test.cc"], deps = [ ":file_deleter_and_sender", - "//cdc_rsync/base:fake_socket", + "//common:fake_socket", "//common:status_test_macros", "//common:test_main", "@com_google_googletest//:gtest", @@ -95,7 +95,6 @@ cc_binary( ":file_diff_generator", ":file_finder", ":file_info", - ":server_socket", ":unzstd_stream", "//cdc_rsync/base:cdc_interface", "//cdc_rsync/base:message_pump", @@ -105,6 +104,7 @@ cc_binary( "//common:gamelet_component", "//common:log", "//common:path_filter", + "//common:server_socket", "//common:status", "//common:stopwatch", "//common:threadpool", @@ -124,33 +124,13 @@ cc_library( hdrs = ["file_info.h"], ) -cc_library( - name = "server_socket", - srcs = ["server_socket.cc"], - hdrs = ["server_socket.h"], - linkopts = select({ - "//tools:windows": [ - "/DEFAULTLIB:Ws2_32.lib", # Sockets, e.g. recv, send, WSA*. - ], - "//conditions:default": [], - }), - deps = [ - "//cdc_rsync/base:socket", - "//common:log", - "//common:status", - "//common:util", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - ], -) - cc_library( name = "unzstd_stream", srcs = ["unzstd_stream.cc"], hdrs = ["unzstd_stream.h"], deps = [ "//cdc_rsync/base:message_pump", - "//cdc_rsync/base:socket", + "//common:socket", "//common:status", "@com_github_zstd//:zstd", "@com_google_absl//absl/status", diff --git a/cdc_rsync_server/cdc_rsync_server.cc b/cdc_rsync_server/cdc_rsync_server.cc index a0212df..80e558c 100644 --- a/cdc_rsync_server/cdc_rsync_server.cc +++ b/cdc_rsync_server/cdc_rsync_server.cc @@ -19,10 +19,10 @@ #include "cdc_rsync/protos/messages.pb.h" #include "cdc_rsync_server/file_deleter_and_sender.h" #include "cdc_rsync_server/file_finder.h" -#include "cdc_rsync_server/server_socket.h" #include "cdc_rsync_server/unzstd_stream.h" #include "common/log.h" #include "common/path.h" +#include "common/server_socket.h" #include "common/status.h" #include "common/status_macros.h" #include "common/stopwatch.h" diff --git a/cdc_rsync_server/file_deleter_and_sender_test.cc b/cdc_rsync_server/file_deleter_and_sender_test.cc index d425bd9..a3d6f52 100644 --- a/cdc_rsync_server/file_deleter_and_sender_test.cc +++ b/cdc_rsync_server/file_deleter_and_sender_test.cc @@ -14,8 +14,8 @@ #include "cdc_rsync_server/file_deleter_and_sender.h" -#include "cdc_rsync/base/fake_socket.h" #include "cdc_rsync/base/message_pump.h" +#include "common/fake_socket.h" #include "common/log.h" #include "common/path.h" #include "common/status_test_macros.h" diff --git a/cdc_rsync_server/unzstd_stream.cc b/cdc_rsync_server/unzstd_stream.cc index d77d51c..2644ff5 100644 --- a/cdc_rsync_server/unzstd_stream.cc +++ b/cdc_rsync_server/unzstd_stream.cc @@ -14,7 +14,7 @@ #include "cdc_rsync_server/unzstd_stream.h" -#include "cdc_rsync/base/socket.h" +#include "common/socket.h" #include "common/status.h" namespace cdc_ft { diff --git a/common/BUILD b/common/BUILD index 0b8e657..0de62eb 100644 --- a/common/BUILD +++ b/common/BUILD @@ -52,6 +52,33 @@ cc_test( ], ) +cc_library( + name = "build_version", + srcs = ["build_version.cc"], + hdrs = ["build_version.h"], + # This definition should be replaced by release flow. + copts = ["-DCDC_BUILD_VERSION=DEV"], +) + +cc_library( + name = "client_socket", + srcs = ["client_socket.cc"], + hdrs = ["client_socket.h"], + linkopts = select({ + "//tools:windows": [ + "/DEFAULTLIB:Ws2_32.lib", # Sockets, e.g. recv, send, WSA*. + ], + "//conditions:default": [], + }), + target_compatible_with = ["@platforms//os:windows"], + deps = [ + ":log", + ":socket", + ":status", + ":util", + ], +) + cc_library( name = "clock", srcs = ["clock.cc"], @@ -62,14 +89,6 @@ cc_library( ], ) -cc_library( - name = "build_version", - srcs = ["build_version.cc"], - hdrs = ["build_version.h"], - # This definition should be replaced by release flow. - copts = ["-DCDC_BUILD_VERSION=DEV"], -) - cc_library( name = "dir_iter", srcs = ["dir_iter.cc"], @@ -127,6 +146,16 @@ cc_test( ], ) +cc_library( + name = "fake_socket", + srcs = ["fake_socket.cc"], + hdrs = ["fake_socket.h"], + deps = [ + ":socket", + "@com_google_absl//absl/status", + ], +) + cc_library( name = "file_watcher", srcs = [ @@ -442,6 +471,39 @@ cc_test( ], ) +cc_library( + name = "server_socket", + srcs = ["server_socket.cc"], + hdrs = ["server_socket.h"], + linkopts = select({ + "//tools:windows": [ + "/DEFAULTLIB:Ws2_32.lib", # Sockets, e.g. recv, send, WSA*. + ], + "//conditions:default": [], + }), + deps = [ + ":log", + ":socket", + ":status", + ":util", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + ], +) + +cc_library( + name = "socket", + srcs = ["socket.cc"], + hdrs = ["socket.h"], + deps = [ + ":log", + ":platform", + ":status", + ":util", + "@com_google_absl//absl/status", + ], +) + cc_library( name = "stats_collector", srcs = ["stats_collector.cc"], diff --git a/cdc_rsync/client_socket.cc b/common/client_socket.cc similarity index 99% rename from cdc_rsync/client_socket.cc rename to common/client_socket.cc index ebe0ebc..b4ce172 100644 --- a/cdc_rsync/client_socket.cc +++ b/common/client_socket.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "cdc_rsync/client_socket.h" +#include "common/client_socket.h" #include #include diff --git a/cdc_rsync/client_socket.h b/common/client_socket.h similarity index 90% rename from cdc_rsync/client_socket.h rename to common/client_socket.h index 9be7835..ae3bc1d 100644 --- a/cdc_rsync/client_socket.h +++ b/common/client_socket.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef CDC_RSYNC_CLIENT_SOCKET_H_ -#define CDC_RSYNC_CLIENT_SOCKET_H_ +#ifndef COMMON_CLIENT_SOCKET_H_ +#define COMMON_CLIENT_SOCKET_H_ #include #include "absl/status/status.h" -#include "cdc_rsync/base/socket.h" +#include "common/socket.h" namespace cdc_ft { @@ -50,4 +50,4 @@ class ClientSocket : public Socket { } // namespace cdc_ft -#endif // CDC_RSYNC_CLIENT_SOCKET_H_ +#endif // COMMON_CLIENT_SOCKET_H_ diff --git a/cdc_rsync/base/fake_socket.cc b/common/fake_socket.cc similarity index 98% rename from cdc_rsync/base/fake_socket.cc rename to common/fake_socket.cc index 94898d4..bf2df9a 100644 --- a/cdc_rsync/base/fake_socket.cc +++ b/common/fake_socket.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "cdc_rsync/base/fake_socket.h" +#include "common/fake_socket.h" namespace cdc_ft { diff --git a/cdc_rsync/base/fake_socket.h b/common/fake_socket.h similarity index 93% rename from cdc_rsync/base/fake_socket.h rename to common/fake_socket.h index 9ef3f53..44686cc 100644 --- a/cdc_rsync/base/fake_socket.h +++ b/common/fake_socket.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef CDC_RSYNC_BASE_FAKE_SOCKET_H_ -#define CDC_RSYNC_BASE_FAKE_SOCKET_H_ +#ifndef COMMON_FAKE_SOCKET_H_ +#define COMMON_FAKE_SOCKET_H_ #include #include #include "absl/status/status.h" -#include "cdc_rsync/base/socket.h" +#include "common/socket.h" namespace cdc_ft { diff --git a/cdc_rsync_server/server_socket.cc b/common/server_socket.cc similarity index 99% rename from cdc_rsync_server/server_socket.cc rename to common/server_socket.cc index e5bc202..78c9c9d 100644 --- a/cdc_rsync_server/server_socket.cc +++ b/common/server_socket.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "cdc_rsync_server/server_socket.h" +#include "common/server_socket.h" #include "common/log.h" #include "common/platform.h" diff --git a/cdc_rsync_server/server_socket.h b/common/server_socket.h similarity index 94% rename from cdc_rsync_server/server_socket.h rename to common/server_socket.h index 17bcb40..68fe8f1 100644 --- a/cdc_rsync_server/server_socket.h +++ b/common/server_socket.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef CDC_RSYNC_SERVER_SERVER_SOCKET_H_ -#define CDC_RSYNC_SERVER_SERVER_SOCKET_H_ +#ifndef COMMON_SERVER_SOCKET_H_ +#define COMMON_SERVER_SOCKET_H_ #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "cdc_rsync/base/socket.h" +#include "common/socket.h" struct addrinfo; diff --git a/cdc_rsync/base/socket.cc b/common/socket.cc similarity index 97% rename from cdc_rsync/base/socket.cc rename to common/socket.cc index e02b9ed..cbc2c37 100644 --- a/cdc_rsync/base/socket.cc +++ b/common/socket.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cdc_rsync/base/socket.h" +#include "common/socket.h" #include "common/log.h" #include "common/platform.h" diff --git a/cdc_rsync/base/socket.h b/common/socket.h similarity index 94% rename from cdc_rsync/base/socket.h rename to common/socket.h index 9c6c876..79b1e66 100644 --- a/cdc_rsync/base/socket.h +++ b/common/socket.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef CDC_RSYNC_BASE_SOCKET_H_ -#define CDC_RSYNC_BASE_SOCKET_H_ +#ifndef COMMON_SOCKET_H_ +#define COMMON_SOCKET_H_ #include "absl/status/status.h" @@ -56,4 +56,4 @@ class SocketFinalizer { } // namespace cdc_ft -#endif // CDC_RSYNC_BASE_SOCKET_H_ +#endif // COMMON_SOCKET_H_ diff --git a/tests_cdc_rsync/BUILD b/tests_cdc_rsync/BUILD index 63b7ce2..423e5f0 100644 --- a/tests_cdc_rsync/BUILD +++ b/tests_cdc_rsync/BUILD @@ -31,12 +31,12 @@ cc_binary( "//cdc_rsync:progress_tracker", "//cdc_rsync:zstd_stream", "//cdc_rsync/base:cdc_interface", - "//cdc_rsync/base:fake_socket", "//cdc_rsync/base:message_pump", "//cdc_rsync_server:file_deleter_and_sender", "//cdc_rsync_server:file_diff_generator", "//cdc_rsync_server:file_finder", "//cdc_rsync_server:unzstd_stream", + "//common:fake_socket", "//common:path_filter", "//common:test_main", "//common:testing_clock",