diff --git a/include/restc-cpp/logging.h b/include/restc-cpp/logging.h index dfb881e..6672fa9 100644 --- a/include/restc-cpp/logging.h +++ b/include/restc-cpp/logging.h @@ -14,10 +14,6 @@ #ifdef RESTC_CPP_LOG_WITH_BOOST_LOG -#ifndef WIN32 -# define BOOST_LOG_DYN_LINK 1 -#endif - #include #define RESTC_CPP_LOG_ERROR_(msg) BOOST_LOG_TRIVIAL(error) << msg diff --git a/src/RequestImpl.cpp b/src/RequestImpl.cpp index bbb8895..8b00f5c 100644 --- a/src/RequestImpl.cpp +++ b/src/RequestImpl.cpp @@ -170,6 +170,19 @@ class RequestImpl : public Request { } } + ~RequestImpl() { + if (connection_ && connection_->GetSocket().IsOpen()) { + try { + RESTC_CPP_LOG_TRACE_("~RequestImpl(): " << *connection_ + << " is still open. Closing it to prevent problems with lingering connections."); + connection_->GetSocket().Close(); + connection_.reset(); + } + catch (std::exception& ex) { + RESTC_CPP_LOG_WARN_("~RequestImpl(): Caught exception:" << ex.what()); + } + } + } private: void ValidateReply(const Reply& reply) { @@ -474,10 +487,11 @@ class RequestImpl : public Request { DataReader::ReadConfig cfg; cfg.msReadTimeout = properties_->recvTimeout; + auto reader = DataReader::CreateIoReader(connection_, ctx, cfg); auto reply = ReplyImpl::Create(connection_, ctx, owner_, properties_, request_type_); - reply->StartReceiveFromServer( - DataReader::CreateIoReader(connection_, ctx, cfg)); + connection_.reset(); + reply->StartReceiveFromServer(move(reader)); const auto http_code = reply->GetResponseCode(); if (http_code == http_301 || http_code == http_302) {