Commit Graph
24 Commits
Author SHA1 Message Date
Henrik Rydgård 1041c976c6 http: Say what the sink's ownership actually is
unique_ptr, not shared_ptr. Nothing ever shares it: naett holds a raw pointer
and takes no part in the counting, and the abandonment path hands the sink over
and lets go in the same breath. What's really going on is a single owner that
moves, which is what unique_ptr says and shared_ptr left you to work out from
reading all the uses.

naett never frees the pointer it's given for the writer - it only reads
bodyWriterData and hands it back to the callback - so deleting the sink is
ours to do. The things naett does allocate, the request and response, stay raw
pointers with explicit naettFree/naettClose.

The length field was just buffer.size() written down twice.
2026-09-05 13:57:31 -06:00
Henrik Rydgård bc095c5e31 naett: Stop the transfer when the body writer fails it
Found reviewing the commits before this one. On Windows a short write marked the
request complete and then queued another read regardless, which is worse than it
sounds: the caller is free to close a response the moment it sees complete, so
WinHTTP carried on writing into memory that was being freed. It also meant
cancelling didn't actually stop anything there. Stop at that point, and ignore
anything raised after the request is complete.

The Apple callbacks do the same check, so the cancellation we ask for after a
failed write doesn't overwrite the error that caused it.

naettMake only asserted that its request was non-NULL, and the request
constructors do return NULL when a platform can't set one up - an unparseable
URL is enough on Windows. Asserts are compiled out in release, so that was a
null dereference. It returns NULL now, and HTTPSRequest checks for it and fails
the request instead of handing it on.

Also: a request cancelled between construction and Start() didn't carry that
into the sink, and -1000 - our own cancellation code, not naett's - was logging
"Unhandled naett error" on a perfectly normal cancel.
2026-09-05 13:22:44 -06:00
Henrik Rydgård b120f0004f http: Make Cancel() actually stop an HTTPS transfer
Cancel() worked on the plain HTTP path - cancelled_ is threaded down as
progress->cancelled and checked while connecting and reading - but on the naett
path it only set a flag that nothing looked at. The transfer ran to completion
and cancelling just relabelled the result afterwards. Cancelling a store icon
that scrolled away, or a homebrew download the user gave up on, kept using the
bandwidth either way.

naett has one hook for this: a body writer that takes less than it was given
fails the request. So HTTPSRequest installs its own writer, which refuses
everything once cancelled. That works on all four backends and needs nothing
from naettClose, which is only really safe on Android.

The catch is lifetime. The writer runs on naett's transfer thread, and a request
that's still going when we're torn down would then be writing into a destroyed
HTTPSRequest - which is why the buffer it writes into is a separate refcounted
sink rather than a member. Join() on an unfinished request parks the sink where
it won't be freed and lets the request go, so a chunk that lands afterwards
writes somewhere that still exists.

That path is shutdown-only: RequestManager only cancels from its destructor, and
Update() waits for Done() before joining. Join now also notices a request that
finished while nobody was polling, and closes it properly instead of abandoning
it. What's left leaking at that point is a request still in flight as the
process exits, which is what already happened, just deliberate now and logged as
such rather than as an error.
2026-09-05 13:15:12 -06:00
Henrik Rydgård 2096df52f5 Vendor naett in-tree, de-amalgamated
naett has been a submodule pinned at v0.3.3; upstream has had no commits since
April 2024, and we want to carry local changes (next up: a libcurl-backed HTTPS
path for Linux). It's ~1500 lines of MIT C, smaller than several things we
already vendor, so bring it in-tree and drop the submodule.

Also drop the generated single-file amalgam (naett.c) that every build system
was compiling, and build src/*.c directly instead - otherwise the file you edit
isn't the file that gets compiled, which is a trap for anyone patching this.
example/ and testrig/ (a whole Android Studio project) are gone with it.

Two changes were needed to make the sources build on their own, both noted in
ext/naett/README-ppsspp.md along with the upstream commit:

- naett_internal.h now includes naett.h, which the amalgam pulled in first.
- naett_linux.c now includes stdio.h/stdlib.h. It calls exit/calloc/realloc/
  free/fprintf without ever including either, and only got away with it because
  naett_core.c sat above it in the concatenation.

No functional change - Linux still has HTTPS_NOT_AVAILABLE set, so it doesn't
build naett at all yet.

Rename naett to naett-lib
2026-09-02 17:35:14 +02:00
Henrik Rydgård 96ae36b7dd Fix some comments, remove redundant fields etc 2026-06-13 17:44:26 +02:00
Henrik Rydgård 00126e4c6f Correct some logging categories 2026-06-13 17:12:16 +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 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 eb719c43e8 HTTP: Replace ProgressBarMode with a new RequestFlags enum 2025-01-23 12:09:56 +01:00
Henrik Rydgård 12adad0494 HTTP request classes code cleanup - move common things up to the base class 2025-01-23 10:16:51 +01:00
Henrik Rydgård e0c12c9547 More lint warning fixes 2024-10-10 10:52:45 +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 c5791764d8 Make the i18n T function use std::string_view
Buildfixes, crashfixes

One more

Android buildfix

Buildfix Qt
2024-02-12 18:44:39 +01:00
Henrik Rydgård 78de59a479 HTTPS through naett: Get the body of the response even if code isn't 200.
This is required for rcheevos to parse errors properly - it ignores the
error code and parses it out of the body instead.
2023-12-31 00:11:36 +01:00
Henrik Rydgård 93bb113009 Common: Rename Download to Request, and the old Request to ServerRequest. 2023-07-21 22:12:00 +02:00
Henrik Rydgård ac6301db47 Use the new function in patched naett to update user agent 2023-07-21 18:23:33 +02:00
Henrik Rydgård 9535b16740 Use the patched naett functions to implement progress updates 2023-07-21 18:23:33 +02:00
Henrik Rydgård 61db21b12d Cleanup, fix so we can run RetroAchievements with https, and start doing that 2023-07-21 10:49:01 +02:00
Henrik Rydgård 9decdd198e Address more feedback, minor cleanup 2023-07-21 10:30:06 +02:00
Henrik Rydgård 96a75f9fc4 naett: Set timeout, POST body, etc. Just missing user agent 2023-07-21 10:28:32 +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 fbd980bee6 Get basic Naett requests to work (the store works in https mode) 2023-07-21 10:28:17 +02:00
Henrik Rydgård e2cc835c2b Setup build for new file HTTPNaettRequest 2023-07-21 10:27:40 +02:00