diff --git a/CMakeLists.txt b/CMakeLists.txt index 4810b04..62d2cac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,13 +56,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Boost - set(BOOST_COMPONENTS system date_time) - if(NOT WEBCC_USE_STD_FILESYSTEM) set(BOOST_COMPONENTS ${BOOST_COMPONENTS} filesystem) endif() - set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) find_package(Boost 1.66.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) @@ -84,6 +81,14 @@ if(WEBCC_ENABLE_SSL) endif() endif() +if(WEBCC_ENABLE_GZIP) + find_package(ZLIB REQUIRED) + if(ZLIB_FOUND) + # You can link to ${ZLIB_LIBRARIES} or the imported target ZLIB::ZLIB. + include_directories(${ZLIB_INCLUDE_DIRS}) + endif() +endif() + include_directories( # For including its own headers as "webcc/client.h". ${PROJECT_SOURCE_DIR} @@ -96,14 +101,6 @@ set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third_party) # For jsoncpp include_directories(${THIRD_PARTY_DIR}/src) -if(WEBCC_ENABLE_GZIP) - find_package(ZLIB REQUIRED) - if(ZLIB_FOUND) - # You can link to ${ZLIB_LIBRARIES} or the imported target ZLIB::ZLIB. - include_directories(${ZLIB_INCLUDE_DIRS}) - endif() -endif() - set_property(GLOBAL PROPERTY USE_FOLDERS ON) add_subdirectory(webcc) diff --git a/webcc/client_base.cc b/webcc/client_base.cc index b7d21d4..6025ade 100644 --- a/webcc/client_base.cc +++ b/webcc/client_base.cc @@ -4,6 +4,7 @@ #include "webcc/logger.h" #include "webcc/socket.h" +#include "webcc/utility.h" using boost::asio::ip::tcp; using namespace std::placeholders; @@ -112,15 +113,22 @@ void ClientBase::OnResolve(boost::system::error_code ec, LOG_VERB("Connect socket"); + // Enable the following log only for debug purpose. +#if 0 + LOG_USER("Resolved endpoints:"); + for (auto& endpoint : endpoints) { + LOG_USER(" - %s", utility::EndpointToString(endpoint).c_str()); + } +#endif + AsyncWaitDeadlineTimer(connect_timeout_); socket_->AsyncConnect(request_->host(), endpoints, std::bind(&ClientBase::OnConnect, this, _1, _2)); } -void ClientBase::OnConnect(boost::system::error_code ec, tcp::endpoint) { - LOG_VERB("On connect"); - +void ClientBase::OnConnect(boost::system::error_code ec, + tcp::endpoint endpoint) { StopDeadlineTimer(); if (ec) { @@ -128,7 +136,7 @@ void ClientBase::OnConnect(boost::system::error_code ec, tcp::endpoint) { // Socket has been closed by OnDeadlineTimer() or CloseSocket(). LOG_WARN("Connect operation aborted"); } else { - LOG_INFO("Connect error"); + LOG_ERRO("Connect error (%s)", ec.message().c_str()); // No need to close socket since no async operation is on it. // socket_->Close(); } diff --git a/webcc/client_base.h b/webcc/client_base.h index 81e9960..0466321 100644 --- a/webcc/client_base.h +++ b/webcc/client_base.h @@ -91,7 +91,8 @@ protected: void OnResolve(boost::system::error_code ec, boost::asio::ip::tcp::resolver::results_type endpoints); - void OnConnect(boost::system::error_code ec, boost::asio::ip::tcp::endpoint); + void OnConnect(boost::system::error_code ec, + boost::asio::ip::tcp::endpoint endpoint); void AsyncWrite(); void OnWrite(boost::system::error_code ec, std::size_t length);