Commit Graph
247 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 2cb0be1bc4 UPnP: fix the exit hang and the CPU spin, and only run the thread when enabled
The two long-standing bug reports had a shared root: the service loop could
end up in a state it never left.

- Exit hang: UPNP_CMD_EXIT was queued alongside port requests and only acted
  on when it reached the front. A request that couldn't complete was never
  popped, so exit sat behind it forever and join() blocked indefinitely.
  Exit is a flag now, checked before anything else.
- CPU spin: wait_for() with a predicate returns immediately when the predicate
  already holds, so a stuck queue head meant a tight loop. sceNetInet's bind()
  queues UPnP_Add regardless of the setting, so this hit whenever UPnP was off
  and a game used sockets. The loop always blocks now, and requests are dropped
  while UPnP is off.
- Failed discovery was retried every 5s forever, each time a full 2s SSDP round
  plus an error toast. Now backs off 5s -> 300s and reports once.

Other things found while in here:

- Every failed Initialize() leaked a UPNPUrls + IGDdatas, so ~every 5 seconds
  for anyone with UPnP on and no router. The manual miniwget/parserootdesc/
  GetUPNPUrls block was also redundant - UPNP_GetValidIGD does all of it and
  memsets over the result, leaking the URLs and costing an extra HTTP round
  trip per attempt.
- UPNP_GetValidIGD's status was never checked, so we could go DONE with no
  usable IGD and hand a NULL controlURL to UPNP_GetConnectionTypeInfo.
- miniupnpc's strncpy into the port-mapping-entry buffers doesn't guarantee a
  terminator; an 80-char description ran std::string off the end of desc[80].
- Add() marked another app's port "taken" only after our own add succeeded, so
  a failed add left their mapping deleted and never restored.
- Clear() walked the router's entire table at exit, one HTTP round trip per
  index. It now deletes only what we know we mapped, and the exit cleanup has
  a time budget so an unreachable router can't stall shutdown.
- The in-flight request stayed in the queue during the router call, so a
  same-port request arriving concurrently could erase it and be dropped
  unexecuted.
- The queue is bounded, and last-write-wins per port collapses the churn from
  games that rebind in a loop.
- The mapping description is built when the request is queued rather than read
  off g_paramSFO from the UPnP thread later.

The thread now only exists while the setting is on - turning it off makes it
remove its mappings and exit, turning it on starts one. That means __UPnPInit()
has to run after the config is actually loaded; g_Config.Init() only builds a
lookup table. QueueRequest() reconciles too, so a per-game config or a libretro
core option enabling UPnP works without a notify at every call site.

The settings checkbox is disabled in-game, since sceNet latches related
settings at boot and a game that already mapped its ports wouldn't cope with
them disappearing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCPmm7FoQUoqrbMdhfqhQ2
2026-08-30 00:37:05 +02:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård 0596ee97f6 More memory access cleanup 2026-08-11 20:14:01 +02:00
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård 9396030f02 More Read_U32 cleanup 2026-08-11 09:08:52 +02:00
Henrik Rydgård 00126e4c6f Correct some logging categories 2026-06-13 17:12:16 +02:00
Henrik Rydgård f60e27a9b7 Just some refactoring of the GPUStatistics struct, and more use of StringWriter 2026-05-29 14:40:31 +02:00
Henrik Rydgård 61e76fcf68 Add the ability to hide adhoc servers using a "hidden" entry in the json.
Useful when servers are temporarily down.
2026-04-23 11:12:58 +02:00
Henrik Rydgård 962d132e5f Make the adhoc server list data driven 2026-03-05 15:15:25 +01:00
MMaZaHaKa 433ac5d5b3 upd sceNet 2026-01-19 21:53:11 +02:00
MMaZaHaKa d957c33989 anti uaf 2026-01-19 21:47:23 +02:00
MMaZaHaKa aa350b3082 upd proAdhoc 2026-01-16 06:17:03 +02:00
Henrik Rydgård d43b1d4618 String function cleanup 2025-08-31 14:45:41 +02:00
Henrik Rydgård 3e2dce1e54 Move AdHoc error codes to the big enum, fix the naming convention to be consistent 2025-08-06 17:44:54 +02:00
Henrik Rydgård 05b82d6ce4 Allow passing in a custom resolver to HTTPRequest and Connection. This inverts the bad dependency. 2025-08-06 00:16:34 +02:00
Henrik Rydgård 3110159bd7 Fix the bAllowSpeedControlWhileConnected flag 2025-07-25 15:30:02 +02:00
Nemoumbra d3d00d7d7b Start moving general adhoc stuff out of sceNetAdhoc 2025-07-01 19:56:09 +03:00
Henrik Rydgård 53718cdb21 Add option to allow speed control while connected
It's pretty easy to cheat this anyway by using an old PPSSPP, and some
people seem to want this for PSO.

