log the connect error

master
Chunting Gu 4 years ago
parent f6e25ab19a
commit 50cf424dc8

@ -56,13 +56,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
# Boost # Boost
set(BOOST_COMPONENTS system date_time) set(BOOST_COMPONENTS system date_time)
if(NOT WEBCC_USE_STD_FILESYSTEM) if(NOT WEBCC_USE_STD_FILESYSTEM)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} filesystem) set(BOOST_COMPONENTS ${BOOST_COMPONENTS} filesystem)
endif() endif()
set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.66.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) find_package(Boost 1.66.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
@ -84,6 +81,14 @@ if(WEBCC_ENABLE_SSL)
endif() endif()
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( include_directories(
# For including its own headers as "webcc/client.h". # For including its own headers as "webcc/client.h".
${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
@ -96,14 +101,6 @@ set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third_party)
# For jsoncpp # For jsoncpp
include_directories(${THIRD_PARTY_DIR}/src) 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) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(webcc) add_subdirectory(webcc)

@ -4,6 +4,7 @@
#include "webcc/logger.h" #include "webcc/logger.h"
#include "webcc/socket.h" #include "webcc/socket.h"
#include "webcc/utility.h"
using boost::asio::ip::tcp; using boost::asio::ip::tcp;
using namespace std::placeholders; using namespace std::placeholders;
@ -112,15 +113,22 @@ void ClientBase::OnResolve(boost::system::error_code ec,
LOG_VERB("Connect socket"); 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_); AsyncWaitDeadlineTimer(connect_timeout_);
socket_->AsyncConnect(request_->host(), endpoints, socket_->AsyncConnect(request_->host(), endpoints,
std::bind(&ClientBase::OnConnect, this, _1, _2)); std::bind(&ClientBase::OnConnect, this, _1, _2));
} }
void ClientBase::OnConnect(boost::system::error_code ec, tcp::endpoint) { void ClientBase::OnConnect(boost::system::error_code ec,
LOG_VERB("On connect"); tcp::endpoint endpoint) {
StopDeadlineTimer(); StopDeadlineTimer();
if (ec) { if (ec) {
@ -128,7 +136,7 @@ void ClientBase::OnConnect(boost::system::error_code ec, tcp::endpoint) {
// Socket has been closed by OnDeadlineTimer() or CloseSocket(). // Socket has been closed by OnDeadlineTimer() or CloseSocket().
LOG_WARN("Connect operation aborted"); LOG_WARN("Connect operation aborted");
} else { } 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. // No need to close socket since no async operation is on it.
// socket_->Close(); // socket_->Close();
} }

@ -91,7 +91,8 @@ protected:
void OnResolve(boost::system::error_code ec, void OnResolve(boost::system::error_code ec,
boost::asio::ip::tcp::resolver::results_type endpoints); 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 AsyncWrite();
void OnWrite(boost::system::error_code ec, std::size_t length); void OnWrite(boost::system::error_code ec, std::size_t length);

Loading…
Cancel
Save