diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp index b01caf06c8..1fb61f7715 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp @@ -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; }