@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
22
22
#include < iostream>
23
23
#include < sstream>
24
24
#include < list>
25
- #include < map >
25
+ #include < unordered_map >
26
26
#include < cerrno>
27
27
#include < mutex>
28
28
#include " network/socket.h" // for select()
@@ -37,13 +37,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
37
37
#include " settings.h"
38
38
#include " noise.h"
39
39
40
- std::mutex g_httpfetch_mutex;
41
- std::map<unsigned long , std::queue<HTTPFetchResult> > g_httpfetch_results;
42
- PcgRandom g_callerid_randomness;
40
+ static std::mutex g_httpfetch_mutex;
41
+ static std::unordered_map<unsigned long , std::queue<HTTPFetchResult>>
42
+ g_httpfetch_results;
43
+ static PcgRandom g_callerid_randomness;
43
44
44
45
HTTPFetchRequest::HTTPFetchRequest () :
45
46
timeout(g_settings->getS32 (" curl_timeout" )),
46
- connect_timeout(timeout ),
47
+ connect_timeout(10 * 1000 ),
47
48
useragent(std::string(PROJECT_NAME_C " /" ) + g_version_hash + " (" + porting::get_sysinfo() + " )")
48
49
{
49
50
}
@@ -54,7 +55,7 @@ static void httpfetch_deliver_result(const HTTPFetchResult &fetch_result)
54
55
unsigned long caller = fetch_result.caller ;
55
56
if (caller != HTTPFETCH_DISCARD) {
56
57
MutexAutoLock lock (g_httpfetch_mutex);
57
- g_httpfetch_results[caller].push (fetch_result);
58
+ g_httpfetch_results[caller].emplace (fetch_result);
58
59
}
59
60
}
60
61
@@ -67,8 +68,7 @@ unsigned long httpfetch_caller_alloc()
67
68
// Check each caller ID except HTTPFETCH_DISCARD
68
69
const unsigned long discard = HTTPFETCH_DISCARD;
69
70
for (unsigned long caller = discard + 1 ; caller != discard; ++caller) {
70
- std::map<unsigned long , std::queue<HTTPFetchResult> >::iterator
71
- it = g_httpfetch_results.find (caller);
71
+ auto it = g_httpfetch_results.find (caller);
72
72
if (it == g_httpfetch_results.end ()) {
73
73
verbosestream << " httpfetch_caller_alloc: allocating "
74
74
<< caller << std::endl;
@@ -127,8 +127,7 @@ bool httpfetch_async_get(unsigned long caller, HTTPFetchResult &fetch_result)
127
127
MutexAutoLock lock (g_httpfetch_mutex);
128
128
129
129
// Check that caller exists
130
- std::map<unsigned long , std::queue<HTTPFetchResult> >::iterator
131
- it = g_httpfetch_results.find (caller);
130
+ auto it = g_httpfetch_results.find (caller);
132
131
if (it == g_httpfetch_results.end ())
133
132
return false ;
134
133
@@ -138,7 +137,7 @@ bool httpfetch_async_get(unsigned long caller, HTTPFetchResult &fetch_result)
138
137
return false ;
139
138
140
139
// Pop first result
141
- fetch_result = caller_results.front ();
140
+ fetch_result = std::move ( caller_results.front () );
142
141
caller_results.pop ();
143
142
return true ;
144
143
}
0 commit comments