fix(libkernel): answer kevent EV_CLEAR on Windows socket and pipe reads #15518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15518"
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 Opensource55 on 2026-11-03T17:10:29Z.
What
Waiting edge-triggered (
EV_CLEAR) on a socket or a pipe withkeventcalledNotImplemented_nid_no_patchon Windows, so a title that waits that way died at its first wait. This adds the Windows branch ofcore/libs/prx/libkernel/Equeue/src/EdgeWatch.cpp. A read edge is a poll of the unread byte count throughGuestSockets::Ready(FIONREADfor a socket, the free-space quota for a pipe): a growth, or a first end-of-file, reports. A write edge reports a change of the writable state, because Winsock has no send-queue query and recordsFD_WRITEagain only after a send failed withWSAEWOULDBLOCK.Watch::Opentakes the guest descriptor as well, because the Windows branch asksGuestSockets::Readyby guest descriptor; Linux and macOS keep using the host descriptor and ignore the new argument. The Windows watch registersstd::numeric_limits<int>::max()as its wait descriptor instead of the socket: that value is not a host socket, soGuestSockets::WaitAnytreats it the way it treats a pipe, waits in one-millisecond slices and lets the wait loop re-evaluate the knote. Waiting on the socket itself makes every wait return while the socket stays readable and unread, which spins: 0.156 s of thread CPU over a 150 ms idle wait, against 0.000 s with the slice.The
kevent EV_CLEARentry indocs/dev/debt/libkernel.mdno longer says Windows throws. It records what stays open there: an activation that arrives while more bytes are consumed than added is missed, every edge carries up to a millisecond of delay, and the write side only tracks the writable state. For that reasonEdgeTriggeredSocketWriteandSocketWriteLowWaterWhileFillingstay Linux-only, and the two assertions that expectedEV_CLEARto throw off Linux are gone.Tested
Windows 10 22H2 (19045.6456), MinGW-W64 GCC 15.2.0 (ucrt, Release build), the repository's own
guest_kqueueandguest_kqueue_cleared_racetests (ctest #3559 and #3560); no title was run.With this change the three cases that were
#ifdef __linux__build and pass on Windows. They cover a read edge on a socket pair (3 bytes report once, a second poll reports nothing, 1 more byte reports again, re-adding withEV_ADDreports immediately, end-of-file reports once), a read edge on a pipe, andEV_CLEARdispatch through a watched kqueue. A 150 ms idle wait with a socket knote registered costs 0.000 s of thread CPU.ctest --test-dir build -R "^guest_kqueue" --output-on-failure: 2 of 2 passed in 7.08 s (guest_kqueue4.60 s,guest_kqueue_cleared_race2.26 s), so the whole file-event, socket and pipe suite passes on Windows with this change.Red side: with
EdgeWatch.cpp,EdgeWatch.hppandKqueue.cpptaken frommainand the tests kept, the same run throwskevent: EV_CLEAR on a socket or a pipe off Linux not implemented.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)