Skip to content

Commit

Permalink
BBA/HLE: Move polling data logic into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
sepalani committed Feb 3, 2024
1 parent 8d4abd4 commit 305b41b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
67 changes: 35 additions & 32 deletions Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,40 @@ void CEXIETHERNET::BuiltInBBAInterface::WriteToQueue(const std::vector<u8>& data
m_queue_write = next_write_index;
}

void CEXIETHERNET::BuiltInBBAInterface::PollData(std::size_t* datasize)
{
for (auto& net_ref : network_ref.data())
{
if (net_ref.ip == 0)
continue;

// Check for sleeping TCP data
if (net_ref.type == IPPROTO_TCP)
{
for (auto& tcp_buf : net_ref.tcp_buffers)
{
if (!tcp_buf.used || (GetTickCountStd() - tcp_buf.tick) <= 1000)
continue;

tcp_buf.tick = GetTickCountStd();
// Timed out packet, resend
if (((m_queue_write + 1) & 15) != m_queue_read)
WriteToQueue(tcp_buf.data);
}
}

// Check for connection data
if (*datasize != 0)
continue;
const auto socket_data = TryGetDataFromSocket(&net_ref);
if (socket_data.has_value())
{
*datasize = socket_data->size();
std::memcpy(m_eth_ref->mRecvBuffer.get(), socket_data->data(), *datasize);
}
}
}

void CEXIETHERNET::BuiltInBBAInterface::HandleARP(const Common::ARPPacket& packet)
{
const auto& [hwdata, arpdata] = packet;
Expand Down Expand Up @@ -657,38 +691,7 @@ void CEXIETHERNET::BuiltInBBAInterface::ReadThreadHandler(CEXIETHERNET::BuiltInB
}

// Check network stack references
for (auto& net_ref : self->network_ref.data())
{
if (net_ref.ip == 0)
continue;

// Check for sleeping TCP data
if (net_ref.type == IPPROTO_TCP)
{
for (auto& tcp_buf : net_ref.tcp_buffers)
{
if (!tcp_buf.used || (GetTickCountStd() - tcp_buf.tick) <= 1000)
continue;

tcp_buf.tick = GetTickCountStd();
// Timed out packet, resend
if (((self->m_queue_write + 1) & 15) != self->m_queue_read)
{
self->WriteToQueue(tcp_buf.data);
}
}
}

// Check for connection data
if (datasize != 0)
continue;
const auto socket_data = self->TryGetDataFromSocket(&net_ref);
if (socket_data.has_value())
{
datasize = socket_data->size();
std::memcpy(self->m_eth_ref->mRecvBuffer.get(), socket_data->data(), datasize);
}
}
self->PollData(&datasize);

// Check for new UPnP client
self->HandleUPnPClient();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ class CEXIETHERNET : public IEXIDevice
static void ReadThreadHandler(BuiltInBBAInterface* self);
#endif
void WriteToQueue(const std::vector<u8>& data);
void PollData(std::size_t* datasize);
std::optional<std::vector<u8>> TryGetDataFromSocket(StackRef* ref);

void HandleARP(const Common::ARPPacket& packet);
Expand Down

0 comments on commit 305b41b

Please sign in to comment.