better fix for linux wiimote disconnect crash

This commit is contained in:
Jordan Woyak 2013-01-10 16:16:49 -06:00
parent e1c8bea2f6
commit 1c10d3a1bb
5 changed files with 35 additions and 11 deletions

View File

@ -195,20 +195,30 @@ void Wiimote::RealDisconnect()
if (m_wiimote_thread.joinable())
m_wiimote_thread.join();
Host_ConnectWiimote(index, false);
Close();
}
close(out_sock);
close(in_sock);
void Wiimote::Close()
{
if (IsOpen())
{
Host_ConnectWiimote(index, false);
out_sock = -1;
in_sock = -1;
close(out_sock);
close(in_sock);
out_sock = -1;
in_sock = -1;
}
}
bool Wiimote::IsOpen() const
{
return out_sock != -1 && in_sock != -1;
}
int Wiimote::IORead(unsigned char *buf)
{
if (!IsConnected())
return 0;
// Block select for 1/2000th of a second
timeval tv;
tv.tv_sec = 0;
@ -239,7 +249,7 @@ int Wiimote::IORead(unsigned char *buf)
// This can happen if the bluetooth dongle is disconnected
ERROR_LOG(WIIMOTE, "Bluetooth appears to be disconnected. "
"Wiimote %i will be disconnected.", index + 1);
//RealDisconnect();
Close();
}
return 0;
@ -247,7 +257,7 @@ int Wiimote::IORead(unsigned char *buf)
else if (!r)
{
// Disconnect
//RealDisconnect();
Close();
}
return r;

View File

@ -294,6 +294,11 @@ void Wiimote::RealDisconnect()
ResetEvent(&hid_overlap);
}
bool Wiimote::IsOpen() const
{
return IsConnected();
}
int Wiimote::IORead(unsigned char* buf)
{
DWORD b, r;

View File

@ -227,6 +227,11 @@ void Wiimote::RealDisconnect()
ichan = NULL;
}
bool Wiimote::IsOpen() const
{
return IsConnected();
}
int Wiimote::IORead(unsigned char *buf)
{
int bytes;

View File

@ -312,7 +312,7 @@ void Wiimote::ThreadFunc()
Rumble();
// main loop
while (IsConnected())
while (IsOpen())
{
#ifdef __APPLE__
while (Write()) {}

View File

@ -54,6 +54,7 @@ public:
bool Write();
bool Connect();
bool IsConnected();
bool IsOpen() const;
void Disconnect();
void DisableDataReporting();
void Rumble();
@ -72,6 +73,9 @@ public:
bdaddr_t bdaddr; // Bluetooth address
int out_sock; // Output socket
int in_sock; // Input socket
void Close();
#elif defined(_WIN32)
char devicepath[255]; // Unique wiimote reference
//ULONGLONG btaddr; // Bluetooth address