forked from sailxy/HttpClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClient.h
More file actions
74 lines (50 loc) · 1.6 KB
/
HttpClient.h
File metadata and controls
74 lines (50 loc) · 1.6 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __HTTPCLIENT_H__
#define __HTTPCLIENT_H__
#include <iostream>
#include "include/curl/curl.h"
#define Z_DEBUG
using namespace std;
#define ZLOG(str) HttpClient::getInstance()->zlog(__DATE__, __TIME__, __FILE__, __LINE__, __FUNCTION__, str);
#ifdef _WIN32
typedef _off_t p_off_t;
#else
typedef off_t p_off_t;
#endif
typedef void(*progress_info_callback)(void *userdata, double downloadSpeed, double remainingTime, double progressPercentage);
typedef struct
{
void *sender;
CURL *handle;
progress_info_callback cb;
}Progress_User_Data;
typedef enum
{
HTTP_REQUEST_OK = CURLE_OK,
HTTP_REQUEST_ERROR = -999,
}Http_Client_Response;
class HttpClient
{
public:
~HttpClient();
static HttpClient *getInstance();
static void destroyInstance();
int HttpGet(const string requestURL, const string saveTo, void *sender, progress_info_callback cb);
void zlog(const char *date, const char *time, const char *file, const int line, const char *func, const char* str);
private:
HttpClient();
bool init();
static size_t write_callback(char *buffer, size_t size, size_t nmemb, void *userdata);
static int progress_callback(void *userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
// Get the local file size
p_off_t getLocalFileLength(string path);
// Get the file size on the server
double getDownloadFileLength(string url);
private:
static HttpClient *instance;
static double downloadFileLength;
static curl_off_t resumeByte;
// Call frequency of the callback function
static time_t lastTime;
static bool stopCurl;
};
#endif // __HTTPCLIENT_H__