Changeset ae733bf09b727f294ead488db5ac953eb50f20d8

Show
Ignore:
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:
10 modified

Legend:

Unmodified
Added
Removed
  • http/connection.cc

    r19beb87 rae733bf  
    348348        } 
    349349 
    350         void connection::tick() 
     350        void connection::tick(bool) 
    351351        { 
    352352                // FIXME 
  • http/connection.hh

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    8686                boost::asio::streambuf readbuf; 
    8787 
    88                 void tick(); 
     88                void tick(bool); 
    8989 
    9090                void accept(boost::system::error_code ec); 
  • nntp/connection.cc

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    9393        void connection::kill() 
    9494        { 
    95                 tick(); 
     95                stats(); 
     96                speer.kill(); 
     97                peer.cancel(); 
    9698                srv_cb.terminal(shared_from_this()); 
    9799                // reset these pointers to break pointer loops 
     
    179181                using boost::bind; 
    180182                using boost::asio::buffer; 
     183 
     184                if (!cont) 
     185                { 
     186                        logger::logline ll; 
     187                        ll << loghead << "has a null continuation"; 
     188                        return; 
     189                } 
    181190 
    182191                // to work around a weird bug in the TLS wrapper... 
     
    510519        connection::command::~command() {} 
    511520 
    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 
    514527                logger::logline ll; 
    515528                ll << loghead  
     
    517530                   << (capabilities_used ? "CAPABILITIES; " : "") 
    518531                   << "age "  
    519                    << boost::posix_time::second_clock::universal_time() - 
    520                         startup_timestamp 
     532                   << now - startup_timestamp 
    521533                   << ", no client activity in " 
    522                    << boost::posix_time::second_clock::universal_time() - 
    523                         client_activity_timestamp 
     534                   << idle 
    524535                   << "; " 
    525536                   << num_commands_served  
     
    529540                   << (identified ? "identified; " : "not identified; ") 
    530541                   << (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                } 
    532561        } 
    533562 
  • nntp/connection.hh

    r4c34ee2 rae733bf  
    253253                void flush_writebuf(continuation::ptr cont); 
    254254 
    255                 void tick(); 
     255                void stats(); 
     256                void tick(bool); 
    256257                void kill(); 
    257258 
  • server.cc

    r19beb87 rae733bf  
    2828#include "smtp_client/smtp_client.hh" 
    2929 
     30#include <boost/date_time.hpp> 
    3031#include <boost/system/system_error.hpp> 
    3132#include <boost/shared_ptr.hpp> 
     
    110111 
    111112 
    112         timer.expires_from_now(boost::posix_time::seconds(10)); 
     113        timer.expires_from_now(boost::posix_time::seconds(30)); 
    113114        timer.async_wait(boost::bind(&server::tick_handler, this, _1)); 
    114115} 
     
    130131void server::tick_handler(boost::system::error_code) 
    131132{ 
    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        } 
    138145        for (std::set<boost::shared_ptr<connection> >::iterator it = 
    139146                     active.begin(); 
    140147             it != active.end(); it++) 
    141148        { 
    142                 (*it)->tick(); 
     149                (*it)->tick(stats); 
    143150        } 
    144151        logger::logger.flush(); 
    145         timer.expires_from_now(boost::posix_time::seconds(600)); 
     152        timer.expires_from_now(boost::posix_time::seconds(30)); 
    146153        timer.async_wait(boost::bind(&server::tick_handler, this, _1)); 
    147154} 
  • server.hh

    rcc0a570 rae733bf  
    2626#include <boost/asio.hpp> 
    2727#include <boost/bind.hpp> 
     28#include <boost/date_time.hpp> 
    2829#include <boost/shared_ptr.hpp> 
    2930#include <fstream> 
     
    4950                virtual boost::shared_ptr<connection_factory> 
    5051                get_factory() const = 0; 
    51                 virtual void tick() = 0; 
     52                virtual void tick(bool stats) = 0; 
    5253        }; 
    5354 
     
    109110        boost::asio::io_service::strand strand; 
    110111        boost::asio::deadline_timer timer; 
     112        boost::posix_time::ptime latest_logged_statistics; 
    111113 
    112114        typedef 
  • smtp_client/smtp_client.cc

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    6969        } 
    7070 
    71         void smtp_client::tick() 
     71        void smtp_client::tick(bool) 
    7272        { 
    7373                size_t n = 0; 
     
    8686                if (active) async_run_queue(); 
    8787 
    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                } 
    9093        } 
    9194 
  • smtp_client/smtp_client.hh

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    105105                void send_mail(const std::list<std::string> &recipients, 
    106106                               std::string message); 
    107                 void tick(); 
     107                void tick(bool); 
    108108        }; 
    109109} 
  • tls/session.hh

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    267267                ~session() { impl->kill(); } 
    268268 
     269                void kill() { impl->kill(); } 
     270 
    269271                template <typename Handler> 
    270272                void async_handshake(Handler h) { impl->async_handshake(h); } 
  • tls/session_impl.hh

    r868b365 rae733bf  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    5252        void session_impl<Stream>::kill() 
    5353        { 
     54                kill_pending_actions(); 
    5455                stream.cancel(); 
    5556        }