Fixed Downloader class progress callbacks, added HTTP::Parser progress calculation function.
This commit is contained in:
parent
e1150fe871
commit
917ce2d452
3 changed files with 26 additions and 2 deletions
|
@ -183,7 +183,15 @@ namespace HTTP{
|
||||||
return true; // Success!
|
return true; // Success!
|
||||||
}
|
}
|
||||||
// reset the data timeout
|
// reset the data timeout
|
||||||
reqTime = Util::bootSecs();
|
if (reqTime != Util::bootSecs()){
|
||||||
|
if (progressCallback != 0){
|
||||||
|
if (!progressCallback()){
|
||||||
|
WARN_MSG("Download aborted by callback");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqTime = Util::bootSecs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (getSocket()){
|
if (getSocket()){
|
||||||
FAIL_MSG("Timeout while retrieving %s (%zu/%" PRIu32 ")", link.getUrl().c_str(),
|
FAIL_MSG("Timeout while retrieving %s (%zu/%" PRIu32 ")", link.getUrl().c_str(),
|
||||||
|
@ -239,7 +247,15 @@ namespace HTTP{
|
||||||
return true; // Success!
|
return true; // Success!
|
||||||
}
|
}
|
||||||
// reset the data timeout
|
// reset the data timeout
|
||||||
reqTime = Util::bootSecs();
|
if (reqTime != Util::bootSecs()){
|
||||||
|
if (progressCallback != 0){
|
||||||
|
if (!progressCallback()){
|
||||||
|
WARN_MSG("Download aborted by callback");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reqTime = Util::bootSecs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (getSocket()){
|
if (getSocket()){
|
||||||
FAIL_MSG("Timeout while retrieving %s", link.getUrl().c_str());
|
FAIL_MSG("Timeout while retrieving %s", link.getUrl().c_str());
|
||||||
|
|
|
@ -751,6 +751,13 @@ bool HTTP::Parser::Read(std::string &strbuf){
|
||||||
return parse(strbuf);
|
return parse(strbuf);
|
||||||
}// HTTPReader::Read
|
}// HTTPReader::Read
|
||||||
|
|
||||||
|
/// Checks download completion percentage.
|
||||||
|
/// Returns zero if that doesn't make sense at the time or cannot be determined.
|
||||||
|
uint8_t HTTP::Parser::getPercentage() const{
|
||||||
|
if (!seenHeaders || length < 1){return 0;}
|
||||||
|
return ((body.length() * 100) / length);
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempt to read a whole HTTP response or request from a data buffer.
|
/// Attempt to read a whole HTTP response or request from a data buffer.
|
||||||
/// If succesful, fills its own fields with the proper data and removes the response/request
|
/// If succesful, fills its own fields with the proper data and removes the response/request
|
||||||
/// from the data buffer.
|
/// from the data buffer.
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace HTTP{
|
||||||
const std::string &GetHeader(const std::string &i) const;
|
const std::string &GetHeader(const std::string &i) const;
|
||||||
bool hasHeader(const std::string &i) const;
|
bool hasHeader(const std::string &i) const;
|
||||||
void clearHeader(const std::string &i);
|
void clearHeader(const std::string &i);
|
||||||
|
uint8_t getPercentage() const;
|
||||||
const std::string &GetVar(const std::string &i) const;
|
const std::string &GetVar(const std::string &i) const;
|
||||||
std::string getUrl();
|
std::string getUrl();
|
||||||
std::string allVars();
|
std::string allVars();
|
||||||
|
|
Loading…
Add table
Reference in a new issue