Skip to content

Commit

Permalink
DEV9: Slightly simplify UDP socket closing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored and stenzek committed May 9, 2024
1 parent b3bb409 commit d7101c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
27 changes: 11 additions & 16 deletions pcsx2/DEV9/Sessions/UDP_Session/UDP_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ namespace Sessions

IP_Payload* UDP_Session::Recv()
{
if (!open)
if (!open.load())
return nullptr;

if (isFixedPort)
{
if (std::chrono::steady_clock::now() - deathClockStart.load() > MAX_IDLE)
{
CloseSocket();
Console.WriteLn("DEV9: UDP: Fixed port max idle reached");
open.store(false);
RaiseEventConnectionClosed();
}
return nullptr;
Expand Down Expand Up @@ -178,7 +178,7 @@ namespace Sessions

bool UDP_Session::WillRecive(IP_Address parDestIP)
{
if (!open)
if (!open.load())
return false;

if (isBroadcast || isMulticast || (parDestIP == destIP))
Expand Down Expand Up @@ -273,7 +273,7 @@ namespace Sessions
}

if (srcPort != 0)
open = true;
open.store(true);
}

PayloadPtr* udpPayload = static_cast<PayloadPtr*>(udp.GetPayload());
Expand Down Expand Up @@ -360,9 +360,14 @@ namespace Sessions
return true;
}

void UDP_Session::CloseSocket()
void UDP_Session::Reset()
{
RaiseEventConnectionClosed();
}

UDP_Session::~UDP_Session()
{
open = false;
open.store(false);
if (!isFixedPort && client != INVALID_SOCKET)
{
#ifdef _WIN32
Expand All @@ -373,14 +378,4 @@ namespace Sessions
client = INVALID_SOCKET;
}
}

void UDP_Session::Reset()
{
RaiseEventConnectionClosed();
}

UDP_Session::~UDP_Session()
{
CloseSocket();
}
} // namespace Sessions
3 changes: 0 additions & 3 deletions pcsx2/DEV9/Sessions/UDP_Session/UDP_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,5 @@ namespace Sessions
virtual void Reset();

virtual ~UDP_Session();

private:
void CloseSocket();
};
} // namespace Sessions

0 comments on commit d7101c3

Please sign in to comment.