Merge branch 'linux-wiimote-crash-fix'
This commit is contained in:
commit
240ea0f116
|
@ -36,6 +36,11 @@ void Wiimote::RealDisconnect()
|
|||
return;
|
||||
}
|
||||
|
||||
bool Wiimote::IsOpen() const
|
||||
{
|
||||
return IsConnected();
|
||||
}
|
||||
|
||||
int Wiimote::IORead(unsigned char* buf)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -136,10 +136,10 @@ int FindWiimotes(Wiimote** wm, int max_wiimotes)
|
|||
// Connect to a wiimote with a known address.
|
||||
bool Wiimote::Connect()
|
||||
{
|
||||
struct sockaddr_l2 addr;
|
||||
|
||||
if (IsConnected()) return false;
|
||||
if (IsConnected())
|
||||
return false;
|
||||
|
||||
sockaddr_l2 addr;
|
||||
addr.l2_family = AF_BLUETOOTH;
|
||||
addr.l2_bdaddr = bdaddr;
|
||||
addr.l2_cid = 0;
|
||||
|
@ -195,28 +195,36 @@ 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)
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int r;
|
||||
|
||||
if (!IsConnected())
|
||||
return 0;
|
||||
|
||||
// Block select for 1/2000th of a second
|
||||
timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = WIIMOTE_DEFAULT_TIMEOUT * 1000;
|
||||
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(in_sock, &fds);
|
||||
|
||||
|
@ -230,7 +238,7 @@ int Wiimote::IORead(unsigned char *buf)
|
|||
return 0;
|
||||
|
||||
// Read the pending message into the buffer
|
||||
r = read(in_sock, buf, MAX_PAYLOAD);
|
||||
int r = read(in_sock, buf, MAX_PAYLOAD);
|
||||
if (r == -1)
|
||||
{
|
||||
// Error reading data
|
||||
|
@ -241,17 +249,17 @@ 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;
|
||||
}
|
||||
if (!r)
|
||||
else if (!r)
|
||||
{
|
||||
// Disconnect
|
||||
RealDisconnect();
|
||||
return 0;
|
||||
Close();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -227,6 +227,11 @@ void Wiimote::RealDisconnect()
|
|||
ichan = NULL;
|
||||
}
|
||||
|
||||
bool Wiimote::IsOpen() const
|
||||
{
|
||||
return IsConnected();
|
||||
}
|
||||
|
||||
int Wiimote::IORead(unsigned char *buf)
|
||||
{
|
||||
int bytes;
|
||||
|
|
|
@ -240,7 +240,7 @@ void Wiimote::Disconnect()
|
|||
DisableDataReporting();
|
||||
}
|
||||
|
||||
bool Wiimote::IsConnected()
|
||||
bool Wiimote::IsConnected() const
|
||||
{
|
||||
return m_connected;
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ void Wiimote::ThreadFunc()
|
|||
Rumble();
|
||||
|
||||
// main loop
|
||||
while (IsConnected())
|
||||
while (IsOpen())
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
while (Write()) {}
|
||||
|
|
|
@ -53,7 +53,8 @@ public:
|
|||
bool Read();
|
||||
bool Write();
|
||||
bool Connect();
|
||||
bool IsConnected();
|
||||
bool IsConnected() const;
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue