AMMediaboard: Replace select() with PlatformPoll in NetDIMMConnect.
This commit is contained in:
1 parent
587c825a9e
commit
4c61b9e009
1 file changed
+12
-19
@@ -556,37 +556,30 @@ static s32 NetDIMMConnect(GuestSocket guest_socket, sockaddr_in* addr, int len)
|
|||||||
|
|
||||||
addr->sin_family = Common::swap16(addr->sin_family);
|
addr->sin_family = Common::swap16(addr->sin_family);
|
||||||
|
|
||||||
const auto fd = GetHostSocket(guest_socket);
|
const auto host_socket = GetHostSocket(guest_socket);
|
||||||
|
|
||||||
u_long val = 1;
|
u_long val = 1;
|
||||||
// Set socket to non-blocking
|
// Set socket to non-blocking
|
||||||
ioctlsocket(fd, FIONBIO, &val);
|
ioctlsocket(host_socket, FIONBIO, &val);
|
||||||
|
|
||||||
int ret = connect(fd, reinterpret_cast<const sockaddr*>(addr), len);
|
int ret = connect(host_socket, reinterpret_cast<const sockaddr*>(addr), len);
|
||||||
const int err = WSAGetLastError();
|
const int err = WSAGetLastError();
|
||||||
|
|
||||||
if (ret == SOCKET_ERROR && err == WSAEWOULDBLOCK)
|
if (ret == SOCKET_ERROR && err == WSAEWOULDBLOCK)
|
||||||
{
|
{
|
||||||
fd_set writefds{};
|
WSAPOLLFD pfds[1]{{.fd = host_socket, .events = POLLOUT}};
|
||||||
FD_ZERO(&writefds);
|
|
||||||
FD_SET(fd, &writefds);
|
|
||||||
|
|
||||||
timeval timeout{};
|
const auto timeout =
|
||||||
timeout.tv_sec = 0;
|
duration_cast<std::chrono::milliseconds>(std::chrono::microseconds{s_timeouts[0]});
|
||||||
timeout.tv_usec = s_timeouts[0];
|
|
||||||
|
|
||||||
// TODO: Don't use select on Linux.
|
ret = PlatformPoll(pfds, timeout);
|
||||||
if (fd >= FD_SETSIZE)
|
|
||||||
{
|
|
||||||
ERROR_LOG_FMT(AMMEDIABOARD, "NetDIMMConnect: fd >= FD_SETSIZE");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = select(fd + 1, nullptr, &writefds, nullptr, &timeout);
|
if (ret > 0 && (pfds[0].revents & POLLOUT) != 0)
|
||||||
if (ret > 0 && FD_ISSET(fd, &writefds))
|
|
||||||
{
|
{
|
||||||
int so_error = 0;
|
int so_error = 0;
|
||||||
socklen_t optlen = sizeof(so_error);
|
socklen_t optlen = sizeof(so_error);
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&so_error), &optlen) == 0 &&
|
if (getsockopt(host_socket, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&so_error),
|
||||||
|
&optlen) == 0 &&
|
||||||
so_error == 0)
|
so_error == 0)
|
||||||
{
|
{
|
||||||
s_last_error = SSC_SUCCESS;
|
s_last_error = SSC_SUCCESS;
|
||||||
@@ -608,7 +601,7 @@ static s32 NetDIMMConnect(GuestSocket guest_socket, sockaddr_in* addr, int len)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(AMMEDIABOARD, "GC-AM: select() failed in NetDIMMConnect ({})",
|
ERROR_LOG_FMT(AMMEDIABOARD, "GC-AM: poll() failed in NetDIMMConnect ({})",
|
||||||
Common::StrNetworkError());
|
Common::StrNetworkError());
|
||||||
s_last_error = SOCKET_ERROR;
|
s_last_error = SOCKET_ERROR;
|
||||||
ret = SOCKET_ERROR;
|
ret = SOCKET_ERROR;
|
||||||
@@ -628,7 +621,7 @@ static s32 NetDIMMConnect(GuestSocket guest_socket, sockaddr_in* addr, int len)
|
|||||||
|
|
||||||
// Restore blocking mode
|
// Restore blocking mode
|
||||||
val = 0;
|
val = 0;
|
||||||
ioctlsocket(fd, FIONBIO, &val);
|
ioctlsocket(host_socket, FIONBIO, &val);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user