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.
|
|
|
|
*/
|
|
|
|
#ifndef SHRPX_LISTEN_HANDLER_H
|
|
|
|
#define SHRPX_LISTEN_HANDLER_H
|
|
|
|
|
|
|
|
#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-08-17 11:50:10 +02:00
|
|
|
#ifndef NOTHREADS
|
2014-08-12 15:22:02 +02:00
|
|
|
#include <future>
|
2014-08-17 11:50:10 +02:00
|
|
|
#endif // NOTHREADS
|
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
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
#include <event.h>
|
2014-03-09 06:53:28 +01:00
|
|
|
#include <event2/bufferevent.h>
|
2014-08-12 15:22:02 +02:00
|
|
|
#include <event2/listener.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 {
|
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
struct WorkerInfo {
|
2014-08-17 11:50:10 +02:00
|
|
|
#ifndef NOTHREADS
|
2014-08-12 15:22:02 +02:00
|
|
|
std::future<void> fut;
|
2014-08-17 11:50:10 +02:00
|
|
|
#endif // NOTHREADS
|
2013-02-07 13:13:36 +01:00
|
|
|
SSL_CTX *sv_ssl_ctx;
|
|
|
|
SSL_CTX *cl_ssl_ctx;
|
2012-06-05 18:26:04 +02:00
|
|
|
bufferevent *bev;
|
2013-12-06 15:17:38 +01:00
|
|
|
int sv[2];
|
2012-06-05 18:26:04 +02:00
|
|
|
};
|
|
|
|
|
2013-11-04 09:53:57 +01:00
|
|
|
class Http2Session;
|
2014-08-19 16:36:04 +02:00
|
|
|
class ConnectBlocker;
|
2014-06-26 15:55:22 +02:00
|
|
|
struct WorkerStat;
|
2012-11-20 17:29:39 +01:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
class ListenHandler {
|
|
|
|
public:
|
2013-02-07 13:13:36 +01:00
|
|
|
ListenHandler(event_base *evbase, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx);
|
2012-06-04 16:48:31 +02:00
|
|
|
~ListenHandler();
|
|
|
|
int accept_connection(evutil_socket_t fd, sockaddr *addr, int addrlen);
|
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();
|
2014-11-27 15:39:04 +01:00
|
|
|
event_base *get_evbase() const;
|
2013-11-04 09:53:57 +01:00
|
|
|
int create_http2_session();
|
2014-08-19 16:36:04 +02:00
|
|
|
int create_http1_connect_blocker();
|
2014-11-27 15:39:04 +01:00
|
|
|
const WorkerStat *get_worker_stat() const;
|
2014-08-12 15:22:02 +02:00
|
|
|
void set_evlistener4(evconnlistener *evlistener4);
|
2014-11-27 15:39:04 +01:00
|
|
|
evconnlistener *get_evlistener4() const;
|
2014-08-12 15:22:02 +02:00
|
|
|
void set_evlistener6(evconnlistener *evlistener6);
|
2014-11-27 15:39:04 +01:00
|
|
|
evconnlistener *get_evlistener6() const;
|
2014-08-27 15:34:00 +02:00
|
|
|
void enable_evlistener();
|
2014-08-12 15:22:02 +02:00
|
|
|
void disable_evlistener();
|
2014-08-27 15:34:00 +02:00
|
|
|
void disable_evlistener_temporary(const timeval *timeout);
|
2014-08-12 15:22:02 +02:00
|
|
|
void accept_pending_connection();
|
|
|
|
void graceful_shutdown_worker();
|
|
|
|
void join_worker();
|
|
|
|
void notify_worker_shutdown();
|
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-08-12 15:22:02 +02:00
|
|
|
std::vector<std::unique_ptr<WorkerInfo>> workers_;
|
2012-06-04 16:48:31 +02:00
|
|
|
event_base *evbase_;
|
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-03-09 06:53:28 +01:00
|
|
|
bufferevent_rate_limit_group *rate_limit_group_;
|
2014-08-12 15:22:02 +02:00
|
|
|
evconnlistener *evlistener4_;
|
|
|
|
evconnlistener *evlistener6_;
|
2014-08-27 15:34:00 +02:00
|
|
|
event *evlistener_disable_timerev_;
|
2014-06-26 15:55:22 +02:00
|
|
|
std::unique_ptr<WorkerStat> worker_stat_;
|
2014-08-19 17:09:18 +02:00
|
|
|
size_t num_worker_shutdown_;
|
2013-12-06 15:17:38 +01:00
|
|
|
unsigned int worker_round_robin_cnt_;
|
2012-06-04 16:48:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shrpx
|
|
|
|
|
|
|
|
#endif // SHRPX_LISTEN_HANDLER_H
|