Apache HTTPD
h2_conn_ctx.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <assert.h>
18#include <apr_strings.h>
19#include <apr_atomic.h>
20
21#include <httpd.h>
22#include <http_core.h>
23#include <http_config.h>
24#include <http_log.h>
25#include <http_protocol.h>
26
27#include "h2_private.h"
28#include "h2_session.h"
29#include "h2_bucket_beam.h"
30#include "h2_c2.h"
31#include "h2_mplx.h"
32#include "h2_stream.h"
33#include "h2_util.h"
34#include "h2_conn_ctx.h"
35
36
38{
39 ap_set_module_config(c->conn_config, &http2_module, NULL);
40}
41
42static h2_conn_ctx_t *ctx_create(conn_rec *c, const char *id)
43{
44 h2_conn_ctx_t *conn_ctx = apr_pcalloc(c->pool, sizeof(*conn_ctx));
45 conn_ctx->id = id;
46 conn_ctx->server = c->base_server;
47 apr_atomic_set32(&conn_ctx->started, 1);
48 conn_ctx->started_at = apr_time_now();
49
50 ap_set_module_config(c->conn_config, &http2_module, conn_ctx);
51 return conn_ctx;
52}
53
55{
57
58 ctx = ctx_create(c1, apr_psprintf(c1->pool, "%ld", c1->id));
59 ctx->server = s;
60 ctx->protocol = apr_pstrdup(c1->pool, protocol);
61
62 ctx->pfd.desc_type = APR_POLL_SOCKET;
63 ctx->pfd.desc.s = ap_get_conn_socket(c1);
64 ctx->pfd.reqevents = APR_POLLIN | APR_POLLERR | APR_POLLHUP;
65 ctx->pfd.client_data = ctx;
66 apr_socket_opt_set(ctx->pfd.desc.s, APR_SO_NONBLOCK, 1);
67
68 return ctx;
69}
70
72{
73 ctx->session = session;
74 ctx->id = apr_psprintf(session->pool, "%d-%lu", session->child_num, (unsigned long)session->id);
75}
76
78 struct h2_mplx *mplx, struct h2_stream *stream,
79 struct h2_c2_transit *transit)
80{
83
84 ap_assert(c2->master);
86 if (!conn_ctx) {
88
91 ap_assert(c1_ctx->session);
92
94 conn_ctx->server = c2->master->base_server;
95 }
96
97 conn_ctx->mplx = mplx;
98 conn_ctx->transit = transit;
99 conn_ctx->stream_id = stream->id;
100 apr_pool_create(&conn_ctx->req_pool, c2->pool);
101 apr_pool_tag(conn_ctx->req_pool, "H2_C2_REQ");
102 conn_ctx->request = stream->request;
103 apr_atomic_set32(&conn_ctx->started, 1);
104 conn_ctx->started_at = apr_time_now();
105 conn_ctx->done = 0;
106 conn_ctx->done_at = 0;
107
108 *pctx = conn_ctx;
109 return rv;
110}
111
113{
114 if (conn_ctx->beam_out) {
116 }
117 if (conn_ctx->beam_in) {
119 }
120 if (conn_ctx->pipe_in[H2_PIPE_OUT]) {
122 }
123}
APR Atomic Operations.
APR Strings library.
void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:73
#define ap_set_module_config(v, m, val)
apr_socket_t * ap_get_conn_socket(conn_rec *c)
Definition core.c:5202
apr_brigade_flush void * ctx
#define ap_assert(exp)
Definition httpd.h:2271
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_vformatter_buff_t * c
Definition apr_lib.h:175
int int int protocol
const char apr_uint32_t * id
@ APR_POLL_SOCKET
Definition apr_poll.h:93
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
#define APR_SO_NONBLOCK
const char * s
Definition apr_strings.h:95
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
#define APR_POLLERR
Definition apr_poll.h:52
#define APR_POLLIN
Definition apr_poll.h:49
#define APR_POLLHUP
Definition apr_poll.h:53
void h2_beam_timeout_set(h2_bucket_beam *beam, apr_interval_time_t timeout)
h2_conn_ctx_t * h2_conn_ctx_create_for_c1(conn_rec *c1, server_rec *s, const char *protocol)
Definition h2_conn_ctx.c:54
void h2_conn_ctx_set_timeout(h2_conn_ctx_t *conn_ctx, apr_interval_time_t timeout)
void h2_conn_ctx_assign_session(h2_conn_ctx_t *ctx, struct h2_session *session)
Definition h2_conn_ctx.c:71
apr_status_t h2_conn_ctx_init_for_c2(h2_conn_ctx_t **pctx, conn_rec *c2, struct h2_mplx *mplx, struct h2_stream *stream, struct h2_c2_transit *transit)
Definition h2_conn_ctx.c:77
static h2_conn_ctx_t * ctx_create(conn_rec *c, const char *id)
Definition h2_conn_ctx.c:42
void h2_conn_ctx_detach(conn_rec *c)
Definition h2_conn_ctx.c:37
#define H2_PIPE_OUT
Definition h2_conn_ctx.h:29
#define h2_conn_ctx_get(c)
Definition h2_conn_ctx.h:78
static void transit(h2_proxy_session *session, const char *action, h2_proxys_state nstate)
Apache Configuration.
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
HTTP Daemon routines.
return NULL
Definition mod_so.c:359
Structure to store things which are per connection.
Definition httpd.h:1152
apr_pool_t * pool
Definition httpd.h:1154
server_rec * base_server
Definition httpd.h:1156
conn_rec * master
Definition httpd.h:1248
long id
Definition httpd.h:1187
apr_uint32_t id
Definition h2_session.h:66
int child_num
Definition h2_session.h:65
apr_pool_t * pool
Definition h2_session.h:71
const struct h2_request * request
Definition h2_stream.h:90
A structure to store information for each virtual server.
Definition httpd.h:1322
apr_status_t apr_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
Definition sockopt.c:113
IN ULONG IN INT timeout