mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
support multiple RouterInfo request callbacks
This commit is contained in:
parent
d8f6c4a93d
commit
4afdca090d
2 changed files with 20 additions and 1 deletions
|
@ -83,8 +83,26 @@ namespace data
|
|||
dest->SetRequestComplete (requestComplete);
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||
if (!m_RequestedDestinations.emplace (destination, dest).second) // not inserted
|
||||
auto ret = m_RequestedDestinations.emplace (destination, dest);
|
||||
if (!ret.second) // not inserted
|
||||
{
|
||||
dest->SetRequestComplete (nullptr); // don't call requestComplete in destructor
|
||||
if (requestComplete)
|
||||
{
|
||||
auto prev = ret.first->second->GetRequestComplete ();
|
||||
if (prev) // if already set
|
||||
ret.first->second->SetRequestComplete (
|
||||
[requestComplete, prev](std::shared_ptr<RouterInfo> r)
|
||||
{
|
||||
prev (r); // call previous
|
||||
requestComplete (r); // then new
|
||||
});
|
||||
else
|
||||
ret.first->second->SetRequestComplete (requestComplete);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue