Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h2_stream.h
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 #ifndef __mod_h2__h2_stream__
18 #define __mod_h2__h2_stream__
19 
20 #include "h2.h"
21 
37 struct h2_mplx;
38 struct h2_priority;
39 struct h2_request;
40 struct h2_headers;
41 struct h2_session;
42 struct h2_task;
43 struct h2_bucket_beam;
44 
45 typedef struct h2_stream h2_stream;
46 
47 typedef void h2_stream_state_cb(void *ctx, h2_stream *stream);
48 typedef void h2_stream_event_cb(void *ctx, h2_stream *stream,
50 
54 typedef struct h2_stream_monitor {
55  void *ctx;
56  h2_stream_state_cb *on_state_enter; /* called when a state is entered */
57  h2_stream_state_cb *on_state_invalid; /* called when an invalid state change
58  was detected */
59  h2_stream_event_cb *on_state_event; /* called right before the given event
60  result in a new stream state */
61  h2_stream_event_cb *on_event; /* called for events that do not
62  trigger a state change */
64 
65 struct h2_stream {
66  int id; /* http2 stream identifier */
67  int initiated_on; /* initiating stream id (PUSH) or 0 */
68  apr_pool_t *pool; /* the memory pool for this stream */
69  struct h2_session *session; /* the session this stream belongs to */
70  h2_stream_state_t state; /* state of this stream */
71 
72  apr_time_t created; /* when stream was created */
73 
74  const struct h2_request *request; /* the request made in this stream */
75  struct h2_request *rtmp; /* request being assembled */
76  apr_table_t *trailers; /* optional incoming trailers */
77  int request_headers_added; /* number of request headers added */
78 
83 
86  apr_size_t max_mem; /* maximum amount of data buffered */
87 
88  int rst_error; /* stream error for RST_STREAM */
89  unsigned int aborted : 1; /* was aborted */
90  unsigned int scheduled : 1; /* stream has been scheduled */
91  unsigned int has_response : 1; /* response headers are known */
92  unsigned int input_eof : 1; /* no more request data coming */
93  unsigned int out_checked : 1; /* output eof was double checked */
94  unsigned int push_policy; /* which push policy to use for this request */
95 
96  struct h2_task *task; /* assigned task to fullfill request */
97 
98  const h2_priority *pref_priority; /* preferred priority for this stream */
99  apr_off_t out_frames; /* # of frames sent out */
100  apr_off_t out_frame_octets; /* # of RAW frame octets sent out */
101  apr_off_t out_data_frames; /* # of DATA frames sent */
102  apr_off_t out_data_octets; /* # of DATA octets (payload) sent */
103  apr_off_t in_data_frames; /* # of DATA frames received */
104  apr_off_t in_data_octets; /* # of DATA octets (payload) received */
105  apr_off_t in_trailer_octets; /* # of HEADER octets (payload) received in trailers */
106 
107  h2_stream_monitor *monitor; /* optional monitor for stream states */
108 };
109 
110 
111 #define H2_STREAM_RST(s, def) (s->rst_error? s->rst_error : (def))
112 
125  struct h2_session *session,
127  int initiated_on);
128 
132 void h2_stream_destroy(h2_stream *stream);
133 
142 
143 /*
144  * Set a new monitor for this stream, replacing any existing one. Can
145  * be called with NULL to have no monitor installed.
146  */
148 
155 
161 void h2_stream_cleanup(h2_stream *stream);
162 
168 
176 void h2_stream_set_request(h2_stream *stream, const h2_request *r);
177 
186  request_rec *r, int eos);
187 
188 /*
189  * Add a HTTP/2 header (including pseudo headers) or trailer
190  * to the given stream, depending on stream state.
191  *
192  * @param stream stream to write the header to
193  * @param name the name of the HTTP/2 header
194  * @param nlen the number of characters in name
195  * @param value the header value
196  * @param vlen the number of characters in value
197  */
199  const char *name, size_t nlen,
200  const char *value, size_t vlen);
201 
202 apr_status_t h2_stream_send_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len);
203 apr_status_t h2_stream_recv_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len);
204 
205 /*
206  * Process a frame of received DATA.
207  *
208  * @param stream stream to write the data to
209  * @param flags the frame flags
210  * @param data the beginning of the bytes to write
211  * @param len the number of bytes to write
212  */
214  const uint8_t *data, size_t len);
215 
217 
224 void h2_stream_rst(h2_stream *stream, int error_code);
225 
234 int h2_stream_was_closed(const h2_stream *stream);
235 
251  int *peos, h2_headers **presponse);
252 
266  apr_off_t *plen, int *peos);
267 
277 
285 
289 const struct h2_priority *h2_stream_get_priority(h2_stream *stream,
291 
296 const char *h2_stream_state_str(h2_stream *stream);
297 
302 int h2_stream_is_ready(h2_stream *stream);
303 
304 #define H2_STRM_MSG(s, msg) \
305  "h2_stream(%ld-%d,%s): "msg, s->session->id, s->id, h2_stream_state_str(s)
306 
307 #define H2_STRM_LOG(aplogno, s, msg) aplogno H2_STRM_MSG(s, msg)
308 
309 #endif /* defined(__mod_h2__h2_stream__) */
h2_stream_monitor * monitor
Definition: h2_stream.h:107
apr_off_t out_frame_octets
Definition: h2_stream.h:100
size_t apr_size_t
Definition: apr.h:375
apr_off_t out_frames
Definition: h2_stream.h:99
int id
Definition: h2_stream.h:66
h2_stream_state_t state
Definition: h2_stream.h:70
apr_status_t h2_stream_recv_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
apr_status_t h2_stream_flush_input(h2_stream *stream)
apr_pool_t * pool
Definition: h2_stream.h:68
struct h2_bucket_beam * output
Definition: h2_stream.h:84
apr_time_t in_last_write
Definition: h2_stream.h:82
Definition: h2_task.h:53
const struct h2_priority * h2_stream_get_priority(h2_stream *stream, h2_headers *response)
struct h2_session * session
Definition: h2_stream.h:69
Definition: h2_mplx.h:57
apr_time_t created
Definition: h2_stream.h:72
int in_window_size
Definition: h2_stream.h:81
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:552
Definition: h2.h:75
unsigned int input_eof
Definition: h2_stream.h:92
h2_stream * h2_stream_create(int id, apr_pool_t *pool, struct h2_session *session, h2_stream_monitor *monitor, int initiated_on)
apr_status_t h2_stream_set_request_rec(h2_stream *stream, request_rec *r, int eos)
struct h2_request * rtmp
Definition: h2_stream.h:75
Definition: h2.h:133
apr_table_t * trailers
Definition: h2_stream.h:76
h2_stream_state_cb * on_state_enter
Definition: h2_stream.h:56
h2_stream_state_cb * on_state_invalid
Definition: h2_stream.h:57
void h2_stream_state_cb(void *ctx, h2_stream *stream)
Definition: h2_stream.h:47
struct h2_stream_monitor h2_stream_monitor
int request_headers_added
Definition: h2_stream.h:77
Definition: h2_bucket_beam.h:164
void h2_stream_dispatch(h2_stream *stream, h2_stream_event_t ev)
apr_bucket_brigade * out_buffer
Definition: h2_stream.h:85
const h2_priority * pref_priority
Definition: h2_stream.h:98
apr_status_t h2_stream_submit_pushes(h2_stream *stream, h2_headers *response)
Definition: apr_buckets.h:258
const struct h2_request * request
Definition: h2_stream.h:74
void h2_stream_set_monitor(h2_stream *stream, h2_stream_monitor *monitor)
apr_status_t h2_stream_prep_processing(h2_stream *stream)
apr_off_t in_data_octets
Definition: h2_stream.h:104
unsigned int out_checked
Definition: h2_stream.h:93
void h2_stream_cleanup(h2_stream *stream)
apr_off_t in_trailer_octets
Definition: h2_stream.h:105
struct h2_task * task
Definition: h2_stream.h:96
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_off_t in_data_frames
Definition: h2_stream.h:103
apr_bucket_brigade * bb
Definition: mod_dav.h:552
apr_status_t h2_stream_add_header(h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen)
apr_status_t h2_stream_recv_DATA(h2_stream *stream, uint8_t flags, const uint8_t *data, size_t len)
apr_off_t out_data_octets
Definition: h2_stream.h:102
int initiated_on
Definition: h2_stream.h:67
void h2_stream_event_cb(void *ctx, h2_stream *stream, h2_stream_event_t ev)
Definition: h2_stream.h:48
unsigned int push_policy
Definition: h2_stream.h:94
Definition: h2_stream.h:65
h2_stream_state_t
Definition: h2.h:106
unsigned int has_response
Definition: h2_stream.h:91
dav_error dav_response * response
Definition: mod_dav.h:203
void h2_stream_set_request(h2_stream *stream, const h2_request *r)
apr_status_t h2_stream_in_consumed(h2_stream *stream, apr_off_t amount)
h2_stream_event_t
Definition: h2.h:118
const char * h2_stream_state_str(h2_stream *stream)
A structure that represents the current request.
Definition: httpd.h:806
Definition: h2.h:148
Definition: h2_stream.h:54
int h2_stream_was_closed(const h2_stream *stream)
struct h2_bucket_beam * input
Definition: h2_stream.h:79
void h2_stream_rst(h2_stream *stream, int error_code)
unsigned int eos
Definition: h2_task.h:65
int rst_error
Definition: h2_stream.h:88
int monitor(apr_pool_t *p, server_rec *s)
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
unsigned int aborted
Definition: h2_stream.h:89
const char * name
Definition: mod_dav.h:726
apr_table_t * h2_stream_get_trailers(h2_stream *stream)
apr_off_t out_data_frames
Definition: h2_stream.h:101
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
unsigned int scheduled
Definition: h2_stream.h:90
int apr_status_t
Definition: apr_errno.h:44
apr_status_t h2_stream_read_to(h2_stream *stream, apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
request_rec * r
Definition: mod_dav.h:515
void h2_stream_destroy(h2_stream *stream)
h2_stream_event_cb * on_event
Definition: h2_stream.h:61
h2_stream_event_cb * on_state_event
Definition: h2_stream.h:59
apr_status_t h2_stream_send_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
apr_bucket_brigade * in_buffer
Definition: h2_stream.h:80
int h2_stream_is_ready(h2_stream *stream)
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1346
Definition: h2_session.h:75
off_t apr_off_t
Definition: apr.h:377
apr_size_t max_mem
Definition: h2_stream.h:86
apr_status_t h2_stream_out_prepare(h2_stream *stream, apr_off_t *plen, int *peos, h2_headers **presponse)
void * ctx
Definition: h2_stream.h:55