From 979c967c92847d5605b64c829097d02a1338a608 Mon Sep 17 00:00:00 2001 From: ihsan Date: Mon, 14 Jul 2025 15:22:24 +0300 Subject: [PATCH 1/5] Added cmake log output for found Boost library and OpenSSL. Added the vcpkg.json for building the project using vcpkg. --- CMakeLists.txt | 16 ++++++++++++++++ vcpkg.json | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 995ae425a..48b4bc4db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,14 @@ else() find_package(Boost 1.71 REQUIRED COMPONENTS thread chrono) endif() +if (Boost_FOUND) + message(STATUS "Boost version: ${Boost_VERSION}") + message(STATUS "Boost include directory: ${Boost_INCLUDE_DIRS}") + message(STATUS "Boost libraries: ${Boost_LIBRARIES}") +else() + message(FATAL_ERROR "Boost not found!") +endif() + # find OpenSSL if building WITH_OPENSSL if (WITH_OPENSSL) if (APPLE) @@ -104,6 +112,14 @@ if (WITH_OPENSSL) endif () find_package(OpenSSL REQUIRED) + + if (OpenSSL_FOUND) + message(STATUS "OpenSSL version: ${OpenSSL_VERSION}") + message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}") + message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}") + else() + message(FATAL_ERROR "OpenSSL not found!") + endif() endif () # add the library target diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..82f5de33e --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "hazelcast-cpp-client", + "version": "5.5.0", + "dependencies": [ + "boost-any", + "boost-asio", + "boost-chrono", + "boost-format", + "boost-optional", + "boost-property-tree", + "boost-system", + "boost-thread", + "boost-uuid" + ] +} \ No newline at end of file From 06abf2836d51aefb5e0d94b9678e0afdfc08d3a6 Mon Sep 17 00:00:00 2001 From: ihsan Date: Wed, 16 Jul 2025 17:14:35 +0300 Subject: [PATCH 2/5] Fixed build problems with latest Boost library versions. Updated the project to use the minimum C++ standard to be the same as the one required by the Boost library. This means if a user is using an older Boost version we use C++11 but if newer Boost version is used we change level to C++ 14 or C++ 17. the algorithm is like this: ``` # Check Boost version and set C++ standard accordingly # Our library can not use a lower C++ standard than the one required by Boost. if (Boost_VERSION VERSION_LESS 1.70) set(CMAKE_CXX_STANDARD 11) elseif (Boost_VERSION VERSION_LESS 1.77) set(CMAKE_CXX_STANDARD 14) else() set(CMAKE_CXX_STANDARD 17) # Boost.JSON, Boost.Process, etc. endif() ``` --- CMakeLists.txt | 24 +++++++++++---- Reference_Manual.md | 21 ++++++++++++++ Reference_Manual.md.in | 27 +++++++++++++++-- examples/CMakeLists.txt | 3 -- .../connection/ClientConnectionManagerImpl.h | 4 ++- .../nearcache/impl/DefaultNearCache.h | 3 +- .../client/internal/socket/BaseSocket.h | 4 +-- .../hazelcast/client/protocol/ClientMessage.h | 22 ++++++++------ .../client/proxy/flake_id_generator_impl.h | 12 ++++---- .../client/serialization/pimpl/data_input.h | 4 +-- .../spi/impl/ClientExecutionServiceImpl.h | 4 +-- .../client/spi/impl/ClientInvocation.h | 17 +---------- .../include/hazelcast/util/SyncHttpClient.h | 2 +- .../include/hazelcast/util/SyncHttpsClient.h | 2 +- hazelcast/src/hazelcast/client/network.cpp | 15 +++++----- hazelcast/src/hazelcast/client/protocol.cpp | 2 +- .../src/hazelcast/client/serialization.cpp | 4 +-- hazelcast/src/hazelcast/client/stats.cpp | 3 +- hazelcast/src/hazelcast/util/util.cpp | 29 +++++++++++-------- hazelcast/test/CMakeLists.txt | 9 +++++- hazelcast/test/src/HazelcastTests8.cpp | 10 +++---- hazelcast/test/src/sql_test.cpp | 8 ++--- vcpkg.json | 13 +++++++-- 23 files changed, 153 insertions(+), 89 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48b4bc4db..99c4fb2c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,6 @@ project(hazelcast-cpp-client DESCRIPTION "Hazelcast C++ Client" LANGUAGES CXX) -# Set the C++ standard -set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Generate the Reference_Manual.md file using the latest project version. @@ -89,15 +87,27 @@ find_package(Threads REQUIRED) # find Boost if (WIN32) - find_package(Boost 1.73 REQUIRED COMPONENTS thread chrono) + find_package(Boost 1.73 CONFIG REQUIRED COMPONENTS thread chrono) else() - find_package(Boost 1.71 REQUIRED COMPONENTS thread chrono) + find_package(Boost 1.71 CONFIG REQUIRED COMPONENTS thread chrono) endif() if (Boost_FOUND) message(STATUS "Boost version: ${Boost_VERSION}") message(STATUS "Boost include directory: ${Boost_INCLUDE_DIRS}") message(STATUS "Boost libraries: ${Boost_LIBRARIES}") + + # Check Boost version and set C++ standard accordingly + # Our library can not use a lower C++ standard than the one required by Boost. + if (Boost_VERSION VERSION_LESS 1.70) + set(CMAKE_CXX_STANDARD 11) + elseif (Boost_VERSION VERSION_LESS 1.77) + set(CMAKE_CXX_STANDARD 14) + else() + set(CMAKE_CXX_STANDARD 17) # Boost.JSON, Boost.Process, etc. + endif() + + message(STATUS "Required C++ standard: ${CMAKE_CXX_STANDARD}") else() message(FATAL_ERROR "Boost not found!") endif() @@ -263,8 +273,12 @@ install( ) if (BUILD_TESTS) + message(STATUS "BUILD_TESTS is enabled. Ensure the 'build-tests' feature is enabled in vcpkg.json.") + find_package(GTest REQUIRED) add_subdirectory(hazelcast/test) -endif () +else() + message(STATUS "BUILD_TESTS is disabled.") +endif() if (BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/Reference_Manual.md b/Reference_Manual.md index 69b612c2e..89c25a9f7 100644 --- a/Reference_Manual.md +++ b/Reference_Manual.md @@ -347,6 +347,27 @@ For example: g++ -DHZ_BUILD_WITH_SSL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DBOOST_THREAD_VERSION=5 -I/var/git/hazelcast-cpp-client/build/include -std=gnu++11 -c main.cpp ``` +##### 1.1.3.5.2. Building the hazelcast-cpp-client library with vcpkg toolchain +If you want to build the `hazelcast-cpp-client` library with vcpkg toolchain, you can use the following command: +```sh +cmake -B build -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake +cmake --build build --config Release +``` + +if you want to build the project with tests and examples enabled, then you can use the following command: +```sh +cmake -b build \ +-DBUILD_TESTS=ON \ +-DBUILD_EXAMPLES=ON \ +-DWITH_OPENSSL=ON \ +-DCMAKE_VERBOSE_MAKEFILE=ON \ +-DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake \ +-DVCPKG_MANIFEST_FEATURES='build-tests' \ + +cmake --build build +``` + + ## 1.2. Starting a Hazelcast Cluster The Hazelcast C++ client requires a working Hazelcast cluster to run. This cluster handles storage and manipulation of the user data. Clients are a way to connect to the Hazelcast cluster and access such data. diff --git a/Reference_Manual.md.in b/Reference_Manual.md.in index 10f8e114d..1fa6e6a8b 100644 --- a/Reference_Manual.md.in +++ b/Reference_Manual.md.in @@ -199,7 +199,7 @@ Please see [getting started](https://github.com/microsoft/vcpkg#getting-started) If you use Linux or Mac: ```sh -git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 +git clone https://github.com/microsoft/vcpkg ./vcpkg/bootstrap-vcpkg.sh ./vcpkg/vcpkg install "hazelcast-cpp-client[openssl]" --recurse ``` @@ -207,7 +207,7 @@ git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 If you use Windows: ```bat -git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 +git clone https://github.com/microsoft/vcpkg .\vcpkg\bootstrap-vcpkg.bat .\vcpkg\vcpkg install "hazelcast-cpp-client[openssl]:x64-windows" --recurse ``` @@ -242,7 +242,7 @@ This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists ### 1.1.3. Install From Source Code Using CMake #### 1.1.3.1. Requirements 1. Linux, macOS or Windows -2. A compiler that supports C++11 +2. A compiler that supports C++11 or above: The project detects the minimum C++ standard supported by the Boost library and uses the same language level for compilation. 3. [CMake](https://cmake.org) 3.10 or above 4. [Boost](https://www.boost.org) 1.71 or above. Minimum boost version is upgraded to 1.73 for Windows due to [this](https://github.com/chriskohlhoff/asio/issues/431) bug. 5. [OpenSSL](https://www.openssl.org) (optional) @@ -347,6 +347,27 @@ For example: g++ -DHZ_BUILD_WITH_SSL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DBOOST_THREAD_VERSION=5 -I/var/git/hazelcast-cpp-client/build/include -std=gnu++11 -c main.cpp ``` +##### 1.1.3.5.2. Building the hazelcast-cpp-client library with vcpkg toolchain +If you want to build the `hazelcast-cpp-client` library with vcpkg toolchain, you can use the following command: +```sh +cmake -B build -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake +cmake --build build --config Release +``` + +if you want to build the project with tests and examples enabled, then you can use the following command: +```sh +cmake -b build \ +-DBUILD_TESTS=ON \ +-DBUILD_EXAMPLES=ON \ +-DWITH_OPENSSL=ON \ +-DCMAKE_VERBOSE_MAKEFILE=ON \ +-DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake \ +-DVCPKG_MANIFEST_FEATURES='build-tests' \ + +cmake --build build +``` + + ## 1.2. Starting a Hazelcast Cluster The Hazelcast C++ client requires a working Hazelcast cluster to run. This cluster handles storage and manipulation of the user data. Clients are a way to connect to the Hazelcast cluster and access such data. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e7351c147..cf701d7a7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -21,9 +21,6 @@ project (hazelcast-cpp-client-examples DESCRIPTION "Hazelcast C++ Client Code Examples" LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - if (NOT TARGET hazelcast-cpp-client) message(STATUS "hazelcast-cpp-client is not a valid target, using find_package to find it.") find_package(hazelcast-cpp-client REQUIRED) diff --git a/hazelcast/include/hazelcast/client/connection/ClientConnectionManagerImpl.h b/hazelcast/include/hazelcast/client/connection/ClientConnectionManagerImpl.h index 43aecd741..0f16849b2 100644 --- a/hazelcast/include/hazelcast/client/connection/ClientConnectionManagerImpl.h +++ b/hazelcast/include/hazelcast/client/connection/ClientConnectionManagerImpl.h @@ -295,7 +295,9 @@ class HAZELCAST_API ClientConnectionManagerImpl std::unique_ptr socket_factory_; HeartbeatManager heartbeat_; std::thread io_thread_; - std::unique_ptr io_guard_; + std::unique_ptr< + boost::asio::executor_work_guard> + io_guard_; const bool async_start_; const config::client_connection_strategy_config::reconnect_mode reconnect_mode_; diff --git a/hazelcast/include/hazelcast/client/internal/nearcache/impl/DefaultNearCache.h b/hazelcast/include/hazelcast/client/internal/nearcache/impl/DefaultNearCache.h index a69e7dc01..bfdfac2a8 100644 --- a/hazelcast/include/hazelcast/client/internal/nearcache/impl/DefaultNearCache.h +++ b/hazelcast/include/hazelcast/client/internal/nearcache/impl/DefaultNearCache.h @@ -124,8 +124,7 @@ class DefaultNearCache : public NearCache { expiration_cancelled_.store(true); if (expiration_timer_) { - boost::system::error_code ignored; - expiration_timer_->cancel(ignored); + expiration_timer_->cancel(); } near_cache_record_store_->destroy(); } diff --git a/hazelcast/include/hazelcast/client/internal/socket/BaseSocket.h b/hazelcast/include/hazelcast/client/internal/socket/BaseSocket.h index 3070833cf..9fdd51d5c 100644 --- a/hazelcast/include/hazelcast/client/internal/socket/BaseSocket.h +++ b/hazelcast/include/hazelcast/client/internal/socket/BaseSocket.h @@ -76,7 +76,7 @@ class BaseSocket : public hazelcast::client::socket const std::shared_ptr connection) override { boost::asio::steady_timer connectTimer(io_); - connectTimer.expires_from_now(connect_timeout_); + connectTimer.expires_after(connect_timeout_); connectTimer.async_wait([=](const boost::system::error_code& ec) { if (ec == boost::asio::error::operation_aborted) { return; @@ -117,7 +117,7 @@ class BaseSocket : public hazelcast::client::socket { check_connection(connection, invocation); auto message = invocation->get_client_message(); - socket_strand_.post([connection, invocation, message, this]() mutable { + boost::asio::post(socket_strand_, [connection, invocation, message, this]() mutable { if (!check_connection(connection, invocation)) { return; } diff --git a/hazelcast/include/hazelcast/client/protocol/ClientMessage.h b/hazelcast/include/hazelcast/client/protocol/ClientMessage.h index d71ece111..c627e305e 100644 --- a/hazelcast/include/hazelcast/client/protocol/ClientMessage.h +++ b/hazelcast/include/hazelcast/client/protocol/ClientMessage.h @@ -56,6 +56,11 @@ namespace hazelcast { namespace util { class ByteBuffer; + +template +struct is_trivial_or_uuid : std::is_trivial {}; +template<> +struct is_trivial_or_uuid : std::true_type {}; } namespace cp { @@ -594,7 +599,7 @@ class HAZELCAST_API ClientMessage std::is_same, typename T::value_type>::value && - std::is_trivial::value && + hazelcast::util::is_trivial_or_uuid::value && std::is_trivial::value, T>::type get() @@ -625,7 +630,7 @@ class HAZELCAST_API ClientMessage std::is_same, typename T::value_type>::value && - std::is_trivial::value && + hazelcast::util::is_trivial_or_uuid::value && !std::is_trivial::value, T>::type get() @@ -1246,12 +1251,11 @@ class HAZELCAST_API ClientMessage set(nil); if (!nil) { boost::endian::endian_reverse_inplace( - *reinterpret_cast(uuid.data)); + *reinterpret_cast(&uuid.data[0])); boost::endian::endian_reverse_inplace( - *reinterpret_cast(uuid.data + - util::Bits::LONG_SIZE_IN_BYTES)); + *reinterpret_cast(&uuid.data[util::Bits::LONG_SIZE_IN_BYTES])); std::memcpy(wr_ptr(sizeof(boost::uuids::uuid)), - uuid.data, + &uuid.data[0], sizeof(boost::uuids::uuid)); } else { wr_ptr(sizeof(boost::uuids::uuid)); @@ -1525,13 +1529,13 @@ class HAZELCAST_API ClientMessage boost::uuids::uuid get_uuid() { boost::uuids::uuid u; - memcpy(&u.data, + memcpy(&u.data[0], rd_ptr(sizeof(boost::uuids::uuid)), sizeof(boost::uuids::uuid)); boost::endian::endian_reverse_inplace( - *reinterpret_cast(u.data)); + *reinterpret_cast(&u.data[0])); boost::endian::endian_reverse_inplace( - *reinterpret_cast(u.data + util::Bits::LONG_SIZE_IN_BYTES)); + *reinterpret_cast(&u.data[util::Bits::LONG_SIZE_IN_BYTES])); return u; } diff --git a/hazelcast/include/hazelcast/client/proxy/flake_id_generator_impl.h b/hazelcast/include/hazelcast/client/proxy/flake_id_generator_impl.h index acb21d4df..d0cfd83a4 100644 --- a/hazelcast/include/hazelcast/client/proxy/flake_id_generator_impl.h +++ b/hazelcast/include/hazelcast/client/proxy/flake_id_generator_impl.h @@ -91,19 +91,20 @@ class HAZELCAST_API flake_id_generator_impl : public ProxyImpl int32_t get_batch_size() const; class IdIterator - : public std::iterator { public: - IdIterator(); + using iterator_category = std::input_iterator_tag; + using value_type = int64_t; + using difference_type = std::ptrdiff_t; + using pointer = int64_t*; + using reference = int64_t&; + IdIterator(); IdIterator(int64_t base2, int64_t increment, int32_t remaining); IdIterator& operator++(); - bool operator==(const IdIterator& rhs) const; - bool operator!=(const IdIterator& rhs) const; - const int64_t& operator*() { return base2_; } private: @@ -111,7 +112,6 @@ class HAZELCAST_API flake_id_generator_impl : public ProxyImpl const int64_t increment_; int32_t remaining_; }; - IdIterator iterator(); static IdIterator& end(); diff --git a/hazelcast/include/hazelcast/client/serialization/pimpl/data_input.h b/hazelcast/include/hazelcast/client/serialization/pimpl/data_input.h index fb41ad8a4..afe9d73ea 100644 --- a/hazelcast/include/hazelcast/client/serialization/pimpl/data_input.h +++ b/hazelcast/include/hazelcast/client/serialization/pimpl/data_input.h @@ -182,11 +182,11 @@ class data_input { check_available(util::Bits::UUID_SIZE_IN_BYTES); boost::uuids::uuid u; - std::memcpy(&u.data, &buffer_[pos_], util::Bits::UUID_SIZE_IN_BYTES); + std::memcpy(&u.data[0], &buffer_[pos_], util::Bits::UUID_SIZE_IN_BYTES); pos_ += util::Bits::UUID_SIZE_IN_BYTES; if (byte_order_ == boost::endian::order::little) { boost::endian::endian_reverse_inplace( - *reinterpret_cast(u.data)); + *reinterpret_cast(&u.data[0])); boost::endian::endian_reverse_inplace( *reinterpret_cast( &u.data[util::Bits::LONG_SIZE_IN_BYTES])); diff --git a/hazelcast/include/hazelcast/client/spi/impl/ClientExecutionServiceImpl.h b/hazelcast/include/hazelcast/client/spi/impl/ClientExecutionServiceImpl.h index 38407d754..a9cb41fcf 100644 --- a/hazelcast/include/hazelcast/client/spi/impl/ClientExecutionServiceImpl.h +++ b/hazelcast/include/hazelcast/client/spi/impl/ClientExecutionServiceImpl.h @@ -96,9 +96,9 @@ class HAZELCAST_API ClientExecutionServiceImpl std::shared_ptr timer) { if (delay.count() > 0) { - timer->expires_from_now(delay); + timer->expires_after(delay); } else { - timer->expires_from_now(period); + timer->expires_after(period); } timer->async_wait([=](boost::system::error_code ec) { diff --git a/hazelcast/include/hazelcast/client/spi/impl/ClientInvocation.h b/hazelcast/include/hazelcast/client/spi/impl/ClientInvocation.h index 81e3d2c0d..e18855f34 100644 --- a/hazelcast/include/hazelcast/client/spi/impl/ClientInvocation.h +++ b/hazelcast/include/hazelcast/client/spi/impl/ClientInvocation.h @@ -210,22 +210,7 @@ class HAZELCAST_API ClientInvocation const std::string& name, int partition = UNASSIGNED_PARTITION, const std::shared_ptr& conn = nullptr, - boost::uuids::uuid uuid = { 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0 }); + boost::uuids::uuid uuid = {}); void invoke_on_selection(); diff --git a/hazelcast/include/hazelcast/util/SyncHttpClient.h b/hazelcast/include/hazelcast/util/SyncHttpClient.h index a1f89da81..144347436 100644 --- a/hazelcast/include/hazelcast/util/SyncHttpClient.h +++ b/hazelcast/include/hazelcast/util/SyncHttpClient.h @@ -39,7 +39,7 @@ class HAZELCAST_API SyncHttpClient private: std::string server_; std::string uri_path_; - boost::asio::io_service io_service_; + boost::asio::io_context io_service_; boost::asio::ip::tcp::socket socket_; boost::asio::streambuf response_; std::istream response_stream_; diff --git a/hazelcast/include/hazelcast/util/SyncHttpsClient.h b/hazelcast/include/hazelcast/util/SyncHttpsClient.h index 15c841209..45d8de634 100644 --- a/hazelcast/include/hazelcast/util/SyncHttpsClient.h +++ b/hazelcast/include/hazelcast/util/SyncHttpsClient.h @@ -48,7 +48,7 @@ class HAZELCAST_API SyncHttpsClient std::chrono::steady_clock::duration timeout_; std::string secret_removal_; - boost::asio::io_service io_service_; + boost::asio::io_context io_service_; boost::asio::ip::tcp::resolver resolver_; boost::asio::ssl::context ssl_context_; diff --git a/hazelcast/src/hazelcast/client/network.cpp b/hazelcast/src/hazelcast/client/network.cpp index b5e342ae7..df3d7d7f5 100644 --- a/hazelcast/src/hazelcast/client/network.cpp +++ b/hazelcast/src/hazelcast/client/network.cpp @@ -119,7 +119,10 @@ ClientConnectionManagerImpl::start() new boost::asio::ip::tcp::resolver(io_context_->get_executor())); socket_factory_.reset(new internal::socket::SocketFactory( client_, *io_context_, *io_resolver_)); - io_guard_.reset(new boost::asio::io_context::work(*io_context_)); + auto guard = boost::asio::make_work_guard(*io_context_); + io_guard_ = std::make_unique< + boost::asio::executor_work_guard>( + std::move(guard)); if (!socket_factory_->start()) { return false; @@ -153,7 +156,7 @@ ClientConnectionManagerImpl::schedule_connect_to_all_members() return; } - connect_to_members_timer_->expires_from_now( + connect_to_members_timer_->expires_after( boost::asio::chrono::seconds(1)); connect_to_members_timer_->async_wait([=](boost::system::error_code ec) { if (ec == boost::asio::error::operation_aborted) { @@ -1234,7 +1237,7 @@ Connection::schedule_periodic_backup_cleanup( return; } - backup_timer_->expires_from_now(backup_timeout); + backup_timer_->expires_after(backup_timeout); backup_timer_->async_wait( socket_->get_executor().wrap([=](boost::system::error_code ec) { if (ec) { @@ -1273,8 +1276,7 @@ Connection::close(const std::string& reason, std::exception_ptr cause) std::chrono::steady_clock::now().time_since_epoch())); if (backup_timer_) { - boost::system::error_code ignored; - backup_timer_->cancel(ignored); + backup_timer_->cancel(); } close_cause_ = cause; @@ -1631,8 +1633,7 @@ void HeartbeatManager::shutdown() { if (timer_) { - boost::system::error_code ignored; - timer_->cancel(ignored); + timer_->cancel(); } } diff --git a/hazelcast/src/hazelcast/client/protocol.cpp b/hazelcast/src/hazelcast/client/protocol.cpp index 8106fe170..9435ef091 100644 --- a/hazelcast/src/hazelcast/client/protocol.cpp +++ b/hazelcast/src/hazelcast/client/protocol.cpp @@ -376,7 +376,7 @@ operator<<(std::ostream& os, const ClientMessage& msg) void ClientMessage::set(unsigned char* /* memory */, boost::uuids::uuid uuid) { - std::memcpy(wr_ptr(uuid.size()), uuid.data, uuid.size()); + std::memcpy(wr_ptr(uuid.size()), &uuid.data[0], uuid.size()); } void diff --git a/hazelcast/src/hazelcast/client/serialization.cpp b/hazelcast/src/hazelcast/client/serialization.cpp index 7b104c1e7..9c911e5ec 100644 --- a/hazelcast/src/hazelcast/client/serialization.cpp +++ b/hazelcast/src/hazelcast/client/serialization.cpp @@ -731,12 +731,12 @@ data_output::write(boost::uuids::uuid v) } if (byte_order_ == boost::endian::order::little) { boost::endian::endian_reverse_inplace( - *reinterpret_cast(v.data)); + *reinterpret_cast(&v.data[0])); boost::endian::endian_reverse_inplace( *reinterpret_cast(&v.data[util::Bits::LONG_SIZE_IN_BYTES])); } output_stream_.insert( - output_stream_.end(), v.data, v.data + util::Bits::UUID_SIZE_IN_BYTES); + output_stream_.end(), &v.data[0], &v.data[util::Bits::LONG_SIZE_IN_BYTES]); } template<> diff --git a/hazelcast/src/hazelcast/client/stats.cpp b/hazelcast/src/hazelcast/client/stats.cpp index 8a59a2513..d7d0305a9 100644 --- a/hazelcast/src/hazelcast/client/stats.cpp +++ b/hazelcast/src/hazelcast/client/stats.cpp @@ -96,8 +96,7 @@ void Statistics::shutdown() { if (send_task_timer_) { - boost::system::error_code ignored; - send_task_timer_->cancel(ignored); + send_task_timer_->cancel(); } } diff --git a/hazelcast/src/hazelcast/util/util.cpp b/hazelcast/src/hazelcast/util/util.cpp index 082f24a01..d0a2f040b 100644 --- a/hazelcast/src/hazelcast/util/util.cpp +++ b/hazelcast/src/hazelcast/util/util.cpp @@ -36,9 +36,9 @@ #include #ifdef HZ_BUILD_WITH_SSL -#include +#include #include -#include +#include #include #include #endif // HZ_BUILD_WITH_SSL @@ -126,12 +126,19 @@ boost::asio::ip::address AddressUtil::get_by_name(const std::string& host, const std::string& service) { try { - boost::asio::io_service ioService; + boost::asio::io_context ioService; boost::asio::ip::tcp::resolver res(ioService); - boost::asio::ip::tcp::resolver::query query(host, service); - boost::asio::ip::basic_resolver::iterator - iterator = res.resolve(query); - return iterator->endpoint().address(); + + auto endpoints = res.resolve(host, service); + + // Get the first endpoint's address + auto endpoint = endpoints.begin(); + if (endpoint == endpoints.end()) { + throw client::exception::unknown_host("AddressUtil::getByName", + "No endpoints found"); + } + + return endpoint->endpoint().address(); } catch (boost::system::system_error& e) { std::ostringstream out; out << "Address " << host << " ip number is not available. " @@ -168,7 +175,7 @@ SyncHttpsClient::SyncHttpsClient(const std::string& server_ip, ssl_context_.set_verify_mode(boost::asio::ssl::verify_peer); ssl_context_.set_verify_callback( - boost::asio::ssl::rfc2818_verification(server_)); + boost::asio::ssl::host_name_verification(server_)); socket_ = std::unique_ptr>( new boost::asio::ssl::stream( @@ -544,11 +551,9 @@ SyncHttpClient::open_connection() try { // Get a list of endpoints corresponding to the server name. boost::asio::ip::tcp::resolver resolver(io_service_); - boost::asio::ip::tcp::resolver::query query(server_, "http"); - boost::asio::ip::tcp::resolver::iterator endpoint_iterator = - resolver.resolve(query); + auto endpoints = resolver.resolve(server_, "http"); - boost::asio::connect(socket_, endpoint_iterator); + boost::asio::connect(socket_, endpoints); socket_.lowest_layer().set_option(boost::asio::ip::tcp::no_delay(true)); diff --git a/hazelcast/test/CMakeLists.txt b/hazelcast/test/CMakeLists.txt index 665460b71..dffbefb16 100644 --- a/hazelcast/test/CMakeLists.txt +++ b/hazelcast/test/CMakeLists.txt @@ -7,11 +7,18 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-maybe-uninitialized") endif () -find_package(GTest 1.10) +find_package(GTest) if (GTest_FOUND) + message(STATUS "GTest package found!") + get_target_property(GTEST_INCLUDES GTest::gtest INTERFACE_INCLUDE_DIRECTORIES) + message(STATUS "GTest include directory: ${GTEST_INCLUDES}") + message(STATUS "GTest libraries: ${GTEST_LIBRARIES}") + set(GTEST_TARGETS GTest::gtest GTest::gtest_main) else() + message(STATUS "GTest package not found!") + message(STATUS "Downloading googletest from Github") configure_file(CMakeLists.googletest.in googletest-download/CMakeLists.txt) diff --git a/hazelcast/test/src/HazelcastTests8.cpp b/hazelcast/test/src/HazelcastTests8.cpp index 1bfde647c..355cadee0 100644 --- a/hazelcast/test/src/HazelcastTests8.cpp +++ b/hazelcast/test/src/HazelcastTests8.cpp @@ -2360,11 +2360,11 @@ TEST(ClientMessageTest, test_encode_sql_query_id) protocol::ClientMessage msg; - boost::uuids::uuid server_uuid{ 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 }; - boost::uuids::uuid client_uuid{ 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36 }; - msg.set(sql::impl::query_id{ server_uuid, client_uuid }); +boost::uuids::uuid server_uuid = boost::uuids::uuid{{ 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }}; +boost::uuids::uuid client_uuid = boost::uuids::uuid{{ 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36 }}; +msg.set(sql::impl::query_id{ server_uuid, client_uuid }); const std::vector expected_bytes{ 6, 0, 0, 0, 0, 16, // begin frame diff --git a/hazelcast/test/src/sql_test.cpp b/hazelcast/test/src/sql_test.cpp index 8d43bda2c..4a376d401 100644 --- a/hazelcast/test/src/sql_test.cpp +++ b/hazelcast/test/src/sql_test.cpp @@ -2269,10 +2269,10 @@ class sql_encode_test : public ::testing::Test protected: query_id get_query_id() const { - boost::uuids::uuid server_uuid{ 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 }; - boost::uuids::uuid client_uuid{ 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36 }; + boost::uuids::uuid server_uuid{ {1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16} }; + boost::uuids::uuid client_uuid{ {21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36} }; return { server_uuid, client_uuid }; } }; diff --git a/vcpkg.json b/vcpkg.json index 82f5de33e..a84bf9f47 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,6 +11,15 @@ "boost-property-tree", "boost-system", "boost-thread", - "boost-uuid" - ] + "boost-uuid", + "boost-multiprecision" + ], + "features": { + "build-tests": { + "description": "Enable GTest for building tests", + "dependencies": [ + "gtest" + ] + } + } } \ No newline at end of file From df7ff8f2dc2a8a62a1ffa7a3c8fb71ae1f9d452f Mon Sep 17 00:00:00 2001 From: ihsan Date: Thu, 17 Jul 2025 12:05:22 +0300 Subject: [PATCH 3/5] review comment fix. --- Reference_Manual.md | 6 +++--- hazelcast/test/src/HazelcastTests8.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Reference_Manual.md b/Reference_Manual.md index 89c25a9f7..a1e778b40 100644 --- a/Reference_Manual.md +++ b/Reference_Manual.md @@ -199,7 +199,7 @@ Please see [getting started](https://github.com/microsoft/vcpkg#getting-started) If you use Linux or Mac: ```sh -git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 +git clone https://github.com/microsoft/vcpkg ./vcpkg/bootstrap-vcpkg.sh ./vcpkg/vcpkg install "hazelcast-cpp-client[openssl]" --recurse ``` @@ -207,7 +207,7 @@ git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 If you use Windows: ```bat -git clone https://github.com/microsoft/vcpkg --branch 2025.02.14 +git clone https://github.com/microsoft/vcpkg .\vcpkg\bootstrap-vcpkg.bat .\vcpkg\vcpkg install "hazelcast-cpp-client[openssl]:x64-windows" --recurse ``` @@ -242,7 +242,7 @@ This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists ### 1.1.3. Install From Source Code Using CMake #### 1.1.3.1. Requirements 1. Linux, macOS or Windows -2. A compiler that supports C++11 +2. A compiler that supports C++11 or above: The project detects the minimum C++ standard supported by the Boost library and uses the same language level for compilation. 3. [CMake](https://cmake.org) 3.10 or above 4. [Boost](https://www.boost.org) 1.71 or above. Minimum boost version is upgraded to 1.73 for Windows due to [this](https://github.com/chriskohlhoff/asio/issues/431) bug. 5. [OpenSSL](https://www.openssl.org) (optional) diff --git a/hazelcast/test/src/HazelcastTests8.cpp b/hazelcast/test/src/HazelcastTests8.cpp index 355cadee0..67b0c7160 100644 --- a/hazelcast/test/src/HazelcastTests8.cpp +++ b/hazelcast/test/src/HazelcastTests8.cpp @@ -2357,14 +2357,16 @@ TEST(ClientMessageTest, testFragmentedMessageHandling) TEST(ClientMessageTest, test_encode_sql_query_id) { // TODO this test can be removed once the query_id encoder is generated. - protocol::ClientMessage msg; -boost::uuids::uuid server_uuid = boost::uuids::uuid{{ 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 }}; -boost::uuids::uuid client_uuid = boost::uuids::uuid{{ 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36 }}; -msg.set(sql::impl::query_id{ server_uuid, client_uuid }); + boost::uuids::uuid server_uuid = boost::uuids::uuid{ + { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }}; + boost::uuids::uuid client_uuid = boost::uuids::uuid{ + { 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36 }}; + + msg.set(sql::impl::query_id{ server_uuid, client_uuid }); const std::vector expected_bytes{ 6, 0, 0, 0, 0, 16, // begin frame From 9fdfb56c65586350d6dc8e22354efcc96b141ce7 Mon Sep 17 00:00:00 2001 From: ihsan Date: Thu, 17 Jul 2025 12:20:17 +0300 Subject: [PATCH 4/5] Review comment fix. Added versions for dependencies. --- Reference_Manual.md.in | 2 +- vcpkg.json | 54 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Reference_Manual.md.in b/Reference_Manual.md.in index 1fa6e6a8b..cb052e842 100644 --- a/Reference_Manual.md.in +++ b/Reference_Manual.md.in @@ -244,7 +244,7 @@ This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists 1. Linux, macOS or Windows 2. A compiler that supports C++11 or above: The project detects the minimum C++ standard supported by the Boost library and uses the same language level for compilation. 3. [CMake](https://cmake.org) 3.10 or above -4. [Boost](https://www.boost.org) 1.71 or above. Minimum boost version is upgraded to 1.73 for Windows due to [this](https://github.com/chriskohlhoff/asio/issues/431) bug. +4. [Boost](https://www.boost.org) 1.73 or above. 5. [OpenSSL](https://www.openssl.org) (optional) #### 1.1.3.2. Downloading Source Code diff --git a/vcpkg.json b/vcpkg.json index a84bf9f47..bb587099e 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,16 +3,50 @@ "name": "hazelcast-cpp-client", "version": "5.5.0", "dependencies": [ - "boost-any", - "boost-asio", - "boost-chrono", - "boost-format", - "boost-optional", - "boost-property-tree", - "boost-system", - "boost-thread", - "boost-uuid", - "boost-multiprecision" + { + "name": "boost-any", + "version>=": "1.73.0" + }, + { + "name": "boost-asio", + "version>=": "1.73.0" + }, + { + "name": "boost-chrono", + "version>=": "1.73.0" + }, + { + "name": "boost-any", + "version>=": "1.73.0" + }, + { + "name": "boost-format", + "version>=": "1.73.0" + }, + { + "name": "boost-optional", + "version>=": "1.73.0" + }, + { + "name": "boost-property-tree", + "version>=": "1.73.0" + }, + { + "name": "boost-system", + "version>=": "1.73.0" + }, + { + "name": "boost-thread", + "version>=": "1.73.0" + }, + { + "name": "boost-uuid", + "version>=": "1.73.0" + }, + { + "name": "boost-multiprecision", + "version>=": "1.73.0" + } ], "features": { "build-tests": { From 6dfa6d1b19b53ccd053285df88f14e8deee89dc6 Mon Sep 17 00:00:00 2001 From: ihsan Date: Thu, 17 Jul 2025 12:34:50 +0300 Subject: [PATCH 5/5] Reverted back the GTest package change. It can be optional and cmake will download and install it if not found. --- CMakeLists.txt | 2 -- hazelcast/test/CMakeLists.txt | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99c4fb2c6..e39c22d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,8 +273,6 @@ install( ) if (BUILD_TESTS) - message(STATUS "BUILD_TESTS is enabled. Ensure the 'build-tests' feature is enabled in vcpkg.json.") - find_package(GTest REQUIRED) add_subdirectory(hazelcast/test) else() message(STATUS "BUILD_TESTS is disabled.") diff --git a/hazelcast/test/CMakeLists.txt b/hazelcast/test/CMakeLists.txt index dffbefb16..a4a33ffe8 100644 --- a/hazelcast/test/CMakeLists.txt +++ b/hazelcast/test/CMakeLists.txt @@ -7,6 +7,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-maybe-uninitialized") endif () +message(STATUS "BUILD_TESTS is enabled. Ensure the 'build-tests' feature is enabled in vcpkg.json.") find_package(GTest) if (GTest_FOUND)