Skip to content

sceNetInet socket remap #19827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better CreateSocket errro handling
  • Loading branch information
hrydgard committed Jan 8, 2025
commit 728268bb3f42da81aa202f60b617f14cdf11ad10
5 changes: 4 additions & 1 deletion Core/HLE/SocketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/SocketManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SocketManager {
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);
Expand Down
3 changes: 1 addition & 2 deletions Core/HLE/sceNetInet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading