fix crash, but now 100% cpu usage on disconnect

This commit is contained in:
Jordan Woyak 2013-01-10 15:23:42 -06:00
parent d6b53af115
commit e1c8bea2f6
1 changed files with 10 additions and 12 deletions

View File

@ -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;
@ -206,17 +206,15 @@ void Wiimote::RealDisconnect()
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 +228,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 +239,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();
//RealDisconnect();
}
return 0;
}
if (!r)
else if (!r)
{
// Disconnect
RealDisconnect();
return 0;
//RealDisconnect();
}
return r;
}