I put it at the bottom of network settings and added "(not recommended)"
to emphasize that it's, well, not recommended.
2025-06-11 10:36:24 +02:00
Henrik Rydgård dbe6ec80a0 Fix some bad "for (auto x : y)" usage 2025-04-29 16:46:14 +02:00
Henrik Rydgård da7c99a585 sceNetInet: Implement per-thread errno. Reduce some log levels 2025-04-08 08:31:09 +02:00
Henrik Rydgård 0450728399 Add a super simple session cache for direct DNS lookups.
Dont even try to download the json if dontdownloadjson is set.
2025-04-08 00:41:08 +02:00
Henrik Rydgård ebcf6be42c When (successfully) using dyn_dns, remove fixed lookups.
Additionally some various cleanup.
2025-04-08 00:32:40 +02:00
Henrik Rydgård 9738a9511f Build and warning fixes 2025-04-07 23:17:56 +02:00
Henrik Rydgård b34f34ebde Move some more error codes to the big enum 2025-04-07 22:25:36 +02:00
Henrik Rydgård 89c0b5f20b sceNetResolver: Move error codes to enum, modernize logging 2025-04-07 22:16:32 +02:00
Henrik Rydgård 279c6fdd3c Don't leave a shared_ptr to the json download sticking around, consume it. 2025-04-07 21:41:41 +02:00
Henrik Rydgård 5f7b698012 Lots of logging and cleanup. 2025-04-07 21:40:52 +02:00
Henrik Rydgård 651cefb6fc Remove redundant functions 2025-04-07 16:48:08 +02:00
Henrik Rydgård 370a521381 Move UPnP init/shutdown to app init/shutdown instead of game init/shutdown 2025-04-07 16:46:04 +02:00
Henrik Rydgård 4e25f44eef Rename some module-related functions to include HLE where appropriate 2025-03-31 11:17:50 +02:00
Henrik Rydgård 0f840e6240 Move JPEG error codes to the big enum, some include cleanup 2025-03-21 20:44:46 +01:00
Henrik Rydgård 5aa73ecb17 Fix backwards check for DontDownloadInfraJson 2025-02-17 16:20:42 -06:00
Henrik Rydgård d7ebed2d66 AutoDNS load fix in some situations 2025-02-17 16:20:41 -06:00
Henrik Rydgård 28b2c7f540 HLE log rename part 1: Remove duplicate log functions. Return type should be determined by metadata. 2025-01-29 09:45:39 +01:00
Henrik Rydgård 8818e440ad Add a hidden option to not download infra-dns.json, instead use the file from assets 2025-01-28 13:45:28 +01:00
Henrik Rydgård 7fa3b48650 Add extra safeguards, fall back to cached file if download fails. 2025-01-23 13:58:59 +01:00
Henrik Rydgård 7f877bb16b Implement simple file caching. 2025-01-23 13:28:51 +01:00
Henrik Rydgård e4d08407ab Add fake request class for cached responses. 2025-01-23 13:02:06 +01:00
Henrik Rydgård c3cc3da8fe Download infra-dns.json from metadata.ppsspp.org 2025-01-23 12:54:22 +01:00
Henrik Rydgård 57b6850ea0 Pause screen improvements 2025-01-22 11:50:01 +01:00
Henrik Rydgård a710faf27b Remove the Network Connected/Shutdown popups. Replace with more info on pause screen 2025-01-21 18:07:52 +01:00
Henrik Rydgård 1aef267acc Add more information to ImDebugger (ApCtl) 2025-01-21 12:22:32 +01:00
Henrik Rydgård 5d124d93f8 Make network connection detection (for pause screen purposes) a bit more strict. 2025-01-21 12:22:29 +01:00
Henrik Rydgård 6f0d28e083 Buildfix 2025-01-20 20:58:22 +01:00
Henrik Rydgård 58f336f64d Infrastructure: Only connect to adhoc server if connect_adhoc_for_grouping is set in the json 2025-01-20 20:58:22 +01:00
Henrik Rydgård eb10247d77 Skip showing regular notifications that don't have messages 2025-01-20 17:48:16 +01:00
Henrik Rydgård e24317b20b A lot more logging fixes 2025-01-20 12:20:21 +01:00
Henrik Rydgård 7d2ad6980e Another batch of changes 2025-01-20 12:20:21 +01:00
Henrik Rydgård 2523690584 Flip around so sceDelayResult is always outermost. Start using HLECall. 2025-01-20 12:20:18 +01:00
Henrik Rydgård 42a2dfbbc1 Convert more code 2025-01-19 17:34:29 +01:00