root/http/connection.hh

Revision 8fab37d78032b4009b127dc2d5c06b71a627ebd5, 4.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 21 months ago)

[http::connection] Kill idle connections.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_HTTP_CONNECTION_HH
21#define GUARD_HTTP_CONNECTION_HH
22
23#include "../tls/session.hh"
24#include "../server.hh"
25#include "response.hh"
26
27#include <boost/asio.hpp>
28#include <boost/shared_ptr.hpp>
29
30namespace http
31{
32        class connection : public server::connection
33                         , public boost::enable_shared_from_this<connection>
34        {
35        public:
36                typedef boost::shared_ptr<connection> ptr;
37                class factory : public server::connection_factory
38                {
39                        bool https;
40                public:
41                        factory(bool https) : https(https) {}
42                        boost::shared_ptr<server::connection>
43                        operator()(std::string port_name,
44                                   boost::asio::ip::tcp::acceptor &acc,
45                                   tls::init init,
46                                   server::conn_cb srv_cb) {
47                                boost::shared_ptr<server::connection> rv
48                                        (new connection(port_name, https,
49                                                        acc, init, srv_cb));
50                                return rv;
51                        }
52                };
53                std::string get_port_name() const { return port_name; }
54                boost::shared_ptr<server::connection_factory>
55                get_factory() const {
56                        boost::shared_ptr<server::connection_factory> rv
57                                (new factory(https));
58                        return rv;
59                }
60
61                connection(std::string port_name,
62                           bool https,
63                           boost::asio::ip::tcp::acceptor &acc,
64                           tls::init,
65                           server::conn_cb srv_cb);
66
67                ~connection();
68
69                server::conn_cb get_srv_cb() { return srv_cb; }
70        protected:
71                server::conn_cb get_conn_cb() { return srv_cb; }
72        private:
73                const std::string port_name;
74                const bool https;
75
76                server::conn_cb srv_cb;
77                boost::asio::io_service &ios;
78                boost::asio::ip::tcp::endpoint ep;
79                boost::asio::ip::tcp::socket peer;
80                tls::session<boost::asio::ip::tcp::socket&> speer;
81
82                std::string loghead;
83
84                boost::posix_time::ptime startup_timestamp;
85                boost::posix_time::ptime request_timestamp;
86                size_t num_requests;
87                bool idle;
88
89                boost::asio::streambuf readbuf;
90
91                void tick(bool);
92
93                void accept(boost::system::error_code ec);
94
95                /* these are static and take a shared pointer to the
96                 * object to make sure that the object stays around
97                 * (too bad "this" is not reference counted) */
98                static void kill(ptr);
99                static void abort(ptr, boost::system::error_code ec);
100                static void get_request(ptr, boost::system::error_code ec);
101                static void got_request(ptr,
102                                        boost::system::error_code ec, size_t);
103                static void reqcont(ptr self,
104                                    boost::shared_ptr<request> req,
105                                    boost::shared_ptr<response> resp,
106                                    response::factory respfac,
107                                    size_t bodylen,
108                                    boost::system::error_code ec,
109                                    std::size_t);
110                static void sent_response(ptr,
111                                          boost::shared_ptr<response>,
112                                          boost::system::error_code ec, size_t);
113        };
114}
115
116#endif /* GUARD_HTTP_CONNECTION_HH */
Note: See TracBrowser for help on using the browser.