mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Use std::unique_ptr for tracking active pings
This commit is contained in:
parent
9da3bccca2
commit
48a1ec3531
|
@ -685,7 +685,7 @@ namespace Sessions
|
||||||
pingRet = pings[i]->Recv();
|
pingRet = pings[i]->Recv();
|
||||||
if (pingRet != nullptr)
|
if (pingRet != nullptr)
|
||||||
{
|
{
|
||||||
Ping* ping = pings[i];
|
std::unique_ptr<Ping> ping = std::move(pings[i]);
|
||||||
// Remove ping from list and unlock mutex
|
// Remove ping from list and unlock mutex
|
||||||
pings.erase(pings.begin() + i);
|
pings.erase(pings.begin() + i);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
@ -729,9 +729,6 @@ namespace Sessions
|
||||||
else
|
else
|
||||||
DevCon.WriteLn("DEV9: ICMP: ICMP timeout");
|
DevCon.WriteLn("DEV9: ICMP: ICMP timeout");
|
||||||
|
|
||||||
// Free ping
|
|
||||||
delete ping;
|
|
||||||
|
|
||||||
if (ret.has_value())
|
if (ret.has_value())
|
||||||
DevCon.WriteLn("DEV9: ICMP: Return Ping");
|
DevCon.WriteLn("DEV9: ICMP: Return Ping");
|
||||||
|
|
||||||
|
@ -848,13 +845,12 @@ namespace Sessions
|
||||||
DevCon.WriteLn("DEV9: ICMP: Send Ping");
|
DevCon.WriteLn("DEV9: ICMP: Send Ping");
|
||||||
open++;
|
open++;
|
||||||
|
|
||||||
Ping* ping = new Ping(icmpPayload->GetLength());
|
std::unique_ptr<Ping> ping = std::make_unique<Ping>(icmpPayload->GetLength());
|
||||||
|
|
||||||
if (!ping->IsInitialised())
|
if (!ping->IsInitialised())
|
||||||
{
|
{
|
||||||
if (--open == 0)
|
if (--open == 0)
|
||||||
RaiseEventConnectionClosed();
|
RaiseEventConnectionClosed();
|
||||||
delete ping;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,7 +858,6 @@ namespace Sessions
|
||||||
{
|
{
|
||||||
if (--open == 0)
|
if (--open == 0)
|
||||||
RaiseEventConnectionClosed();
|
RaiseEventConnectionClosed();
|
||||||
delete ping;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,7 +868,7 @@ namespace Sessions
|
||||||
|
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(ping_mutex);
|
std::scoped_lock lock(ping_mutex);
|
||||||
pings.push_back(ping);
|
pings.push_back(std::move(ping));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -892,10 +887,8 @@ namespace Sessions
|
||||||
|
|
||||||
ICMP_Session::~ICMP_Session()
|
ICMP_Session::~ICMP_Session()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(ping_mutex);
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
for (size_t i = 0; i < pings.size(); i++)
|
std::scoped_lock lock(ping_mutex);
|
||||||
delete pings[i];
|
pings.clear();
|
||||||
}
|
}
|
||||||
} // namespace Sessions
|
} // namespace Sessions
|
||||||
|
|
|
@ -68,9 +68,8 @@ namespace Sessions
|
||||||
~Ping();
|
~Ping();
|
||||||
};
|
};
|
||||||
|
|
||||||
SimpleQueue<PacketReader::IP::ICMP::ICMP_Packet*> _recvBuff;
|
|
||||||
std::mutex ping_mutex;
|
std::mutex ping_mutex;
|
||||||
std::vector<Ping*> pings;
|
std::vector<std::unique_ptr<Ping>> pings;
|
||||||
ThreadSafeMap<Sessions::ConnectionKey, Sessions::BaseSession*>* connections;
|
ThreadSafeMap<Sessions::ConnectionKey, Sessions::BaseSession*>* connections;
|
||||||
|
|
||||||
std::atomic<int> open{0};
|
std::atomic<int> open{0};
|
||||||
|
|
Loading…
Reference in New Issue