2012-06-04 16:48:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-04 16:48:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2015-01-08 13:48:39 +01:00
|
|
|
#ifndef SHRPX_CONNECTION_HANDLER_H
|
|
|
|
#define SHRPX_CONNECTION_HANDLER_H
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include "shrpx.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2014-06-26 15:55:22 +02:00
|
|
|
#include <memory>
|
2014-06-26 17:26:21 +02:00
|
|
|
#include <vector>
|
2014-06-26 15:55:22 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
#include <openssl/ssl.h>
|
2012-06-05 18:26:04 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <ev.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-10-13 14:09:00 +02:00
|
|
|
#include "shrpx_downstream_connection_pool.h"
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace shrpx {
|
|
|
|
|
2013-11-04 09:53:57 +01:00
|
|
|
class Http2Session;
|
2014-08-19 16:36:04 +02:00
|
|
|
class ConnectBlocker;
|
2014-12-27 18:59:06 +01:00
|
|
|
class AcceptHandler;
|
|
|
|
class Worker;
|
2014-06-26 15:55:22 +02:00
|
|
|
struct WorkerStat;
|
2015-01-08 13:15:45 +01:00
|
|
|
struct TicketKeys;
|
2012-11-20 17:29:39 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
// TODO should be renamed as ConnectionHandler
|
2015-01-08 13:48:39 +01:00
|
|
|
class ConnectionHandler {
|
2012-06-04 16:48:31 +02:00
|
|
|
public:
|
2015-01-12 16:18:27 +01:00
|
|
|
ConnectionHandler(struct ev_loop *loop);
|
2015-01-08 13:48:39 +01:00
|
|
|
~ConnectionHandler();
|
2014-12-27 18:59:06 +01:00
|
|
|
int handle_connection(int fd, sockaddr *addr, int addrlen);
|
2015-01-12 16:18:27 +01:00
|
|
|
void create_ssl_context();
|
2012-06-05 18:26:04 +02:00
|
|
|
void create_worker_thread(size_t num);
|
2014-07-05 11:22:40 +02:00
|
|
|
void worker_reopen_log_files();
|
2015-01-08 13:15:45 +01:00
|
|
|
void worker_renew_ticket_keys(const std::shared_ptr<TicketKeys> &ticket_keys);
|
2014-12-27 18:59:06 +01:00
|
|
|
struct ev_loop *get_loop() const;
|
|
|
|
void create_http2_session();
|
|
|
|
void create_http1_connect_blocker();
|
2014-11-27 15:39:04 +01:00
|
|
|
const WorkerStat *get_worker_stat() const;
|
2014-12-27 18:59:06 +01:00
|
|
|
void set_acceptor4(std::unique_ptr<AcceptHandler> h);
|
|
|
|
AcceptHandler *get_acceptor4() const;
|
|
|
|
void set_acceptor6(std::unique_ptr<AcceptHandler> h);
|
|
|
|
AcceptHandler *get_acceptor6() const;
|
|
|
|
void enable_acceptor();
|
|
|
|
void disable_acceptor();
|
|
|
|
void disable_acceptor_temporary(ev_tstamp t);
|
2014-08-12 15:22:02 +02:00
|
|
|
void accept_pending_connection();
|
|
|
|
void graceful_shutdown_worker();
|
|
|
|
void join_worker();
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
private:
|
2014-10-13 14:09:00 +02:00
|
|
|
DownstreamConnectionPool dconn_pool_;
|
2014-12-27 18:59:06 +01:00
|
|
|
std::vector<std::unique_ptr<Worker>> workers_;
|
|
|
|
struct ev_loop *loop_;
|
2013-02-07 13:13:36 +01:00
|
|
|
// The frontend server SSL_CTX
|
|
|
|
SSL_CTX *sv_ssl_ctx_;
|
|
|
|
// The backend server SSL_CTX
|
|
|
|
SSL_CTX *cl_ssl_ctx_;
|
2013-11-04 09:53:57 +01:00
|
|
|
// Shared backend HTTP2 session. NULL if multi-threaded. In
|
2013-02-07 13:13:36 +01:00
|
|
|
// multi-threaded case, see shrpx_worker.cc.
|
2014-06-26 17:39:53 +02:00
|
|
|
std::unique_ptr<Http2Session> http2session_;
|
2014-08-19 16:36:04 +02:00
|
|
|
std::unique_ptr<ConnectBlocker> http1_connect_blocker_;
|
2014-12-27 18:59:06 +01:00
|
|
|
// bufferevent_rate_limit_group *rate_limit_group_;
|
|
|
|
std::unique_ptr<AcceptHandler> acceptor4_;
|
|
|
|
std::unique_ptr<AcceptHandler> acceptor6_;
|
|
|
|
ev_timer disable_acceptor_timer_;
|
2014-06-26 15:55:22 +02:00
|
|
|
std::unique_ptr<WorkerStat> worker_stat_;
|
2013-12-06 15:17:38 +01:00
|
|
|
unsigned int worker_round_robin_cnt_;
|
2012-06-04 16:48:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shrpx
|
|
|
|
|
2015-01-08 13:48:39 +01:00
|
|
|
#endif // SHRPX_CONNECTION_HANDLER_H
|