GBASockServer: clean up Receive() return value

This commit is contained in:
Michael Maltese 2017-03-31 14:09:13 -07:00
parent 89ca32daa6
commit d30e0ea28e

View File

@ -262,8 +262,7 @@ void GBASockServer::Send(const u8* si_buffer)
int GBASockServer::Receive(u8* si_buffer) int GBASockServer::Receive(u8* si_buffer)
{ {
if (!m_client) if (!m_client)
if (!GetAvailableSock(m_client)) return 0;
return 5;
if (m_booted) if (m_booted)
{ {
@ -279,22 +278,18 @@ int GBASockServer::Receive(u8* si_buffer)
if (recv_stat == sf::Socket::Disconnected) if (recv_stat == sf::Socket::Disconnected)
{ {
Disconnect(); Disconnect();
return 5; return 0;
} }
if (recv_stat == sf::Socket::NotReady) if (recv_stat == sf::Socket::NotReady)
num_received = 0; num_received = 0;
if (num_received > recv_data.size())
num_received = recv_data.size();
if (num_received > 0) if (num_received > 0)
{ {
for (size_t i = 0; i < recv_data.size(); i++) for (size_t i = 0; i < recv_data.size(); i++)
si_buffer[i ^ 3] = recv_data[i]; si_buffer[i ^ 3] = recv_data[i];
} }
return static_cast<int>(std::min(num_received, recv_data.size()));
return static_cast<int>(num_received);
} }
CSIDevice_GBA::CSIDevice_GBA(SIDevices device, int device_number) : ISIDevice(device, device_number) CSIDevice_GBA::CSIDevice_GBA(SIDevices device, int device_number) : ISIDevice(device, device_number)
@ -352,6 +347,10 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int length)
num_data_received); num_data_received);
#endif #endif
} }
else
{
num_data_received = 5;
}
if (num_data_received > 0) if (num_data_received > 0)
m_next_action = NextAction::SendCommand; m_next_action = NextAction::SendCommand;
return num_data_received; return num_data_received;