Changeset 8fab37d78032b4009b127dc2d5c06b71a627ebd5
- Timestamp:
- 08/28/10 23:47:53 (21 months ago)
- Author:
- Antti-Juhani Kaijanaho <antti-juhani@…>
- Children:
- 62231ec0359b34f6a82b6688a7af97f2eb2ede10
- Parents:
- e044cc70b8bbba183fdf396ddbc00b2407eb5bea
- git-committer:
- Antti-Juhani Kaijanaho <antti-juhani@…> (08/28/10 23:47:53)
- Message:
-
[http::connection] Kill idle connections.
Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>
- Location:
- http
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r6197546
|
r8fab37d
|
|
| 45 | 45 | , startup_timestamp |
| 46 | 46 | (boost::posix_time::second_clock::universal_time()) |
| | 47 | , request_timestamp(startup_timestamp) |
| | 48 | , num_requests(0) |
| | 49 | , idle(false) |
| 47 | 50 | { |
| 48 | 51 | acc.async_accept(peer, ep, |
| … |
… |
|
| 116 | 119 | if (ec) { abort(self, ec); return; } |
| 117 | 120 | |
| | 121 | self->idle = true; |
| | 122 | |
| 118 | 123 | async_read_until(self->speer, self->readbuf, "\r\n\r\n", |
| 119 | 124 | bind(&connection::got_request, |
| … |
… |
|
| 130 | 135 | using boost::bind; |
| 131 | 136 | using boost::shared_ptr; |
| | 137 | |
| | 138 | self->idle = false; |
| | 139 | ++self->num_requests; |
| 132 | 140 | |
| 133 | 141 | if (ec == boost::asio::error::eof) |
| … |
… |
|
| 255 | 263 | } |
| 256 | 264 | |
| 257 | | boost::posix_time::ptime reqtime = boost::posix_time::microsec_clock::universal_time(); |
| | 265 | self->request_timestamp = |
| | 266 | boost::posix_time::microsec_clock::universal_time(); |
| 258 | 267 | |
| 259 | 268 | if (self->srv_cb.do_log_protocol_details()) |
| … |
… |
|
| 317 | 326 | ll << self->loghead << (req ? req->logbit() : "") << " " |
| 318 | 327 | << resp->logbit() |
| 319 | | << "; " << boost::posix_time::microsec_clock::universal_time() - reqtime; |
| | 328 | << "; " |
| | 329 | << boost::posix_time::microsec_clock::universal_time() - |
| | 330 | self->request_timestamp; |
| 320 | 331 | ll.close(); |
| 321 | 332 | |
| … |
… |
|
| 349 | 360 | } |
| 350 | 361 | |
| 351 | | void connection::tick(bool) |
| 352 | | { |
| 353 | | // FIXME |
| | 362 | void connection::tick(bool stats) |
| | 363 | { |
| | 364 | using namespace boost::posix_time; |
| | 365 | ptime now = microsec_clock::universal_time(); |
| | 366 | bool kill = idle && num_requests != 0 && |
| | 367 | now - request_timestamp > minutes(10); |
| | 368 | |
| | 369 | if (stats || kill) |
| | 370 | { |
| | 371 | logger::logline ll; |
| | 372 | ll << loghead |
| | 373 | << " age " |
| | 374 | << now - startup_timestamp |
| | 375 | << "; " |
| | 376 | << (idle ? "idle " : "busy ") |
| | 377 | << now - request_timestamp |
| | 378 | << "; served " << num_requests << " requests"; |
| | 379 | if (kill) ll << "; killing"; |
| | 380 | } |
| | 381 | if (kill) speer.kill(); |
| 354 | 382 | } |
| 355 | 383 | |
-
|
r6197546
|
r8fab37d
|
|
| 83 | 83 | |
| 84 | 84 | boost::posix_time::ptime startup_timestamp; |
| | 85 | boost::posix_time::ptime request_timestamp; |
| | 86 | size_t num_requests; |
| | 87 | bool idle; |
| 85 | 88 | |
| 86 | 89 | boost::asio::streambuf readbuf; |