Merge pull request #4940 from sjnewbury/wiimote-connect

Retry opening of wiimote channels on initial failure
This commit is contained in:
Leo Lam 2017-06-19 10:56:09 +02:00 committed by GitHub
commit 1be10e7ebc
1 changed files with 37 additions and 7 deletions

View File

@ -140,22 +140,52 @@ bool WiimoteLinux::ConnectInternal()
// Output channel
addr.l2_psm = htobs(WC_OUTPUT);
if ((m_cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_cmd_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
if (m_cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP))
{
int retry = 0;
while (connect(m_cmd_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{
// If opening channel fails sleep and try again
if (retry == 3)
{
WARN_LOG(WIIMOTE, "Unable to connect output channel to Wiimote: %s", strerror(errno));
close(m_cmd_sock);
m_cmd_sock = -1;
return false;
}
retry++;
sleep(1);
}
}
else
{
WARN_LOG(WIIMOTE, "Unable to open output socket to Wiimote: %s", strerror(errno));
close(m_cmd_sock);
m_cmd_sock = -1;
return false;
}
// Input channel
addr.l2_psm = htobs(WC_INPUT);
if ((m_int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_int_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
if (m_int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP))
{
int retry = 0;
while (connect(m_int_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{
// If opening channel fails sleep and try again
if (retry == 3)
{
WARN_LOG(WIIMOTE, "Unable to connect input channel to Wiimote: %s", strerror(errno));
close(m_int_sock);
close(m_cmd_sock);
m_int_sock = m_cmd_sock = -1;
return false;
}
retry++;
sleep(1);
}
}
else
{
WARN_LOG(WIIMOTE, "Unable to open input socket from Wiimote: %s", strerror(errno));
close(m_int_sock);
close(m_cmd_sock);
m_int_sock = m_cmd_sock = -1;
return false;