Files
ppsspp/Common/Net/HTTPNaettRequest.h
T
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

55 lines
1.5 KiB
C++

#pragma once
#include <memory>
#include <string_view>
#include <thread>
#include "Common/Net/HTTPRequest.h"
#ifndef HTTPS_NOT_AVAILABLE
#include "ext/naett-lib/naett.h"
namespace http {
struct NaettBodySink;
// Really an asynchronous request.
class HTTPSRequest : public Request {
public:
HTTPSRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags = RequestFlags::ProgressBar | RequestFlags::ProgressBarDelayed, std::string_view name = "");
~HTTPSRequest();
void Start() override;
void Join() override;
// Also acts as a Poll.
bool Done() override;
bool Failed() const override { return failed_; }
// Cancelling has to reach naett, or it only changes the code we report once the transfer ends
// on its own. See the .cpp.
void Cancel() override;
private:
static int WriteBodyThunk(const void *source, int bytes, void *userData);
std::string postData_;
std::string postMime_;
bool completed_ = false;
bool failed_ = false;
// Where the response body lands. Deliberately not part of this object: naett writes into it
// from its own transfer thread, and that can outlive us if we're torn down before the request
// finishes, so ownership has to be able to move elsewhere. See NaettBodySink in the .cpp.
std::unique_ptr<NaettBodySink> sink_;
// Naett state
naettReq *req_ = nullptr;
naettRes *res_ = nullptr;
};
} // namespace http
#endif // HTTPS_NOT_AVAILABLE