Commit Graph
49 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 46d5fae342 VSH prep: Free up kernel memory by not storing the PPGe atlas in it 2026-08-19 18:45:52 +02:00
Henrik Rydgård f5bd302694 Improve DescribeAddress, show the description of the currently selected line in disassembly 2026-08-14 14:38:33 +02:00
Henrik Rydgård db8ff4391e Enable ImDebugger everywhere, on top of the regular UI. 2026-08-07 17:35:15 +02:00
Henrik Rydgård c1310ae4a5 Rework UPnP service thread sync
No longer waking up twice per second. Instead a slow 5s poll plus
wakeups if needed.
2026-08-07 11:24:22 +02:00
Henrik Rydgård 2b509e4b1e Minor cleanups, revert change in sceKernelMbx 2026-07-29 20:30:17 +02:00
Henrik Rydgård 95ce95e489 Add a new "Net" log category, do assorted cleanup 2026-06-13 14:43:59 +02:00
Henrik Rydgård 7cc4a0f3a3 Add more accurate sleep function (well, not more accurate on Windows unfortunately) 2025-10-21 12:11:23 +02:00
Henrik Rydgård 04684cc88b Minor error message improvement 2025-06-07 17:18:51 +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 ebfc467d5d Start removing bad coreState checks 2025-04-05 09:18:56 +02:00
Henrik Rydgård 4dd3621fa0 Remove some unnecessary <algorithm> includes. 2024-12-18 17:04:27 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård 83af54950f Move more core-related stuff into Core.cpp/h 2024-12-08 11:54:58 +01:00
Henrik Rydgård 59a56d66c7 Add a "reason" argument to sleep_ms().
sleep_ms() should generally be avoided when possible. This can be used to try
to track down unnecessary sleeps by adding some logging.

This commit on its own doesn't actually add any logging.
2024-11-21 15:28:51 +01:00
Henrik Rydgård f690cb99a4 If upnp is disabled, poll the check less aggressively. TODO: should wait for a cond instead. 2024-10-31 23:15:08 +01:00
Henrik Rydgård 3cd0e18556 Apply miniupnp buildfix proposed in #19333
See #19333
2024-07-17 16:23:39 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård ab257e335f Ugprade miniupnp submodule to latest
Maybe will help #19246, but no idea really.

Windows buildfix

UWP buildfix

miniupnpc path fixes

libretro buildfix attempt, android.mk
2024-06-05 00:18:00 +02:00
Henrik Rydgård 9decdd198e Address more feedback, minor cleanup 2023-07-21 10:30:06 +02:00
Henrik Rydgård ab6e902fea Make naett work on Android, UWP, Mac. Exclude on Linux 2023-07-21 10:28:31 +02:00
Henrik Rydgård b54d5ab8e6 Cleanup the g_PortManager shutdown process
Following up comment by @ANR2ME in #17744, to be merged before that one.
2023-07-20 23:55:35 +02:00
Henrik Rydgård eb21a2e6c9 Break out the OSD data holder from Common/System/System.h, into OSD.cpp/h 2023-06-30 17:15:49 +02:00
Henrik Rydgård 7cc8c6cea4 OSD: Add semantics, move the the OSD state to common (while keeping the renderer in the UI). 2023-06-20 14:40:46 +02:00
Henrik Rydgård 6945deec01 Replace a LOT of sprintf with snprintf, and a few strcpy with truncate_cpy 2023-04-28 21:04:05 +02:00
Henrik Rydgård ee6234ecb6 I18N: Switch to getting categories by index instead of by string lookup
Also gets rid of the shared_ptr usage, and generally makes things nicer.

