]> granicus.if.org Git - apache/blob - modules/http2/h2_session.h
merged latest changes in 2.4.x
[apache] / modules / http2 / h2_session.h
1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __mod_h2__h2_session__
17 #define __mod_h2__h2_session__
18
19 #include "h2_conn_io.h"
20
21 /**
22  * A HTTP/2 connection, a session with a specific client.
23  * 
24  * h2_session sits on top of a httpd conn_rec* instance and takes complete
25  * control of the connection data. It receives protocol frames from the
26  * client. For new HTTP/2 streams it creates h2_task(s) that are sent
27  * via callback to a dispatcher (see h2_conn.c).
28  * h2_session keeps h2_io's for each ongoing stream which buffer the
29  * payload for that stream.
30  *
31  * New incoming HEADER frames are converted into a h2_stream+h2_task instance
32  * that both represent a HTTP/2 stream, but may have separate lifetimes. This
33  * allows h2_task to be scheduled in other threads without semaphores
34  * all over the place. It allows task memory to be freed independant of
35  * session lifetime and sessions may close down while tasks are still running.
36  *
37  *
38  */
39
40 struct apr_thread_mutext_t;
41 struct apr_thread_cond_t;
42 struct h2_config;
43 struct h2_mplx;
44 struct h2_response;
45 struct h2_session;
46 struct h2_stream;
47 struct h2_task;
48 struct h2_workers;
49
50 struct nghttp2_session;
51
52 typedef struct h2_session h2_session;
53
54 struct h2_session {
55     long id;                        /* identifier of this session, unique
56                                      * inside a httpd process */
57     conn_rec *c;                    /* the connection this session serves */
58     request_rec *r;                 /* the request that started this in case
59                                      * of 'h2c', NULL otherwise */
60     int aborted;                    /* this session is being aborted */
61     apr_size_t frames_received;     /* number of http/2 frames received */
62     apr_size_t max_stream_count;    /* max number of open streams */
63     apr_size_t max_stream_mem;      /* max buffer memory for a single stream */
64     
65     apr_pool_t *pool;               /* pool to use in session handling */
66     apr_bucket_brigade *bbtmp;      /* brigade for keeping temporary data */
67     struct apr_thread_cond_t *iowait; /* our cond when trywaiting for data */
68     
69     h2_conn_io io;                  /* io on httpd conn filters */
70     struct h2_mplx *mplx;           /* multiplexer for stream data */
71     
72     struct h2_stream_set *streams;  /* streams handled by this session */
73     
74     struct nghttp2_session *ngh2;   /* the nghttp2 session (internal use) */
75     struct h2_workers *workers;     /* for executing stream tasks */
76 };
77
78
79 /* Create a new h2_session for the given connection (mode 'h2').
80  * The session will apply the configured parameter.
81  */
82 h2_session *h2_session_create(conn_rec *c, struct h2_config *cfg, 
83                               struct h2_workers *workers);
84
85 /* Create a new h2_session for the given request (mode 'h2c').
86  * The session will apply the configured parameter.
87  */
88 h2_session *h2_session_rcreate(request_rec *r, struct h2_config *cfg,
89                                struct h2_workers *workers);
90
91 /* Destroy the session and all object it still contains. This will not
92  * destroy h2_task instances that not finished yet. */
93 void h2_session_destroy(h2_session *session);
94
95 /* Called once at start of session. Performs initial client thingies. */
96 apr_status_t h2_session_start(h2_session *session, int *rv);
97
98 /* Return != 0 iff session is finished and connection can be closed.
99  */
100 int h2_session_is_done(h2_session *session);
101
102 /* Called when the session will shutdown after all open streams
103  * are handled. New streams will no longer be accepted. 
104  * Call with reason APR_SUCCESS to initiate a graceful shutdown. */
105 apr_status_t h2_session_goaway(h2_session *session, apr_status_t reason);
106
107 /* Called when an error occured and the session needs to shut down.
108  * Status indicates the reason of the error. */
109 apr_status_t h2_session_abort(h2_session *session, apr_status_t reason, int rv);
110
111 /* Called before a session gets destroyed, might flush output etc. */
112 apr_status_t h2_session_close(h2_session *session);
113
114 /* Read more data from the client connection. Used normally with blocking
115  * APR_NONBLOCK_READ, which will return APR_EAGAIN when no data is available.
116  * Use with APR_BLOCK_READ only when certain that no data needs to be written
117  * while waiting. */
118 apr_status_t h2_session_read(h2_session *session, apr_read_type_e block);
119
120 /* Write data out to the client, if there is any. Otherwise, wait for
121  * a maximum of timeout micro-seconds and return to the caller. If timeout
122  * occurred, APR_TIMEUP will be returned.
123  */
124 apr_status_t h2_session_write(h2_session *session,
125                               apr_interval_time_t timeout);
126
127 /* Start submitting the response to a stream request. This is possible
128  * once we have all the response headers. */
129 apr_status_t h2_session_handle_response(h2_session *session,
130                                         struct h2_stream *stream);
131
132 /* Get the h2_stream for the given stream idenrtifier. */
133 struct h2_stream *h2_session_get_stream(h2_session *session, int stream_id);
134
135 void h2_session_log_stats(h2_session *session);
136
137 #endif /* defined(__mod_h2__h2_session__) */