code: скорость загрузки по сети, вариант

master
EfremovSI 1 год назад
Родитель 1b1311833a
Сommit 7449ef860f

@ -68,7 +68,7 @@ write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
} }
Input Input
download(const string& address) { download(const string& address, bool proverka_skorosti) {
stringstream buffer; stringstream buffer;
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
if(curl) if(curl)
@ -79,16 +79,20 @@ download(const string& address) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res!=0) if(!res) {
{ curl_off_t speed;
res2=curl_easy_strerror(res); res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD_T, &speed);
cout<<res2<<endl; if(!res) {
exit(1); cerr << "Upload speed "<< speed << " bytes/sec\n";
}
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
return input_data(buffer, true); return input_data(buffer, true);
} }
@ -99,7 +103,7 @@ int main(int argc, char* argv[])
Input in; Input in;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if (argc > 1) { if (argc > 1) {
in = download(argv[1]); in = download(argv[1], false);
} else { } else {
in = input_data(cin, true); in = input_data(cin, true);
} }
@ -109,3 +113,4 @@ int main(int argc, char* argv[])
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить