@@ -11,57 +11,56 @@ using curl::curl_easy;
11
11
using std::vector;
12
12
using std::unique_ptr;
13
13
14
- // Implementation of constructor.
15
- curl_multi::curl_multi () : curl_interface() {
16
- this ->curl = curl_multi_init ();
14
+ void curl_multi::milti_deleter::operator ()(CURLM* ptr) const
15
+ {
16
+ curl_multi_cleanup (ptr);
17
+ }
18
+
19
+ curl_multi::curl_multi () : curl_multi(CURL_GLOBAL_ALL) {
20
+ }
21
+
22
+ curl_multi::curl_multi (const long flag)
23
+ : curl_interface(flag),
24
+ curl(curl_multi_init()) {
17
25
if (this ->curl == nullptr ) {
18
- throw curl_multi_exception (" Null pointer intercepted" ,__FUNCTION__);
26
+ throw curl_multi_exception (" Null pointer intercepted" , __FUNCTION__);
19
27
}
20
28
this ->active_transfers = 0 ;
21
29
this ->message_queued = 0 ;
22
30
}
23
31
24
- // Implementation of overloaded constructor.
25
- curl_multi::curl_multi (const long flag) : curl_interface(flag) {
26
- curl_multi ();
32
+ curl_multi::curl_multi (curl_multi&& other)
33
+ : curl_interface(std::forward<curl_interface>(other)),
34
+ curl(std::move(other.curl)),
35
+ active_transfers(other.active_transfers),
36
+ message_queued(other.message_queued) {
27
37
}
28
38
29
- // Implementation of copy constructor to respect the rule of three.
30
- curl_multi::curl_multi (const curl_multi &multi)
31
- : curl_interface(),
32
- message_queued(multi.message_queued),
33
- active_transfers(multi.active_transfers) {
34
- this ->curl = curl_multi_init ();
35
- if (this ->curl == nullptr ) {
36
- throw curl_multi_exception (" Null pointer intercepted" ,__FUNCTION__);
39
+ curl_multi &curl_multi::operator =(curl_multi&& other) {
40
+ if (this != &other) {
41
+ curl = std::move (other.curl );
42
+ active_transfers = other.active_transfers ;
43
+ message_queued = other.message_queued ;
37
44
}
38
- }
39
45
40
- // Implementation of assignment operator to perform deep copy.
41
- curl_multi &curl_multi::operator =(const curl_multi &multi) {
42
- if (this == &multi) {
43
- return *this ;
44
- }
45
- curl_multi ();
46
46
return *this ;
47
47
}
48
48
49
- // Implementation of destructor.
50
- curl_multi::~curl_multi () NOEXCEPT{
51
- curl_multi_cleanup (this ->curl );
49
+ curl_multi::~curl_multi () NOEXCEPT
50
+ {
52
51
}
53
52
54
53
// Implementation of add method for easy handlers.
55
54
void curl_multi::add (const curl_easy &easy) {
56
- const CURLMcode code = curl_multi_add_handle (this ->curl ,easy.get_curl ());
55
+ const CURLMcode code = curl_multi_add_handle (this ->curl . get () ,easy.get_curl ());
57
56
if (code != CURLM_OK) {
58
57
throw curl_multi_exception (code,__FUNCTION__);
59
58
}
60
59
}
61
60
62
61
// Implementation of remove for easy handlers.
63
62
void curl_multi::remove (const curl_easy &easy) {
64
- const CURLMcode code = curl_multi_remove_handle (this ->curl ,easy.get_curl ());
63
+ const CURLMcode code = curl_multi_remove_handle (this ->curl . get () ,easy.get_curl ());
65
64
if (code != CURLM_OK) {
66
65
throw curl_multi_exception (code,__FUNCTION__);
67
66
}
@@ -71,7 +70,7 @@ void curl_multi::remove(const curl_easy &easy) {
71
70
vector<unique_ptr<curl_multi::curl_message>> curl_multi::get_info () {
72
71
vector<unique_ptr<curl_multi::curl_message>> infos;
73
72
CURLMsg *message = nullptr ;
74
- while ((message = curl_multi_info_read (this ->curl ,&this ->message_queued ))) {
73
+ while ((message = curl_multi_info_read (this ->curl . get () ,&this ->message_queued ))) {
75
74
infos.push_back (unique_ptr<curl_multi::curl_message>(new curl_multi::curl_message (message)));
76
75
}
77
76
return infos;
@@ -80,7 +79,7 @@ vector<unique_ptr<curl_multi::curl_message>> curl_multi::get_info() {
80
79
// Implementation of overloaded get_info method.
81
80
unique_ptr<curl_multi::curl_message> curl_multi::get_info (const curl_easy &easy) {
82
81
CURLMsg *message = nullptr ;
83
- while ((message = curl_multi_info_read (this ->curl ,&this ->message_queued ))) {
82
+ while ((message = curl_multi_info_read (this ->curl . get () ,&this ->message_queued ))) {
84
83
if (message->easy_handle == easy.get_curl ()) {
85
84
unique_ptr<curl_multi::curl_message> ptr{new curl_multi::curl_message (message)};
86
85
return ptr;
@@ -92,7 +91,7 @@ unique_ptr<curl_multi::curl_message> curl_multi::get_info(const curl_easy &easy)
92
91
// Implementation of is_finished method.
93
92
bool curl_multi::is_finished (const curl_easy &easy) {
94
93
CURLMsg *message = nullptr ;
95
- while ((message = curl_multi_info_read (this ->curl ,&this ->message_queued ))) {
94
+ while ((message = curl_multi_info_read (this ->curl . get () ,&this ->message_queued ))) {
96
95
if (message->easy_handle == easy.get_curl () and message->msg == CURLMSG_DONE) {
97
96
return true ;
98
97
}
@@ -102,7 +101,7 @@ bool curl_multi::is_finished(const curl_easy &easy) {
102
101
103
102
// Implementation of perform method.
104
103
bool curl_multi::perform () {
105
- const CURLMcode code = curl_multi_perform (this ->curl ,&this ->active_transfers );
104
+ const CURLMcode code = curl_multi_perform (this ->curl . get () ,&this ->active_transfers );
106
105
if (code == CURLM_CALL_MULTI_PERFORM) {
107
106
return false ;
108
107
}
@@ -114,7 +113,7 @@ bool curl_multi::perform() {
114
113
115
114
// Implementation of socket_action method.
116
115
bool curl_multi::socket_action (const curl_socket_t sockfd, const int ev_bitmask) {
117
- const CURLMcode code = curl_multi_socket_action (this ->curl ,sockfd,ev_bitmask,&this ->active_transfers );
116
+ const CURLMcode code = curl_multi_socket_action (this ->curl . get () ,sockfd,ev_bitmask,&this ->active_transfers );
118
117
if (code == CURLM_CALL_MULTI_PERFORM) {
119
118
return false ;
120
119
}
@@ -126,31 +125,31 @@ bool curl_multi::socket_action(const curl_socket_t sockfd, const int ev_bitmask)
126
125
127
126
// Implementation of set_fd method.
128
127
void curl_multi::set_descriptors (fd_set *read, fd_set *write, fd_set *exec, int *max_fd) {
129
- const CURLMcode code = curl_multi_fdset (this ->curl ,read,write,exec,max_fd);
128
+ const CURLMcode code = curl_multi_fdset (this ->curl . get () ,read,write,exec,max_fd);
130
129
if (code != CURLM_OK) {
131
130
throw curl_multi_exception (code,__FUNCTION__);
132
131
}
133
132
}
134
133
135
134
// Implementation of wait method.
136
135
void curl_multi::wait (struct curl_waitfd extra_fds[], const unsigned int extra_nfds, const int timeout_ms, int *numfds) {
137
- const CURLMcode code = curl_multi_wait (this ->curl ,extra_fds,extra_nfds,timeout_ms,numfds);
136
+ const CURLMcode code = curl_multi_wait (this ->curl . get () ,extra_fds,extra_nfds,timeout_ms,numfds);
138
137
if (code != CURLM_OK) {
139
138
throw curl_multi_exception (code,__FUNCTION__);
140
139
}
141
140
}
142
141
143
142
// Implementation of assign method.
144
143
void curl_multi::assign (const curl_socket_t sockfd, void *sockptr) {
145
- const CURLMcode code = curl_multi_assign (this ->curl ,sockfd,sockptr);
144
+ const CURLMcode code = curl_multi_assign (this ->curl . get () ,sockfd,sockptr);
146
145
if (code != CURLM_OK) {
147
146
throw curl_multi_exception (code,__FUNCTION__);
148
147
}
149
148
}
150
149
151
150
// Implementation of timeout method.
152
151
void curl_multi::timeout (long *timeout) {
153
- const CURLMcode code = curl_multi_timeout (this ->curl ,timeout);
152
+ const CURLMcode code = curl_multi_timeout (this ->curl . get () ,timeout);
154
153
if (code != CURLM_OK) {
155
154
throw curl_multi_exception (code,__FUNCTION__);
156
155
}
@@ -161,3 +160,8 @@ curl_multi::curl_message::curl_message(const CURLMsg *msg) :
161
160
message(msg->msg), whatever(msg->data.whatever), code(msg->data.result) {
162
161
// ... nothing to do here ...
163
162
}
163
+
164
+ // Implementation of get_curl method.
165
+ CURLM *curl_multi::get_curl () const {
166
+ return this ->curl .get ();
167
+ }
0 commit comments