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

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