2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Tatsuhiro Tsujikawa
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:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
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.
25 #ifndef SHRPX_WORKER_H
26 #define SHRPX_WORKER_H
38 #include <openssl/ssl.h>
39 #include <openssl/err.h>
43 #include "shrpx_config.h"
44 #include "shrpx_downstream_connection_pool.h"
47 using namespace nghttp2;
59 WorkerStat() : num_connections(0), next_downstream(0) {}
61 size_t num_connections;
62 // Next downstream index in Config::downstream_addrs. For HTTP/2
63 // downstream connections, this is always 0. For HTTP/1, this is
64 // used as load balancing.
65 size_t next_downstream;
68 enum WorkerEventType {
69 NEW_CONNECTION = 0x01,
71 GRACEFUL_SHUTDOWN = 0x03,
72 RENEW_TICKET_KEYS = 0x04,
78 sockaddr_union client_addr;
79 size_t client_addrlen;
82 std::shared_ptr<TicketKeys> ticket_keys;
87 Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
88 ssl::CertLookupTree *cert_tree,
89 const std::shared_ptr<TicketKeys> &ticket_keys);
93 void process_events();
94 void send(const WorkerEvent &event);
96 ssl::CertLookupTree *get_cert_lookup_tree() const;
97 const std::shared_ptr<TicketKeys> &get_ticket_keys() const;
98 void set_ticket_keys(std::shared_ptr<TicketKeys> ticket_keys);
99 WorkerStat *get_worker_stat();
100 DownstreamConnectionPool *get_dconn_pool();
101 Http2Session *next_http2_session();
102 ConnectBlocker *get_connect_blocker() const;
103 struct ev_loop *get_loop() const;
104 SSL_CTX *get_sv_ssl_ctx() const;
105 SSL_CTX *get_cl_ssl_ctx() const;
107 void set_graceful_shutdown(bool f);
108 bool get_graceful_shutdown() const;
110 MemchunkPool *get_mcpool();
111 void schedule_clear_mcpool();
114 std::vector<std::unique_ptr<Http2Session>> http2sessions_;
115 size_t next_http2session_;
117 std::future<void> fut_;
120 std::deque<WorkerEvent> q_;
122 ev_timer mcpool_clear_timer_;
123 MemchunkPool mcpool_;
124 DownstreamConnectionPool dconn_pool_;
125 WorkerStat worker_stat_;
126 struct ev_loop *loop_;
128 // Following fields are shared across threads if
129 // get_config()->tls_ctx_per_worker == true.
130 SSL_CTX *sv_ssl_ctx_;
131 SSL_CTX *cl_ssl_ctx_;
132 ssl::CertLookupTree *cert_tree_;
134 std::shared_ptr<TicketKeys> ticket_keys_;
135 std::unique_ptr<ConnectBlocker> connect_blocker_;
137 bool graceful_shutdown_;
142 #endif // SHRPX_WORKER_H