Needed for later config refactorings, good to get in early.
2023-04-07 10:35:01 +02:00
Henrik Rydgård 9e125eeba7 Remove NotifyUserMessage from Host 2023-03-25 10:32:09 +01:00
Unknown W. Brackets 9cfcbc46e6 Global: Cleanup initialization/pointer checks.
Cleaning up a lot of cases of uninitialized data, unchecked return values
for failures, and similar.
2022-12-10 21:13:36 -08:00
Unknown W. Brackets 2479d52202 Global: Reduce includes of common headers.
In many places, string, map, or Common.h were included but not needed.
2022-01-30 16:35:33 -08:00
Unknown W. Brackets 63e623ecb2 Build: Fix some format truncation warnings.
Generally all should be safe already, but better to be sure.
2021-12-11 10:45:27 -08:00
Henrik Rydgård f4a6d291e1 Common: Capitalize setCurrentThreadName(). 2021-04-30 23:02:36 -07:00
ANR2ME 36ba5e0ef0 Prevent flooding the logs with repeated attempts of Adding/Removing port mapping due to failure in the middle of UPnP initialization, as it needs to be reinitialized. 2021-04-02 13:03:07 +07:00
Paul Cercueil 08e60c27d7 Fix build with USE_MINIUPNPC=OFF
Instead of adding platform-specific dirty workarounds, why not try to
handle things *properly*?

With this commit, the PortManager will compile UPnP specific code only
if USE_MINIUPNPC is set.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2021-03-19 12:48:28 +00:00
M4xw 4cc322466a Switch: Workaround several missing toolchain defs. 2021-03-04 21:24:57 -08:00
Henrik Rydgård 1405e28166 More buildfixes 2020-10-16 00:24:12 +02:00
Henrik Rydgård 4f43cff5ca Move fileutil, net, image loaders, ui to Common. (#13506)
* Move and rename file_util/fd_util to Common/File/FileUtil and DirListing

Let's also move net while we're at it.

Move the ZIM/PNG loaders over to Common.

Move the UI framework into Common

iOS buildfix

* Buildfix

* Buildfixes

* Apple buildfix

* This typo again..

* UWP buildfix

* Fix build of PPSSPPQt, such as it is (it's not in good condition...)

* Guess what? Another buildfix.
2020-10-04 20:48:47 +02:00
Henrik Rydgård ff8148dd92 Move native/util, native/data and native/i18 to Common/Data.
Also move colorutil.cpp/h

linking build fix experiment

Delete a bunch of unused CMakeLists.txt files

CMakeLists.txt linking fix

Don't include NativeApp.h from any headers.

Android.mk buildfix

Half of the UWP fix

Buildfix

Minor project file cleanup

Buildfixes

Guess what? More buildfixes!
2020-10-04 07:28:29 +02:00
Henrik Rydgård 15382d5f94 Move threading utils from native to Common 2020-10-01 09:27:25 +02:00
Unknown W. Brackets 1371ef298b Net: Reduce PortManager log noise.
Shows up when running unit tests, etc.
2020-08-27 19:23:23 -07:00
Henrik Rydgård ccc0331279 Move timeutil to Common. (Experiment to see how much work it is to move these). 2020-08-15 20:53:08 +02:00
Unknown W. Brackets 667a8522cc Global: Cut down on file/string includes. 2020-08-10 08:03:44 +00:00
ANR2ME bd36fdda0e Do UPnP stuff on it's own thread to prevent causing stutters/lags during multiplayer game due to blocking socket behavior on miniUPnP 2020-07-23 12:41:13 +02:00
ANR2ME e21ea719e9 Fixed PortManager fallback Cleanup issue when exiting PPSSPP due to early WSACleanup 2020-07-22 23:13:41 +02:00
ANR2ME 68fa15784c Fixed UPnP port opened by PPSSPP detection, and Updated PortManager to be compliant to general purpose usage 2020-07-22 23:13:41 +02:00
ANR2ME b9025b50bd Added a UPnP option to use original port for external port instead of using the shifted port by port offset, to be compatible with real PSP or other PSP emulators 2020-07-22 23:13:41 +02:00
ANR2ME d12218e8da Attempt to fix compilation error on Linux 2020-07-22 20:41:47 +02:00
ANR2ME d0045947f1 An attempt to fix socket's behavior inconsistencies across platforms.
Added an option to override minimum socket's timeout to prevent getting timeouts on high latency networks.
2020-07-22 16:46:34 +02:00
ANR2ME 088e489c91 Fix UPnP error detection
Fix Local IP detection on non-Windows system
2020-07-21 23:03:04 +02:00
ANR2ME 33d3ac28de Added UPnP Support
Fix i18n type
2020-07-21 23:02:58 +02:00