-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmooca_http.hpp
More file actions
58 lines (48 loc) · 1.2 KB
/
mooca_http.hpp
File metadata and controls
58 lines (48 loc) · 1.2 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
#ifndef __MOOCA_HTTP_HPP__
#define __MOOCA_HTTP_HPP__
//
// mooca_http.h
// mooca
//
// Created by jelly on 18/02/2018.
// Copyright © 2018 mooca.io. All rights reserved.
//
#include "mooca_base.hpp"
#include "mooca_status.hpp"
#include "mooca_threadpool.hpp"
#include <atomic>
#include <curl/curl.h>
#include <fstream>
#include <iostream>
#include <mutex>
namespace mooca {
class HttpClient;
static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* userdata);
typedef struct BlockNode {
size_t start;
size_t end;
CURL* curl;
std::ofstream* fp;
HttpClient* cl;
} BlockNode;
class HttpClient : public BaseClient {
private:
std::string url;
int thread_num = 0;
File* file_ptr = NULL;
std::mutex mutex_file;
ThreadPool* worker_ptr = NULL;
std::atomic<bool> is_start{ false };
std::ofstream* fp = NULL;
std::mutex mutex_io;
std::vector<BlockNode*> blocks;
public:
HttpClient(std::string url, std::ofstream* fp, size_t thread_num);
void sync_http_file_size();
virtual bool NotifyMe(Status status);
virtual bool NotifyStart();
~HttpClient();
friend size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* userdata);
};
}
#endif