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
37 #include <openssl/ssl.h>
38 #include <openssl/err.h>
42 #include "shrpx_config.h"
43 #include "shrpx_downstream_connection_pool.h"
55 WorkerStat() : num_connections(0), next_downstream(0) {}
57 size_t num_connections;
58 // Next downstream index in Config::downstream_addrs. For HTTP/2
59 // downstream connections, this is always 0. For HTTP/1, this is
60 // used as load balancing.
61 size_t next_downstream;
64 enum WorkerEventType {
65 NEW_CONNECTION = 0x01,
67 GRACEFUL_SHUTDOWN = 0x03,
68 RENEW_TICKET_KEYS = 0x04,
74 sockaddr_union client_addr;
75 size_t client_addrlen;
78 std::shared_ptr<TicketKeys> ticket_keys;
83 Worker(SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
84 ssl::CertLookupTree *cert_tree,
85 const std::shared_ptr<TicketKeys> &ticket_keys);
88 void process_events();
89 void send(const WorkerEvent &event);
93 std::future<void> fut_;
96 std::deque<WorkerEvent> q_;
98 DownstreamConnectionPool dconn_pool_;
99 struct ev_loop *loop_;
100 SSL_CTX *sv_ssl_ctx_;
101 SSL_CTX *cl_ssl_ctx_;
102 std::unique_ptr<Http2Session> http2session_;
103 std::unique_ptr<ConnectBlocker> http1_connect_blocker_;
104 std::unique_ptr<WorkerStat> worker_stat_;
109 #endif // SHRPX_WORKER_H