Bugfixes HTTP::Downloader, downloadertest now outputs data immediately without buffering

This commit is contained in:
Thulinma 2020-09-21 14:10:44 +02:00
parent bc3ca638cd
commit e28743db54
2 changed files with 11 additions and 3 deletions

View file

@ -331,7 +331,7 @@ namespace HTTP{
} }
// No data? Wait for a second or so. // No data? Wait for a second or so.
if (!getSocket().spool()){ if (!getSocket().spool() && getSocket()){
if (progressCallback != 0){ if (progressCallback != 0){
if (!progressCallback()){ if (!progressCallback()){
WARN_MSG("Download aborted by callback"); WARN_MSG("Download aborted by callback");

View file

@ -1,14 +1,22 @@
#include "../lib/downloader.cpp" #include "../lib/downloader.cpp"
#include <iostream> #include <iostream>
class CB : public Util::DataCallback {
virtual void dataCallback(const char *ptr, size_t size){
std::cout.write(ptr, size);
}
};
CB callback;
int main(int argc, char **argv){ int main(int argc, char **argv){
if (argc < 2){ if (argc < 2){
std::cout << "Usage: " << argv[0] << " URL" << std::endl; std::cout << "Usage: " << argv[0] << " URL" << std::endl;
return 1; return 1;
} }
HTTP::Downloader d; HTTP::Downloader d;
if (d.get(argv[1])){ HTTP::URL url(argv[1]);
std::cout << d.data() << std::endl; if (d.get(url, 10, callback)){
std::cerr << "Download success!" << std::endl; std::cerr << "Download success!" << std::endl;
}else{ }else{
std::cerr << "Download fail!" << std::endl; std::cerr << "Download fail!" << std::endl;