BBA/HLE: Move polling data logic into a method

This commit is contained in:
Sepalani 2024-02-03 13:25:00 +04:00
parent fbebbcc0fd
commit f3194b777b
2 changed files with 36 additions and 32 deletions

View File

@ -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)
{
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;
@ -657,38 +691,7 @@ void CEXIETHERNET::BuiltInBBAInterface::ReadThreadHandler(CEXIETHERNET::BuiltInB
}
// Check network stack references
for (auto& net_ref : self->network_ref)
{
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();

View File

@ -463,6 +463,7 @@ private:
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);