HW/WiimoteReal: Replace invalid select call with poll.

This commit is contained in:
Jordan Woyak 2019-11-09 18:45:35 -06:00
parent 59ebaed81c
commit e85e51e5ce

View File

@ -6,7 +6,7 @@
#include <bluetooth/hci.h> #include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h> #include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h> #include <bluetooth/l2cap.h>
#include <sys/select.h> #include <sys/poll.h>
#include <unistd.h> #include <unistd.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -223,18 +223,23 @@ void WiimoteLinux::IOWakeup()
// zero = error // zero = error
int WiimoteLinux::IORead(u8* buf) int WiimoteLinux::IORead(u8* buf)
{ {
fd_set fds; std::array<pollfd, 2> pollfds = {};
FD_ZERO(&fds);
FD_SET(m_int_sock, &fds);
FD_SET(m_wakeup_pipe_r, &fds);
if (select(m_int_sock + 1, &fds, nullptr, nullptr, nullptr) == -1) auto& poll_wakeup = pollfds[0];
poll_wakeup.fd = m_wakeup_pipe_r;
poll_wakeup.events = POLLIN;
auto& poll_sock = pollfds[1];
poll_sock.fd = m_int_sock;
poll_sock.events = POLLIN;
if (poll(pollfds.data(), pollfds.size(), -1) == -1)
{ {
ERROR_LOG(WIIMOTE, "Unable to select Wiimote %i input socket.", m_index + 1); ERROR_LOG(WIIMOTE, "Unable to poll Wiimote %i input socket.", m_index + 1);
return -1; return -1;
} }
if (FD_ISSET(m_wakeup_pipe_r, &fds)) if (poll_wakeup.revents & POLLIN)
{ {
char c; char c;
if (read(m_wakeup_pipe_r, &c, 1) != 1) if (read(m_wakeup_pipe_r, &c, 1) != 1)
@ -244,7 +249,7 @@ int WiimoteLinux::IORead(u8* buf)
return -1; return -1;
} }
if (!FD_ISSET(m_int_sock, &fds)) if (!(poll_sock.revents & POLLIN))
return -1; return -1;
// Read the pending message into the buffer // Read the pending message into the buffer