-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.cpp
47 lines (41 loc) · 1.15 KB
/
connect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "modules/connect.h"
#include "modules/clear.h"
#include "curl/curl.h"
void connect::DownloadFile(const char *link, const char *outfile)
{
CURL *curl;
FILE *fp;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
fp = fopen(outfile, "wb");
curl_easy_setopt(curl, CURLOPT_URL, link);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
bool connect::CheckNet()
{
CURL *curl;
CURLcode result;
static char errorBuffer[CURL_ERROR_SIZE];
static std::string buffer;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ClearWrite);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
result = curl_easy_perform(curl);
if (result == CURLE_OK)
return true;
else
return false;
}
return false;
}