CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/FileLoaders/HTTPFileLoader.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <mutex>
21
#include <vector>
22
23
#include "Common/File/Path.h"
24
#include "Common/Net/HTTPClient.h"
25
#include "Common/Net/Resolve.h"
26
#include "Common/Net/URL.h"
27
#include "Common/CommonTypes.h"
28
#include "Core/Loaders.h"
29
30
class HTTPFileLoader : public FileLoader {
31
public:
32
HTTPFileLoader(const ::Path &filename);
33
~HTTPFileLoader();
34
35
bool IsRemote() override {
36
return true;
37
}
38
bool Exists() override;
39
bool ExistsFast() override;
40
bool IsDirectory() override;
41
s64 FileSize() override;
42
Path GetPath() const override;
43
44
size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
45
return ReadAt(absolutePos, bytes * count, data, flags) / bytes;
46
}
47
size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override;
48
49
void Cancel() override {
50
cancel_ = true;
51
}
52
53
std::string LatestError() const override {
54
return latestError_;
55
}
56
57
private:
58
void Prepare();
59
int SendHEAD(const Url &url, std::vector<std::string> &responseHeaders);
60
61
void Connect(double timeout);
62
63
void Disconnect() {
64
if (connected_) {
65
client_.Disconnect();
66
}
67
connected_ = false;
68
}
69
70
s64 filesize_ = 0;
71
s64 filepos_ = 0;
72
Url url_;
73
http::Client client_;
74
net::RequestProgress progress_;
75
::Path filename_;
76
bool connected_ = false;
77
bool cancel_ = false;
78
const char *latestError_ = "";
79
80
std::once_flag preparedFlag_;
81
std::mutex readAtMutex_;
82
};
83
84