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
Crashfix with asan, minor
  • Loading branch information
hrydgard committed Jan 8, 2025
commit cddd3d439d39e151d3d73f2d311e1a09798264bd
16 changes: 12 additions & 4 deletions Core/HLE/sceNetInet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
for (int i = SocketManager::MIN_VALID_INET_SOCKET; i < nfds; i++) {
if (readfds && (NetInetFD_ISSET(i, readfds))) {
SOCKET sock = g_socketManager.GetHostSocketFromInetSocket(i);
_dbg_assert_(sock != 0);
hostSockets[i] = sock;
DEBUG_LOG(Log::sceNet, "Input Read FD #%i (host: %d)", i, sock);
if (rdcnt < FD_SETSIZE) {
Expand All @@ -221,6 +222,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
}
if (writefds && (NetInetFD_ISSET(i, writefds))) {
SOCKET sock = g_socketManager.GetHostSocketFromInetSocket(i);
_dbg_assert_(sock != 0);
hostSockets[i] = sock;
DEBUG_LOG(Log::sceNet, "Input Write FD #%i (host: %d)", i, sock);
if (wrcnt < FD_SETSIZE) {
Expand All @@ -232,6 +234,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
}
if (exceptfds && (NetInetFD_ISSET(i, exceptfds))) {
SOCKET sock = g_socketManager.GetHostSocketFromInetSocket(i);
_dbg_assert_(sock != 0);
hostSockets[i] = sock;
DEBUG_LOG(Log::sceNet, "Input Except FD #%i (host: %d)", i, sock);
if (excnt < FD_SETSIZE) {
Expand All @@ -255,9 +258,10 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
}
DEBUG_LOG(Log::sceNet, "Select: Read count: %d, Write count: %d, Except count: %d, TimeVal: %u.%u", rdcnt, wrcnt, excnt, (int)tmout.tv_sec, (int)tmout.tv_usec);
// TODO: Simulate blocking behaviour when timeout = NULL to prevent PPSSPP from freezing
// Note: select can overwrite tmout.
int retval = select(nfds, readfds ? &rdfds : nullptr, writefds ? &wrfds : nullptr, exceptfds ? &exfds : nullptr, /*(timeout == NULL) ? NULL :*/ &tmout);
if (retval < 0) {
ERROR_LOG(Log::sceNet, "selected returned an error, TODO");
ERROR_LOG(Log::sceNet, "select returned an error, TODO");
}

// Convert the results back to PSP fd_sets.
Expand All @@ -270,13 +274,17 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
NetInetFD_ZERO(exceptfds);

for (int i = SocketManager::MIN_VALID_INET_SOCKET; i < nfds; i++) {
if (readfds && hostSockets[i] != 0 && FD_ISSET(hostSockets[i], &rdfds)) {
if (hostSockets[i] == 0) {
continue;
}
if (readfds && FD_ISSET(hostSockets[i], &rdfds)) {

NetInetFD_SET(i, readfds);
}
if (writefds && hostSockets[i] != 0 && FD_ISSET(hostSockets[i], &wrfds)) {
if (writefds && FD_ISSET(hostSockets[i], &wrfds)) {
NetInetFD_SET(i, writefds);
}
if (exceptfds && hostSockets[i] != 0 && FD_ISSET(hostSockets[i], &exfds)) {
if (exceptfds && FD_ISSET(hostSockets[i], &exfds)) {
NetInetFD_SET(i, exceptfds);
}
}
Expand Down
2 changes: 1 addition & 1 deletion UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static void DrawNp(ImConfig &cfg) {

SceNpId id{};
NpGetNpId(&id);
ImGui::Text("User Handle: %s", id.handle);
ImGui::Text("User Handle: %s", id.handle.data);
ImGui::End();
}

Expand Down