35
35
#endif
36
36
#endif
37
37
38
- #include < boost/algorithm/string/case_conv.hpp> // for to_lower()
39
- #include < boost/foreach.hpp>
40
-
41
38
/* * Maximum size of http request (request line + headers) */
42
39
static const size_t MAX_HEADERS_SIZE = 8192 ;
43
40
@@ -69,8 +66,8 @@ class WorkQueue
69
66
{
70
67
private:
71
68
/* * Mutex protects entire object */
72
- CWaitableCriticalSection cs;
73
- CConditionVariable cond;
69
+ std::mutex cs;
70
+ std::condition_variable cond;
74
71
std::deque<std::unique_ptr<WorkItem>> queue;
75
72
bool running;
76
73
size_t maxDepth;
@@ -83,12 +80,12 @@ class WorkQueue
83
80
WorkQueue &wq;
84
81
ThreadCounter (WorkQueue &w): wq(w)
85
82
{
86
- boost ::lock_guard<boost ::mutex> lock (wq.cs );
83
+ std ::lock_guard<std ::mutex> lock (wq.cs );
87
84
wq.numThreads += 1 ;
88
85
}
89
86
~ThreadCounter ()
90
87
{
91
- boost ::lock_guard<boost ::mutex> lock (wq.cs );
88
+ std ::lock_guard<std ::mutex> lock (wq.cs );
92
89
wq.numThreads -= 1 ;
93
90
wq.cond .notify_all ();
94
91
}
@@ -109,7 +106,7 @@ class WorkQueue
109
106
/* * Enqueue a work item */
110
107
bool Enqueue (WorkItem* item)
111
108
{
112
- boost ::unique_lock<boost ::mutex> lock (cs);
109
+ std ::unique_lock<std ::mutex> lock (cs);
113
110
if (queue.size () >= maxDepth) {
114
111
return false ;
115
112
}
@@ -124,7 +121,7 @@ class WorkQueue
124
121
while (running) {
125
122
std::unique_ptr<WorkItem> i;
126
123
{
127
- boost ::unique_lock<boost ::mutex> lock (cs);
124
+ std ::unique_lock<std ::mutex> lock (cs);
128
125
while (running && queue.empty ())
129
126
cond.wait (lock);
130
127
if (!running)
@@ -138,22 +135,22 @@ class WorkQueue
138
135
/* * Interrupt and exit loops */
139
136
void Interrupt ()
140
137
{
141
- boost ::unique_lock<boost ::mutex> lock (cs);
138
+ std ::unique_lock<std ::mutex> lock (cs);
142
139
running = false ;
143
140
cond.notify_all ();
144
141
}
145
142
/* * Wait for worker threads to exit */
146
143
void WaitExit ()
147
144
{
148
- boost ::unique_lock<boost ::mutex> lock (cs);
145
+ std ::unique_lock<std ::mutex> lock (cs);
149
146
while (numThreads > 0 )
150
147
cond.wait (lock);
151
148
}
152
149
153
150
/* * Return current depth of queue */
154
151
size_t Depth ()
155
152
{
156
- boost ::unique_lock<boost ::mutex> lock (cs);
153
+ std ::unique_lock<std ::mutex> lock (cs);
157
154
return queue.size ();
158
155
}
159
156
};
@@ -190,7 +187,7 @@ static bool ClientAllowed(const CNetAddr& netaddr)
190
187
{
191
188
if (!netaddr.IsValid ())
192
189
return false ;
193
- BOOST_FOREACH (const CSubNet& subnet, rpc_allow_subnets)
190
+ for (const CSubNet& subnet : rpc_allow_subnets)
194
191
if (subnet.Match (netaddr))
195
192
return true ;
196
193
return false ;
@@ -204,7 +201,7 @@ static bool InitHTTPAllowList()
204
201
rpc_allow_subnets.push_back (CSubNet (" ::1" )); // always allow IPv6 localhost
205
202
if (mapMultiArgs.count (" -rpcallowip" )) {
206
203
const std::vector<std::string>& vAllow = mapMultiArgs[" -rpcallowip" ];
207
- BOOST_FOREACH (std::string strAllow, vAllow) {
204
+ for (std::string strAllow : vAllow) {
208
205
CSubNet subnet (strAllow);
209
206
if (!subnet.IsValid ()) {
210
207
uiInterface.ThreadSafeMessageBox (
@@ -216,7 +213,7 @@ static bool InitHTTPAllowList()
216
213
}
217
214
}
218
215
std::string strAllowed;
219
- BOOST_FOREACH (const CSubNet& subnet, rpc_allow_subnets)
216
+ for (const CSubNet& subnet : rpc_allow_subnets)
220
217
strAllowed += subnet.ToString () + " " ;
221
218
LogPrint (" http" , " Allowing HTTP connections from: %s\n " , strAllowed);
222
219
return true ;
@@ -439,7 +436,7 @@ bool InitHTTPServer()
439
436
return true ;
440
437
}
441
438
442
- boost ::thread threadHTTP;
439
+ std ::thread threadHTTP;
443
440
std::future<bool > threadResult;
444
441
445
442
bool StartHTTPServer ()
@@ -449,10 +446,10 @@ bool StartHTTPServer()
449
446
LogPrintf (" HTTP: starting %d worker threads\n " , rpcThreads);
450
447
std::packaged_task<bool (event_base*, evhttp*)> task (ThreadHTTP);
451
448
threadResult = task.get_future ();
452
- threadHTTP = boost ::thread (std::bind ( std:: move (task), eventBase, eventHTTP) );
449
+ threadHTTP = std ::thread (std::move (task), eventBase, eventHTTP);
453
450
454
451
for (int i = 0 ; i < rpcThreads; i++) {
455
- boost ::thread rpc_worker (HTTPWorkQueueRun, workQueue);
452
+ std ::thread rpc_worker (HTTPWorkQueueRun, workQueue);
456
453
rpc_worker.detach ();
457
454
}
458
455
return true ;
@@ -463,7 +460,7 @@ void InterruptHTTPServer()
463
460
LogPrint (" http" , " Interrupting HTTP server\n " );
464
461
if (eventHTTP) {
465
462
// Unlisten sockets
466
- BOOST_FOREACH (evhttp_bound_socket *socket, boundSockets) {
463
+ for (evhttp_bound_socket *socket : boundSockets) {
467
464
evhttp_del_accept_socket (eventHTTP, socket);
468
465
}
469
466
// Reject requests on current connections
@@ -520,7 +517,7 @@ static void httpevent_callback_fn(evutil_socket_t, short, void* data)
520
517
delete self;
521
518
}
522
519
523
- HTTPEvent::HTTPEvent (struct event_base * base, bool deleteWhenTriggered, const boost ::function<void (void )>& handler):
520
+ HTTPEvent::HTTPEvent (struct event_base * base, bool deleteWhenTriggered, const std ::function<void (void )>& handler):
524
521
deleteWhenTriggered(deleteWhenTriggered), handler(handler)
525
522
{
526
523
ev = event_new (base, -1 , 0 , httpevent_callback_fn, this );
@@ -602,7 +599,7 @@ void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
602
599
assert (evb);
603
600
evbuffer_add (evb, strReply.data (), strReply.size ());
604
601
HTTPEvent* ev = new HTTPEvent (eventBase, true ,
605
- boost ::bind (evhttp_send_reply, req, nStatus, (const char *)NULL , (struct evbuffer *)NULL ));
602
+ std ::bind (evhttp_send_reply, req, nStatus, (const char *)NULL , (struct evbuffer *)NULL ));
606
603
ev->trigger (0 );
607
604
replySent = true ;
608
605
req = 0 ; // transferred back to main thread
0 commit comments