Loaders: Add cancelation to all file loaders.
Mainly, for HTTP which might be stalled trying to connect (especially if you're not near your PC right now and it's in your recent, for example.)
This commit is contained in:
parent
6e3cb0cd48
commit
ee5b68f1fc
11 changed files with 87 additions and 43 deletions
|
@ -22,7 +22,7 @@
|
|||
#include "Core/FileLoaders/HTTPFileLoader.h"
|
||||
|
||||
HTTPFileLoader::HTTPFileLoader(const std::string &filename)
|
||||
: filesize_(0), filepos_(0), url_(filename), filename_(filename), connected_(false) {
|
||||
: url_(filename), filename_(filename) {
|
||||
}
|
||||
|
||||
void HTTPFileLoader::Prepare() {
|
||||
|
@ -33,6 +33,10 @@ void HTTPFileLoader::Prepare() {
|
|||
}
|
||||
|
||||
Connect();
|
||||
if (!connected_) {
|
||||
return;
|
||||
}
|
||||
|
||||
int err = client_.SendRequest("HEAD", url_.Resource().c_str());
|
||||
if (err < 0) {
|
||||
Disconnect();
|
||||
|
@ -123,6 +127,9 @@ size_t HTTPFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags f
|
|||
}
|
||||
|
||||
Connect();
|
||||
if (!connected_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char requestHeaders[4096];
|
||||
// Note that the Range header is *inclusive*.
|
||||
|
@ -186,3 +193,11 @@ size_t HTTPFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags f
|
|||
filepos_ = absolutePos + readBytes;
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
void HTTPFileLoader::Connect() {
|
||||
if (!connected_) {
|
||||
cancelConnect_ = false;
|
||||
// Latency is important here, so reduce the timeout.
|
||||
connected_ = client_.Connect(3, 10.0, &cancelConnect_);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue