Changeset ae733bf09b727f294ead488db5ac953eb50f20d8
- Timestamp:
- 06/26/10 15:13:59 (2 years ago)
- Author:
- Antti-Juhani Kaijanaho <antti-juhani@…>
- Children:
- 8d4f7f7d0239d22536f28b4900b2931d40a8537f
- Parents:
- 72ebe081314754cf0300ebd5b8969fac31b3330e
- git-author:
- Antti-Juhani Kaijanaho <antti-juhani@…> (06/26/10 14:08:26)
- git-committer:
- Antti-Juhani Kaijanaho <antti-juhani@…> (06/26/10 15:13:59)
- Message:
-
[nntp::connection::tick] Kill idle connections (timeout at 2 hours)
Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r19beb87
|
rae733bf
|
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | | void connection::tick() |
| | 350 | void connection::tick(bool) |
| 351 | 351 | { |
| 352 | 352 | // FIXME |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 86 | 86 | boost::asio::streambuf readbuf; |
| 87 | 87 | |
| 88 | | void tick(); |
| | 88 | void tick(bool); |
| 89 | 89 | |
| 90 | 90 | void accept(boost::system::error_code ec); |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 93 | 93 | void connection::kill() |
| 94 | 94 | { |
| 95 | | tick(); |
| | 95 | stats(); |
| | 96 | speer.kill(); |
| | 97 | peer.cancel(); |
| 96 | 98 | srv_cb.terminal(shared_from_this()); |
| 97 | 99 | // reset these pointers to break pointer loops |
| … |
… |
|
| 179 | 181 | using boost::bind; |
| 180 | 182 | using boost::asio::buffer; |
| | 183 | |
| | 184 | if (!cont) |
| | 185 | { |
| | 186 | logger::logline ll; |
| | 187 | ll << loghead << "has a null continuation"; |
| | 188 | return; |
| | 189 | } |
| 181 | 190 | |
| 182 | 191 | // to work around a weird bug in the TLS wrapper... |
| … |
… |
|
| 510 | 519 | connection::command::~command() {} |
| 511 | 520 | |
| 512 | | void connection::tick() |
| 513 | | { |
| | 521 | void connection::stats() |
| | 522 | { |
| | 523 | using namespace boost::posix_time; |
| | 524 | ptime now = second_clock::universal_time(); |
| | 525 | time_duration idle = now - client_activity_timestamp; |
| | 526 | |
| 514 | 527 | logger::logline ll; |
| 515 | 528 | ll << loghead |
| … |
… |
|
| 517 | 530 | << (capabilities_used ? "CAPABILITIES; " : "") |
| 518 | 531 | << "age " |
| 519 | | << boost::posix_time::second_clock::universal_time() - |
| 520 | | startup_timestamp |
| | 532 | << now - startup_timestamp |
| 521 | 533 | << ", no client activity in " |
| 522 | | << boost::posix_time::second_clock::universal_time() - |
| 523 | | client_activity_timestamp |
| | 534 | << idle |
| 524 | 535 | << "; " |
| 525 | 536 | << num_commands_served |
| … |
… |
|
| 529 | 540 | << (identified ? "identified; " : "not identified; ") |
| 530 | 541 | << (authenticated ? "authenticated" : "not authenticated"); |
| 531 | | ll.close(); |
| | 542 | } |
| | 543 | |
| | 544 | void connection::tick(bool log) |
| | 545 | { |
| | 546 | if (log) stats(); |
| | 547 | using namespace boost::posix_time; |
| | 548 | ptime now = second_clock::universal_time(); |
| | 549 | time_duration idle = now - client_activity_timestamp; |
| | 550 | if (idle > hours(2) && dispatch) |
| | 551 | { |
| | 552 | logger::logline ll; |
| | 553 | ll << loghead |
| | 554 | << "dropping idle connection"; |
| | 555 | ll.close(); |
| | 556 | terminate.reset(); |
| | 557 | dispatch.reset(); |
| | 558 | starttls.reset(); |
| | 559 | kill(); |
| | 560 | } |
| 532 | 561 | } |
| 533 | 562 | |
-
|
r4c34ee2
|
rae733bf
|
|
| 253 | 253 | void flush_writebuf(continuation::ptr cont); |
| 254 | 254 | |
| 255 | | void tick(); |
| | 255 | void stats(); |
| | 256 | void tick(bool); |
| 256 | 257 | void kill(); |
| 257 | 258 | |
-
|
r19beb87
|
rae733bf
|
|
| 28 | 28 | #include "smtp_client/smtp_client.hh" |
| 29 | 29 | |
| | 30 | #include <boost/date_time.hpp> |
| 30 | 31 | #include <boost/system/system_error.hpp> |
| 31 | 32 | #include <boost/shared_ptr.hpp> |
| … |
… |
|
| 110 | 111 | |
| 111 | 112 | |
| 112 | | timer.expires_from_now(boost::posix_time::seconds(10)); |
| | 113 | timer.expires_from_now(boost::posix_time::seconds(30)); |
| 113 | 114 | timer.async_wait(boost::bind(&server::tick_handler, this, _1)); |
| 114 | 115 | } |
| … |
… |
|
| 130 | 131 | void server::tick_handler(boost::system::error_code) |
| 131 | 132 | { |
| 132 | | smtpc->tick(); |
| 133 | | logger::logline ll; |
| 134 | | ll << "server statistics: " |
| 135 | | << active.size() |
| 136 | | << " open connections"; |
| 137 | | ll.close(); |
| | 133 | using namespace boost::posix_time; |
| | 134 | ptime now = second_clock::universal_time(); |
| | 135 | bool stats = now - latest_logged_statistics > minutes(30); |
| | 136 | if (stats) latest_logged_statistics = now; |
| | 137 | smtpc->tick(stats); |
| | 138 | if (stats) |
| | 139 | { |
| | 140 | logger::logline ll; |
| | 141 | ll << "server statistics: " |
| | 142 | << active.size() |
| | 143 | << " open connections"; |
| | 144 | } |
| 138 | 145 | for (std::set<boost::shared_ptr<connection> >::iterator it = |
| 139 | 146 | active.begin(); |
| 140 | 147 | it != active.end(); it++) |
| 141 | 148 | { |
| 142 | | (*it)->tick(); |
| | 149 | (*it)->tick(stats); |
| 143 | 150 | } |
| 144 | 151 | logger::logger.flush(); |
| 145 | | timer.expires_from_now(boost::posix_time::seconds(600)); |
| | 152 | timer.expires_from_now(boost::posix_time::seconds(30)); |
| 146 | 153 | timer.async_wait(boost::bind(&server::tick_handler, this, _1)); |
| 147 | 154 | } |
-
|
rcc0a570
|
rae733bf
|
|
| 26 | 26 | #include <boost/asio.hpp> |
| 27 | 27 | #include <boost/bind.hpp> |
| | 28 | #include <boost/date_time.hpp> |
| 28 | 29 | #include <boost/shared_ptr.hpp> |
| 29 | 30 | #include <fstream> |
| … |
… |
|
| 49 | 50 | virtual boost::shared_ptr<connection_factory> |
| 50 | 51 | get_factory() const = 0; |
| 51 | | virtual void tick() = 0; |
| | 52 | virtual void tick(bool stats) = 0; |
| 52 | 53 | }; |
| 53 | 54 | |
| … |
… |
|
| 109 | 110 | boost::asio::io_service::strand strand; |
| 110 | 111 | boost::asio::deadline_timer timer; |
| | 112 | boost::posix_time::ptime latest_logged_statistics; |
| 111 | 113 | |
| 112 | 114 | typedef |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | | void smtp_client::tick() |
| | 71 | void smtp_client::tick(bool) |
| 72 | 72 | { |
| 73 | 73 | size_t n = 0; |
| … |
… |
|
| 86 | 86 | if (active) async_run_queue(); |
| 87 | 87 | |
| 88 | | logger::logline ll; |
| 89 | | ll << "activated " << n << " deferred emails"; |
| | 88 | if (n > 0) |
| | 89 | { |
| | 90 | logger::logline ll; |
| | 91 | ll << "activated " << n << " deferred emails"; |
| | 92 | } |
| 90 | 93 | } |
| 91 | 94 | |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 105 | 105 | void send_mail(const std::list<std::string> &recipients, |
| 106 | 106 | std::string message); |
| 107 | | void tick(); |
| | 107 | void tick(bool); |
| 108 | 108 | }; |
| 109 | 109 | } |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 267 | 267 | ~session() { impl->kill(); } |
| 268 | 268 | |
| | 269 | void kill() { impl->kill(); } |
| | 270 | |
| 269 | 271 | template <typename Handler> |
| 270 | 272 | void async_handshake(Handler h) { impl->async_handshake(h); } |
-
|
r868b365
|
rae733bf
|
|
| 1 | 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | 2 | |
| 3 | | Copyright © 2009 Antti-Juhani Kaijanaho |
| | 3 | Copyright © 2009, 2010 Antti-Juhani Kaijanaho |
| 4 | 4 | |
| 5 | 5 | Alue is free software: you can redistribute it and/or modify it |
| … |
… |
|
| 52 | 52 | void session_impl<Stream>::kill() |
| 53 | 53 | { |
| | 54 | kill_pending_actions(); |
| 54 | 55 | stream.cancel(); |
| 55 | 56 | } |