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

View File

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

View File

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

View File

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

View File

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