@@ -43,9 +43,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
43
43
{
44
44
public:
45
45
Server (Handler* handler, std::string bindaddr, uint16_t port, std::string server_name = std::string(" Crow/" ) + VERSION, std::tuple<Middlewares...>* middlewares = nullptr , uint16_t concurrency = 1 , uint8_t timeout = 5 , typename Adaptor::context* adaptor_ctx = nullptr ):
46
- acceptor_ (io_service_ , tcp::endpoint(asio::ip::address::from_string (bindaddr), port)),
47
- signals_ (io_service_ ),
48
- tick_timer_ (io_service_ ),
46
+ acceptor_ (io_context_ , tcp::endpoint(asio::ip::make_address (bindaddr), port)),
47
+ signals_ (io_context_ ),
48
+ tick_timer_ (io_context_ ),
49
49
handler_ (handler),
50
50
concurrency_ (concurrency),
51
51
timeout_ (timeout),
@@ -78,7 +78,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
78
78
{
79
79
uint16_t worker_thread_count = concurrency_ - 1 ;
80
80
for (int i = 0 ; i < worker_thread_count; i++)
81
- io_service_pool_ .emplace_back (new asio::io_service ());
81
+ io_context_pool_ .emplace_back (new asio::io_context ());
82
82
get_cached_date_str_pool_.resize (worker_thread_count);
83
83
task_timer_pool_.resize (worker_thread_count);
84
84
@@ -116,7 +116,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
116
116
};
117
117
118
118
// initializing task timers
119
- detail::task_timer task_timer (*io_service_pool_ [i]);
119
+ detail::task_timer task_timer (*io_context_pool_ [i]);
120
120
task_timer.set_default_timeout (timeout_);
121
121
task_timer_pool_[i] = &task_timer;
122
122
task_queue_length_pool_[i] = 0 ;
@@ -126,7 +126,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
126
126
{
127
127
try
128
128
{
129
- if (io_service_pool_ [i]->run () == 0 )
129
+ if (io_context_pool_ [i]->run () == 0 )
130
130
{
131
131
// when io_service.run returns 0, there are no more works to do.
132
132
break ;
@@ -170,7 +170,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
170
170
std::thread (
171
171
[this ] {
172
172
notify_start ();
173
- io_service_ .run ();
173
+ io_context_ .run ();
174
174
CROW_LOG_INFO << " Exiting." ;
175
175
})
176
176
.join ();
@@ -179,17 +179,17 @@ namespace crow // NOTE: Already documented in "crow/app.h"
179
179
void stop ()
180
180
{
181
181
shutting_down_ = true ; // Prevent the acceptor from taking new connections
182
- for (auto & io_service : io_service_pool_ )
182
+ for (auto & io_context : io_context_pool_ )
183
183
{
184
- if (io_service != nullptr )
184
+ if (io_context != nullptr )
185
185
{
186
- CROW_LOG_INFO << " Closing IO service " << &io_service ;
187
- io_service ->stop (); // Close all io_services (and HTTP connections)
186
+ CROW_LOG_INFO << " Closing IO service " << &io_context ;
187
+ io_context ->stop (); // Close all io_services (and HTTP connections)
188
188
}
189
189
}
190
190
191
- CROW_LOG_INFO << " Closing main IO service (" << &io_service_ << ' )' ;
192
- io_service_ .stop (); // Close main io_service
191
+ CROW_LOG_INFO << " Closing main IO service (" << &io_context_ << ' )' ;
192
+ io_context_ .stop (); // Close main io_service
193
193
}
194
194
195
195
uint16_t port (){
@@ -215,7 +215,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
215
215
}
216
216
217
217
private:
218
- uint16_t pick_io_service_idx ()
218
+ uint16_t pick_io_context_idx ()
219
219
{
220
220
uint16_t min_queue_idx = 0 ;
221
221
@@ -235,29 +235,29 @@ namespace crow // NOTE: Already documented in "crow/app.h"
235
235
{
236
236
if (!shutting_down_)
237
237
{
238
- uint16_t service_idx = pick_io_service_idx ();
239
- asio::io_service& is = *io_service_pool_[service_idx ];
240
- task_queue_length_pool_[service_idx ]++;
241
- CROW_LOG_DEBUG << &is << " {" << service_idx << " } queue length: " << task_queue_length_pool_[service_idx ];
238
+ uint16_t context_idx = pick_io_context_idx ();
239
+ asio::io_context& ic = *io_context_pool_[context_idx ];
240
+ task_queue_length_pool_[context_idx ]++;
241
+ CROW_LOG_DEBUG << &ic << " {" << context_idx << " } queue length: " << task_queue_length_pool_[context_idx ];
242
242
243
243
auto p = std::make_shared<Connection<Adaptor, Handler, Middlewares...>>(
244
- is , handler_, server_name_, middlewares_,
245
- get_cached_date_str_pool_[service_idx ], *task_timer_pool_[service_idx ], adaptor_ctx_, task_queue_length_pool_[service_idx ]);
244
+ ic , handler_, server_name_, middlewares_,
245
+ get_cached_date_str_pool_[context_idx ], *task_timer_pool_[context_idx ], adaptor_ctx_, task_queue_length_pool_[context_idx ]);
246
246
247
247
acceptor_.async_accept (
248
248
p->socket (),
249
- [this , p, &is, service_idx ](error_code ec) {
249
+ [this , p, &ic, context_idx ](error_code ec) {
250
250
if (!ec)
251
251
{
252
- is. post (
252
+ asio:: post (ic,
253
253
[p] {
254
254
p->start ();
255
255
});
256
256
}
257
257
else
258
258
{
259
- task_queue_length_pool_[service_idx ]--;
260
- CROW_LOG_DEBUG << &is << " {" << service_idx << " } queue length: " << task_queue_length_pool_[service_idx ];
259
+ task_queue_length_pool_[context_idx ]--;
260
+ CROW_LOG_DEBUG << &ic << " {" << context_idx << " } queue length: " << task_queue_length_pool_[context_idx ];
261
261
}
262
262
do_accept ();
263
263
});
@@ -273,8 +273,8 @@ namespace crow // NOTE: Already documented in "crow/app.h"
273
273
}
274
274
275
275
private:
276
- std::vector<std::unique_ptr<asio::io_service >> io_service_pool_ ;
277
- asio::io_service io_service_ ;
276
+ std::vector<std::unique_ptr<asio::io_context >> io_context_pool_ ;
277
+ asio::io_context io_context_ ;
278
278
std::vector<detail::task_timer*> task_timer_pool_;
279
279
std::vector<std::function<std::string()>> get_cached_date_str_pool_;
280
280
tcp::acceptor acceptor_;
0 commit comments