From d30e0ea28e286805afeec650bc3370dc96c10b2c Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Fri, 31 Mar 2017 14:09:13 -0700 Subject: [PATCH] GBASockServer: clean up Receive() return value --- Source/Core/Core/HW/SI/SI_DeviceGBA.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp index 382fadd749..83676f39a5 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp @@ -262,8 +262,7 @@ void GBASockServer::Send(const u8* si_buffer) int GBASockServer::Receive(u8* si_buffer) { if (!m_client) - if (!GetAvailableSock(m_client)) - return 5; + return 0; if (m_booted) { @@ -279,22 +278,18 @@ int GBASockServer::Receive(u8* si_buffer) if (recv_stat == sf::Socket::Disconnected) { Disconnect(); - return 5; + return 0; } if (recv_stat == sf::Socket::NotReady) num_received = 0; - if (num_received > recv_data.size()) - num_received = recv_data.size(); - if (num_received > 0) { for (size_t i = 0; i < recv_data.size(); i++) si_buffer[i ^ 3] = recv_data[i]; } - - return static_cast(num_received); + return static_cast(std::min(num_received, recv_data.size())); } 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); #endif } + else + { + num_data_received = 5; + } if (num_data_received > 0) m_next_action = NextAction::SendCommand; return num_data_received;