Lib.Net: Misc fixes (#4082)

* Fix Windows-specific incorrect error in PosixSocket::Connect

* Hide typical non-blocking errors

* Also hide EWOULDBLOCK from recvfrom

* Fix the resolver fix
This commit is contained in:
Stephen Miller 2026-02-28 01:09:01 -06:00 committed by GitHub
parent aae10ecdf7
commit 49c2a4999b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View File

@ -35,8 +35,11 @@ void Resolver::Resolve() {
if (async_resolution) {
auto* netinfo = Common::Singleton<NetUtil::NetUtilInternal>::Instance();
auto ret = netinfo->ResolveHostname(async_resolution->hostname, async_resolution->addr);
// Resolver errors are stored as ORBIS_NET_ERROR values.
resolution_error = -ret | ORBIS_NET_ERROR_BASE;
resolution_error = ret;
if (ret != ORBIS_OK) {
// Resolver errors are stored as ORBIS_NET_ERROR values.
resolution_error = -ret | ORBIS_NET_ERROR_BASE;
}
} else {
LOG_ERROR(Lib_Net, "async resolution has not been set-up");
}

View File

@ -430,6 +430,15 @@ int PosixSocket::Connect(const OrbisNetSockaddr* addr, u32 namelen) {
sockaddr addr2;
convertOrbisNetSockaddrToPosix(addr, &addr2);
int result = ::connect(sock, &addr2, sizeof(sockaddr_in));
#ifdef _WIN32
// Winsock returns EWOULDBLOCK where real hardware returns EINPROGRESS
// Step in here on errors to address this.
if (result == -1) {
if (WSAGetLastError() == WSAEWOULDBLOCK) {
WSASetLastError(WSAEINPROGRESS);
}
}
#endif
LOG_DEBUG(Lib_Net, "raw connect result = {}, errno = {}", result,
result == -1 ? Common::GetLastErrorMsg() : "none");
return ConvertReturnErrorCode(result);

View File

@ -28,8 +28,11 @@ int PS4_SYSV_ABI sys_connect(OrbisNetId s, const OrbisNetSockaddr* addr, u32 add
if (returncode >= 0) {
return returncode;
}
LOG_ERROR(Lib_Net, "s = {} ({}) returned error code: {}", s, file->m_guest_name,
(u32)*Libraries::Kernel::__Error());
u32 error = *Libraries::Kernel::__Error();
// Don't log EINPROGRESS or EISCONN, these are normal to see from non-blocking communication.
if (error != ORBIS_NET_EINPROGRESS && error != ORBIS_NET_EISCONN) {
LOG_ERROR(Lib_Net, "s = {} ({}) returned error code: {}", s, file->m_guest_name, error);
}
return -1;
}
@ -59,8 +62,13 @@ int PS4_SYSV_ABI sys_accept(OrbisNetId s, OrbisNetSockaddr* addr, u32* paddrlen)
LOG_DEBUG(Lib_Net, "s = {} ({})", s, file->m_guest_name);
auto new_sock = file->socket->Accept(addr, paddrlen);
if (!new_sock) {
LOG_ERROR(Lib_Net, "s = {} ({}) returned error code creating new socket for accepting: {}",
s, file->m_guest_name, (u32)*Libraries::Kernel::__Error());
u32 error = *Libraries::Kernel::__Error();
// Don't log EWOULDBLOCK, this is normal to see from non-blocking communication.
if (error != ORBIS_NET_EWOULDBLOCK) {
LOG_ERROR(Lib_Net,
"s = {} ({}) returned error code creating new socket for accepting: {}", s,
file->m_guest_name, error);
}
return -1;
}
auto fd = FDTable::Instance()->CreateHandle();
@ -396,8 +404,11 @@ s64 PS4_SYSV_ABI sys_recvfrom(OrbisNetId s, void* buf, u64 len, int flags, Orbis
if (returncode >= 0) {
return returncode;
}
LOG_ERROR(Lib_Net, "s = {} ({}) returned error code: {}", s, file->m_guest_name,
(u32)*Libraries::Kernel::__Error());
// Don't log EWOULDBLOCK, this is normal to see from non-blocking communication.
u32 error = *Libraries::Kernel::__Error();
if (error != ORBIS_NET_EWOULDBLOCK) {
LOG_ERROR(Lib_Net, "s = {} ({}) returned error code: {}", s, file->m_guest_name, error);
}
return -1;
}