fix(libkernel): answer a receive after SHUT_RD or with no buffer without the host #8492
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8492"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T13:46:59Z.
What
recvandrecvfromhanded every receive to the host. On Windows that fails a receive aftershutdown(SHUT_RD)withWSAESHUTDOWN(reported asEPIPE) and blocks a zero-length receive on a stream socket until data arrives. FreeBSD 11.4'ssoreceive_genericreturns 0 for a socket whose receive side is shut and for a zero-length receive on a connected stream socket (ENOTCONNwhen it is not connected), without waiting; TCP uses it in 11.4. Both calls now answer these cases themselves, before any wait.recvfromalso reports a zero address length.recvmsgis unchanged. The Technical debt entry says so.Fixes #8491
Overlap:
git merge-treehas conflicts with #7090 (one), #8448 (one) and #8474 (two) inUdp.cpp; the others (#8392, #8463, #8483, #7511, #7850, #7490, #8312) are clean. Whichever lands second rebases.pr_overlapwas not run.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main
cabd80f472+ this commit:guest_tcp: the new case aborts without the change toUdp.cppand passes with it. It checks a zero-length receive on an unconnected socket (ENOTCONN) and on a connected one with and withoutMSG_DONTWAIT(0),recvfromreporting address length 0, andrecv/recvfromreturning 0 aftershutdown(SHUT_RD)even though the peer sent data.guest_datagram_recv,guest_sce_net,guest_socket_error,guest_socket_timeouts,guest_udp,guest_poll,guest_socket_pairandguest_recvmsg_memorypass.python tools/check_conventions.py --base upstream/main: passes.recvmsg.Checklist
main; no other open PR implements the same functions (#8483 and #7090 touchUdp.cppelsewhere).mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T13:55:38Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL191Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestTcp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppImported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-20T15:09:28Z.
Review: COMMENTED
Tested this change against current
main.Notes:
tools/check_conventions.py).guest_tcp_testsand ran CTest locally on Windows (MinGW-w64):soreceive_genericemulation matches expectations:socket.receiveShutavoids Winsock'sWSAESHUTDOWNreturningEPIPEto the guest, instead cleanly returning EOF (0).0when connected (orENOTCONNwhen unconnected viagetpeername), avoiding Winsock's blocking behavior on 0-length reads.recvfrom, correctly clears*addressLength = 0on answered receives where no sender address is produced.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T10:42:56Z.
On Linux (WSL2 Ubuntu 24.04, GCC 13.3, Release; not a bare-metal CI)
guest_socket_pairaborts at head bd895d132 and passes 30 of 30 runs at the merge basecabd80f47(ctest --repeat until-fail:30).GuestSocketPair.cpphas a non-Windows branch that callsshutdown(pair[1], SHUT_RD)and then expectsrecv(pair[1])to return the 5 buffered bytes andfstatto reportst_size == 5(lines 227-229). WithReceiveAnsweredHerea receive afterreceiveShutnow returns 0 on every host, so thatrecvreturns 0 instead of 5. FreeBSD discards the receive buffer onSHUT_RD(soshutdowncallssorflush), so 0 is what the console does, but the Linux/macOS branch of the test and the host behaviour pin the buffered data. Either thereceiveShutshortcut stays Windows-only (the PR title says Windows), or the non-Windows branch ofguest_socket_pairchanges to the FreeBSD result in the same PR; I did not try either. Not tested: macOS, a console.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T10:54:13Z.
Follow-up for the Linux failure reported above. The
receiveShutshortcut inReceiveAnsweredHerenow runs on Windows only (#ifdef _WIN32), so Linux keeps its host behaviour: data buffered beforeshutdown(SHUT_RD)is still readable, whichguest_socket_pairexpects. The post-shutdown receives inReceiveAnsweredWithoutTheHost(guest_tcp) are Windows-only for the same reason; the no-buffer part (zero-length receive,ENOTCONN) still runs everywhere. I chose this over making the shortcut FreeBSD-exact on Linux because the PR title and the reported case are Windows, and it leaves the Linux branch ofguest_socket_pairas it is.Checked: Linux (WSL2 Ubuntu 24.04, GCC 13.3, Release; not a bare-metal CI):
guest_socket_pair,guest_udpandguest_tcppass 30 consecutive runs each at the new head (ctest --repeat until-fail:30); at the old head bd895d1325guest_socket_pairaborts andguest_tcppasses, and with only theUdp.cppchangeguest_tcpaborts on its post-shutdown receives, which is why the test is Windows-only now. Windows 10 (MinGW GCC 15.2, Release): the same three tests pass 5 of 5 runs.check_conventionspasses. Not tested: macOS, a console.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:40:31Z.
Checked the diff against FreeBSD 11.4
soreceive_generic(SBS_CANTRCVMORE returns 0, zero-length stream receive returns 0 orENOTCONN), the newguest_tcpcase (the zero-length rows fail without the change) and the Linuxguest_socket_pairfollow-up. Rebased ontomain(conflicts with #8474 inGuestTcp.cppanddocs/dev/debt/libkernel.md, both kept) and pushed one commit: the debt entry now says the post-SHUT_RDanswer is Windows only and that Linux/macOS still return data buffered before the shutdown; merged.