diff --git a/Core/HLE/SocketManager.cpp b/Core/HLE/SocketManager.cpp index 533635abec..241b6fca53 100644 --- a/Core/HLE/SocketManager.cpp +++ b/Core/HLE/SocketManager.cpp @@ -8,7 +8,7 @@ SocketManager g_socketManager; static std::mutex g_socketMutex; // TODO: Remove once the adhoc thread is gone -InetSocket *SocketManager::CreateSocket(int *index, SocketState state, int domain, int type, int protocol) { +InetSocket *SocketManager::CreateSocket(int *index, int *returned_errno, SocketState state, int domain, int type, int protocol) { _dbg_assert_(state != SocketState::Unused); int hostDomain = convertSocketDomainPSP2Host(domain); @@ -17,6 +17,7 @@ InetSocket *SocketManager::CreateSocket(int *index, SocketState state, int domai SOCKET hostSock = ::socket(hostDomain, hostType, hostProtocol); if (hostSock < 0) { + *returned_errno = socket_errno; return nullptr; } @@ -32,6 +33,7 @@ InetSocket *SocketManager::CreateSocket(int *index, SocketState state, int domai inetSock->type = type; inetSock->protocol = protocol; inetSock->nonblocking = false; + *returned_errno = 0; return inetSock; } } @@ -40,6 +42,7 @@ InetSocket *SocketManager::CreateSocket(int *index, SocketState state, int domai ERROR_LOG(Log::sceNet, "Ran out of socket handles! This is BAD."); closesocket(hostSock); *index = 0; + *returned_errno = ENOMEM; // or something.. return nullptr; } diff --git a/Core/HLE/SocketManager.h b/Core/HLE/SocketManager.h index f16883b761..ecc9055112 100644 --- a/Core/HLE/SocketManager.h +++ b/Core/HLE/SocketManager.h @@ -31,7 +31,7 @@ public: MIN_VALID_INET_SOCKET = 61, }; - InetSocket *CreateSocket(int *index, SocketState state, int domain, int type, int protocol); + InetSocket *CreateSocket(int *index, int *returned_errno, SocketState state, int domain, int type, int protocol); bool GetInetSocket(int sock, InetSocket **inetSocket); SOCKET GetHostSocketFromInetSocket(int sock); bool Close(InetSocket *inetSocket); diff --git a/Core/HLE/sceNetInet.cpp b/Core/HLE/sceNetInet.cpp index 9c00f0e581..457b15bc72 100644 --- a/Core/HLE/sceNetInet.cpp +++ b/Core/HLE/sceNetInet.cpp @@ -393,9 +393,8 @@ static int sceNetInetSocket(int domain, int type, int protocol) { DEBUG_LOG(Log::sceNet, "Socket: Domain = %s, Type = %s, Protocol = %s", inetSocketDomain2str(domain).c_str(), inetSocketType2str(type).c_str(), inetSocketProto2str(protocol).c_str()); int socket; - InetSocket *inetSock = g_socketManager.CreateSocket(&socket, SocketState::UsedNetInet, domain, type, protocol); + InetSocket *inetSock = g_socketManager.CreateSocket(&socket, &inetLastErrno, SocketState::UsedNetInet, domain, type, protocol); if (!inetSock) { - inetLastErrno = socket_errno; return hleLogError(Log::sceNet, -1, "errno = %d", inetLastErrno); }