diff --git a/include/opendht/http.h b/include/opendht/http.h index ca5f86aa..199dc6e5 100644 --- a/include/opendht/http.h +++ b/include/opendht/http.h @@ -99,6 +99,7 @@ public: void async_read(const size_t bytes, BytesHandlerCb cb); void timeout(const std::chrono::seconds timeout, HandlerCb cb = {}); + void close(); private: unsigned int id_; diff --git a/src/http.cpp b/src/http.cpp index a27ae183..276e919a 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -117,19 +117,21 @@ Connection::Connection(asio::io_context& ctx, std::shared_ptrcancel(ec); - ssl_socket_->close(ec); - } - else { - socket_->cancel(ec); - socket_->close(ec); - } - if (ec and logger_) - logger_->e("[http:client] [connection:%i] error closing: %s", id_, ec.message().c_str()); - } + if (ssl_ctx_) + ssl_socket_->close(ec); + else + socket_->close(ec); + if (ec and logger_) + logger_->e("[http:client] [connection:%i] error closing: %s", id_, ec.message().c_str()); } unsigned int @@ -442,7 +444,7 @@ Request::~Request() void Request::cancel() { - terminate(asio::error::eof); + conn_->close(); } unsigned int @@ -899,8 +901,10 @@ Request::handle_response_header(const asio::error_code& ec) void Request::handle_response_body(const asio::error_code& ec, const size_t bytes) { - if (ec == asio::error::operation_aborted) + if (ec == asio::error::operation_aborted){ + terminate(ec); return; + } else if ((ec == asio::error::eof) or (ec == asio::error::connection_reset)){ terminate(ec); return;