Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/restc-cpp/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

#ifdef RESTC_CPP_LOG_WITH_BOOST_LOG

#ifndef WIN32
# define BOOST_LOG_DYN_LINK 1
#endif

#include <boost/log/trivial.hpp>

#define RESTC_CPP_LOG_ERROR_(msg) BOOST_LOG_TRIVIAL(error) << msg
Expand Down
18 changes: 16 additions & 2 deletions src/RequestImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down