Ilya (OgarkovIA) 6 месяцев назад
Родитель 2cc16d900d
Сommit 32078e2770

@ -2,24 +2,24 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="204" topLine="0" />
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="0" topLine="20" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="0" topLine="41" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="1933" topLine="47" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -51,37 +51,34 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
return data_size;
}
Input download(const string& address) {
stringstream buffer;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
double connect_time;
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init(); // CURL* - äåñêðèïòîð, ñëîæíûé îáúåêò, ïåðåäàâàòü èõ ôóíêöèÿì áèáëèîòåêè è ñðàâíèâàòü ìåæäó ñîáîé
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); // áèáëèîòåêà ìîæåò âûçûâàòü ôóíêöèþ, êîòîðóþ óêàæåò ïðîãðàììà.
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if (!curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect_time)) {
cerr << "Connect time: " << connect_time << " seconds." << endl;
} else {
cerr << "Failed to retrieve connect time." << endl;
}
if (res != CURLE_OK) {
curl_easy_strerror(res);
exit(1);
}
if(!res) {
long req;
res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &req);
if(!res) {
cerr<<"Request size: "<<req<< " bytes\n";
}
}
if (res != CURLE_OK) {
cerr << "CURL error: " << curl_easy_strerror(res) << endl;
curl_easy_cleanup(curl);
exit(1);
}
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}

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