mirror of
https://github.com/drogonframework/drogon.git
synced 2025-09-28 00:00:52 -04:00
Use weakptr instead of shared_ptr (#1504)
Co-authored-by: Nitin Anand <gmail@an.andnit.in>
This commit is contained in:
parent
ae9d5f20b3
commit
54d96963f3
@ -289,24 +289,39 @@ void HttpClientImpl::sendRequestInLoop(const HttpRequestPtr &req,
|
|||||||
auto callbackPtr =
|
auto callbackPtr =
|
||||||
std::make_shared<drogon::HttpReqCallback>(std::move(callback));
|
std::make_shared<drogon::HttpReqCallback>(std::move(callback));
|
||||||
auto thisPtr = shared_from_this();
|
auto thisPtr = shared_from_this();
|
||||||
loop_->runAfter(timeout, [timeoutFlag, callbackPtr, req, thisPtr] {
|
loop_->runAfter(timeout,
|
||||||
if (*timeoutFlag)
|
[timeoutFlag,
|
||||||
{
|
weakCallbackPtr =
|
||||||
return;
|
std::weak_ptr<HttpReqCallback>(callbackPtr),
|
||||||
}
|
reqPtr = std::weak_ptr<HttpRequest>(req),
|
||||||
*timeoutFlag = true;
|
thisPtr] {
|
||||||
for (auto iter = thisPtr->requestsBuffer_.begin();
|
if (*timeoutFlag)
|
||||||
iter != thisPtr->requestsBuffer_.end();
|
{
|
||||||
++iter)
|
return;
|
||||||
{
|
}
|
||||||
if (iter->first == req)
|
*timeoutFlag = true;
|
||||||
{
|
|
||||||
thisPtr->requestsBuffer_.erase(iter);
|
auto req = reqPtr.lock();
|
||||||
break;
|
if (req != nullptr)
|
||||||
}
|
{
|
||||||
}
|
for (auto iter = thisPtr->requestsBuffer_.begin();
|
||||||
(*callbackPtr)(ReqResult::Timeout, nullptr);
|
iter != thisPtr->requestsBuffer_.end();
|
||||||
});
|
++iter)
|
||||||
|
{
|
||||||
|
if (iter->first == req)
|
||||||
|
{
|
||||||
|
thisPtr->requestsBuffer_.erase(iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto callbackPtr = weakCallbackPtr.lock();
|
||||||
|
if (callbackPtr != nullptr)
|
||||||
|
{
|
||||||
|
(*callbackPtr)(ReqResult::Timeout, nullptr);
|
||||||
|
}
|
||||||
|
});
|
||||||
sendRequestInLoop(req,
|
sendRequestInLoop(req,
|
||||||
[timeoutFlag, callbackPtr](ReqResult r,
|
[timeoutFlag, callbackPtr](ReqResult r,
|
||||||
const HttpResponsePtr &resp) {
|
const HttpResponsePtr &resp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user