Fix an error of std::bad_function_call (#1115)

This commit is contained in:
An Tao 2021-12-09 19:25:39 +08:00 committed by GitHub
parent 7455355419
commit 66e29dd9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -345,12 +345,13 @@ void HttpClientImpl::sendRequestInLoop(const drogon::HttpRequestPtr &req,
if (!tcpClientPtr_)
{
auto callbackPtr =
std::make_shared<drogon::HttpReqCallback>(std::move(callback));
requestsBuffer_.push_back(
{req,
[thisPtr = shared_from_this(),
callback = std::move(callback)](ReqResult result,
const HttpResponsePtr &response) {
callback(result, response);
callbackPtr](ReqResult result, const HttpResponsePtr &response) {
(*callbackPtr)(result, response);
}});
if (!dns_)
{
@ -422,7 +423,7 @@ void HttpClientImpl::sendRequestInLoop(const drogon::HttpRequestPtr &req,
else
{
requestsBuffer_.pop_front();
callback(ReqResult::BadServerAddress, nullptr);
(*callbackPtr)(ReqResult::BadServerAddress, nullptr);
assert(requestsBuffer_.empty());
return;
}