DEV9: Slightly simplify UDP socket closing

This commit is contained in:
TheLastRar 2024-05-01 22:14:05 +01:00 committed by Connor McLaughlin
parent b3bb40980e
commit d7101c3be5
2 changed files with 11 additions and 19 deletions

View File

@ -61,15 +61,15 @@ namespace Sessions
IP_Payload* UDP_Session::Recv() IP_Payload* UDP_Session::Recv()
{ {
if (!open) if (!open.load())
return nullptr; return nullptr;
if (isFixedPort) if (isFixedPort)
{ {
if (std::chrono::steady_clock::now() - deathClockStart.load() > MAX_IDLE) if (std::chrono::steady_clock::now() - deathClockStart.load() > MAX_IDLE)
{ {
CloseSocket();
Console.WriteLn("DEV9: UDP: Fixed port max idle reached"); Console.WriteLn("DEV9: UDP: Fixed port max idle reached");
open.store(false);
RaiseEventConnectionClosed(); RaiseEventConnectionClosed();
} }
return nullptr; return nullptr;
@ -178,7 +178,7 @@ namespace Sessions
bool UDP_Session::WillRecive(IP_Address parDestIP) bool UDP_Session::WillRecive(IP_Address parDestIP)
{ {
if (!open) if (!open.load())
return false; return false;
if (isBroadcast || isMulticast || (parDestIP == destIP)) if (isBroadcast || isMulticast || (parDestIP == destIP))
@ -273,7 +273,7 @@ namespace Sessions
} }
if (srcPort != 0) if (srcPort != 0)
open = true; open.store(true);
} }
PayloadPtr* udpPayload = static_cast<PayloadPtr*>(udp.GetPayload()); PayloadPtr* udpPayload = static_cast<PayloadPtr*>(udp.GetPayload());
@ -360,9 +360,14 @@ namespace Sessions
return true; return true;
} }
void UDP_Session::CloseSocket() void UDP_Session::Reset()
{ {
open = false; RaiseEventConnectionClosed();
}
UDP_Session::~UDP_Session()
{
open.store(false);
if (!isFixedPort && client != INVALID_SOCKET) if (!isFixedPort && client != INVALID_SOCKET)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -373,14 +378,4 @@ namespace Sessions
client = INVALID_SOCKET; client = INVALID_SOCKET;
} }
} }
void UDP_Session::Reset()
{
RaiseEventConnectionClosed();
}
UDP_Session::~UDP_Session()
{
CloseSocket();
}
} // namespace Sessions } // namespace Sessions

View File

@ -52,8 +52,5 @@ namespace Sessions
virtual void Reset(); virtual void Reset();
virtual ~UDP_Session(); virtual ~UDP_Session();
private:
void CloseSocket();
}; };
} // namespace Sessions } // namespace Sessions