tizen 2.4 release
[external/nghttp2.git] / src / shrpx_connection_handler.h
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 Tatsuhiro Tsujikawa
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef SHRPX_CONNECTION_HANDLER_H
26 #define SHRPX_CONNECTION_HANDLER_H
27
28 #include "shrpx.h"
29
30 #include <sys/types.h>
31 #include <sys/socket.h>
32
33 #include <memory>
34 #include <vector>
35
36 #include <openssl/ssl.h>
37
38 #include <ev.h>
39
40 #include "shrpx_downstream_connection_pool.h"
41
42 namespace shrpx {
43
44 class Http2Session;
45 class ConnectBlocker;
46 class AcceptHandler;
47 class Worker;
48 struct WorkerStat;
49 struct TicketKeys;
50
51 // TODO should be renamed as ConnectionHandler
52 class ConnectionHandler {
53 public:
54   ConnectionHandler(struct ev_loop *loop);
55   ~ConnectionHandler();
56   int handle_connection(int fd, sockaddr *addr, int addrlen);
57   void create_ssl_context();
58   void create_worker_thread(size_t num);
59   void worker_reopen_log_files();
60   void worker_renew_ticket_keys(const std::shared_ptr<TicketKeys> &ticket_keys);
61   struct ev_loop *get_loop() const;
62   void create_http2_session();
63   void create_http1_connect_blocker();
64   const WorkerStat *get_worker_stat() const;
65   void set_acceptor4(std::unique_ptr<AcceptHandler> h);
66   AcceptHandler *get_acceptor4() const;
67   void set_acceptor6(std::unique_ptr<AcceptHandler> h);
68   AcceptHandler *get_acceptor6() const;
69   void enable_acceptor();
70   void disable_acceptor();
71   void disable_acceptor_temporary(ev_tstamp t);
72   void accept_pending_connection();
73   void graceful_shutdown_worker();
74   void join_worker();
75
76 private:
77   DownstreamConnectionPool dconn_pool_;
78   std::vector<std::unique_ptr<Worker>> workers_;
79   struct ev_loop *loop_;
80   // The frontend server SSL_CTX
81   SSL_CTX *sv_ssl_ctx_;
82   // The backend server SSL_CTX
83   SSL_CTX *cl_ssl_ctx_;
84   // Shared backend HTTP2 session. NULL if multi-threaded. In
85   // multi-threaded case, see shrpx_worker.cc.
86   std::unique_ptr<Http2Session> http2session_;
87   std::unique_ptr<ConnectBlocker> http1_connect_blocker_;
88   // bufferevent_rate_limit_group *rate_limit_group_;
89   std::unique_ptr<AcceptHandler> acceptor4_;
90   std::unique_ptr<AcceptHandler> acceptor6_;
91   ev_timer disable_acceptor_timer_;
92   std::unique_ptr<WorkerStat> worker_stat_;
93   unsigned int worker_round_robin_cnt_;
94 };
95
96 } // namespace shrpx
97
98 #endif // SHRPX_CONNECTION_HANDLER_H