@@ -53,15 +53,19 @@ curl_multi::~curl_multi() NOEXCEPT
53
53
// Implementation of add method for easy handlers.
54
54
void curl_multi::add (const curl_easy &easy) {
55
55
const CURLMcode code = curl_multi_add_handle (this ->curl .get (),easy.get_curl ());
56
- if (code != CURLM_OK) {
56
+ if (code == CURLM_OK) {
57
+ handles[easy.get_curl ()] = (curl_easy*)&easy;
58
+ } else {
57
59
throw curl_multi_exception (code,__FUNCTION__);
58
60
}
59
61
}
60
62
61
63
// Implementation of remove for easy handlers.
62
64
void curl_multi::remove (const curl_easy &easy) {
63
65
const CURLMcode code = curl_multi_remove_handle (this ->curl .get (),easy.get_curl ());
64
- if (code != CURLM_OK) {
66
+ if (code == CURLM_OK) {
67
+ handles.erase (easy.get_curl ());
68
+ } else {
65
69
throw curl_multi_exception (code,__FUNCTION__);
66
70
}
67
71
}
@@ -88,6 +92,20 @@ unique_ptr<curl_multi::curl_message> curl_multi::get_info(const curl_easy &easy)
88
92
return nullptr ;
89
93
}
90
94
95
+ // Implementation of get_next_finished method.
96
+ curl_easy* curl_multi::get_next_finished () {
97
+ CURLMsg *message = curl_multi_info_read (this ->curl .get (),&this ->message_queued );
98
+ if (!message)
99
+ return nullptr ;
100
+ if (message->msg == CURLMSG_DONE) {
101
+ std::unordered_map<CURL*, curl_easy*>::const_iterator it = handles.find (message->easy_handle );
102
+ if (it != handles.end ()) {
103
+ return it->second ;
104
+ }
105
+ }
106
+ return nullptr ;
107
+ }
108
+
91
109
// Implementation of is_finished method.
92
110
bool curl_multi::is_finished (const curl_easy &easy) {
93
111
CURLMsg *message = nullptr ;
0 commit comments