Skip to content

Commit

Permalink
SI_DeviceGBA: if a client doesn't respond within 1s, disconnect them
Browse files Browse the repository at this point in the history
Rather than returning 0 / not creating an expected SI interrupt. You can
test this by running VBA-M in a debugger and stopping it while it's
connected to Dolphin: on current master, Dolphin will freeze-up until it
gets a response. With this PR, Dolphin will gracefully disconnect the device, and reconnect if it starts responding again.
  • Loading branch information
ligfx committed Jul 14, 2017
1 parent f004dfa commit becb1a7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Source/Core/Core/HW/SI/SI_DeviceGBA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ int GBASockServer::Receive(u8* si_buffer)
return 0;
}

if (recv_stat == sf::Socket::NotReady)
num_received = 0;

if (num_received > 0)
if (recv_stat == sf::Socket::NotReady || num_received == 0)
{
for (size_t i = 0; i < recv_data.size(); i++)
si_buffer[i ^ 3] = recv_data[i];
m_booted = false;
return 0;
}

for (size_t i = 0; i < recv_data.size(); i++)
si_buffer[i ^ 3] = recv_data[i];
return static_cast<int>(std::min(num_received, recv_data.size()));
}

Expand Down Expand Up @@ -329,9 +329,9 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int length)
case NextAction::ReceiveResponse:
{
int num_data_received = m_sock_server.Receive(buffer);
if (!m_sock_server.IsConnected())
m_next_action = NextAction::SendCommand;
if (num_data_received == 0)
{
m_next_action = NextAction::SendCommand;
constexpr u32 reply = SI_ERROR_NO_RESPONSE;
std::memcpy(buffer, &reply, sizeof(reply));
return sizeof(reply);
Expand All @@ -344,8 +344,6 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int length)
"%01d [< %02x%02x%02x%02x%02x] (%i)", m_device_number,
buffer[3], buffer[2], buffer[1], buffer[0], buffer[7], num_data_received);
#endif
if (num_data_received > 0)
m_next_action = NextAction::SendCommand;
return num_data_received;
}
}
Expand Down

0 comments on commit becb1a7

Please sign in to comment.