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 /* 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_stream__
17 #define __mod_h2__h2_stream__
18 
19 #include "h2.h"
20 
34 struct h2_mplx;
35 struct h2_priority;
36 struct h2_request;
37 struct h2_headers;
38 struct h2_session;
39 struct h2_sos;
40 struct h2_bucket_beam;
41 
42 typedef struct h2_stream h2_stream;
43 
44 struct h2_stream {
45  int id; /* http2 stream id */
46  int initiated_on; /* initiating stream id (PUSH) or 0 */
47  apr_time_t created; /* when stream was created */
48  h2_stream_state_t state; /* http/2 state of this stream */
49  struct h2_session *session; /* the session this stream belongs to */
50 
51  apr_pool_t *pool; /* the memory pool for this stream */
52  const struct h2_request *request; /* the request made in this stream */
53  struct h2_request *rtmp; /* request being assembled */
54  apr_table_t *trailers; /* optional incoming trailers */
55  int request_headers_added; /* number of request headers added */
56 
60  apr_array_header_t *files; /* apr_file_t* we collected during I/O */
61 
62  int rst_error; /* stream error for RST_STREAM */
63  unsigned int aborted : 1; /* was aborted */
64  unsigned int scheduled : 1; /* stream has been scheduled */
65  unsigned int started : 1; /* stream has started processing */
66  unsigned int has_response : 1; /* response headers are known */
67  unsigned int push_policy; /* which push policy to use for this request */
68  unsigned int can_be_cleaned : 1; /* stream pool can be cleaned */
69 
70  const h2_priority *pref_priority; /* preferred priority for this stream */
71  apr_off_t out_data_frames; /* # of DATA frames sent */
72  apr_off_t out_data_octets; /* # of DATA octets (payload) sent */
73  apr_off_t in_data_frames; /* # of DATA frames received */
74  apr_off_t in_data_octets; /* # of DATA octets (payload) received */
75 
76  const char *sos_filter;
77 };
78 
79 
80 #define H2_STREAM_RST(s, def) (s->rst_error? s->rst_error : (def))
81 
89 h2_stream *h2_stream_open(int id, apr_pool_t *pool, struct h2_session *session,
90  int initiated_on);
91 
95 void h2_stream_eos_destroy(h2_stream *stream);
96 
100 void h2_stream_destroy(h2_stream *stream);
101 
107 void h2_stream_cleanup(h2_stream *stream);
108 
117 
125 
133 
134 /*
135  * Add a HTTP/2 header (including pseudo headers) or trailer
136  * to the given stream, depending on stream state.
137  *
138  * @param stream stream to write the header to
139  * @param name the name of the HTTP/2 header
140  * @param nlen the number of characters in name
141  * @param value the header value
142  * @param vlen the number of characters in value
143  */
145  const char *name, size_t nlen,
146  const char *value, size_t vlen);
147 
154 
155 /*
156  * Write a chunk of DATA to the stream.
157  *
158  * @param stream stream to write the data to
159  * @param data the beginning of the bytes to write
160  * @param len the number of bytes to write
161  */
163  const char *data, size_t len, int eos);
164 
171 void h2_stream_rst(h2_stream *stream, int error_code);
172 
183 apr_status_t h2_stream_schedule(h2_stream *stream, int eos, int push_enabled,
184  h2_stream_pri_cmp *cmp, void *ctx);
185 
191 int h2_stream_is_scheduled(const h2_stream *stream);
192 
196 apr_status_t h2_stream_set_error(h2_stream *stream, int http_status);
197 
213  int *peos, h2_headers **presponse);
214 
228  apr_off_t *plen, int *peos);
229 
239 
245 int h2_stream_input_is_open(const h2_stream *stream);
246 
254 
258 const struct h2_priority *h2_stream_get_priority(h2_stream *stream,
260 
265 const char *h2_stream_state_str(h2_stream *stream);
266 
271 int h2_stream_is_ready(h2_stream *stream);
272 
273 #endif /* defined(__mod_h2__h2_stream__) */
int id
Definition: h2_stream.h:45
h2_stream_state_t state
Definition: h2_stream.h:48
apr_pool_t * pool
Definition: h2_stream.h:51
apr_array_header_t * files
Definition: h2_stream.h:60
struct h2_bucket_beam * output
Definition: h2_stream.h:58
const struct h2_priority * h2_stream_get_priority(h2_stream *stream, h2_headers *response)
apr_status_t h2_stream_set_request(h2_stream *stream, const h2_request *r)
struct h2_session * session
Definition: h2_stream.h:49
Definition: h2_mplx.h:62
const char * sos_filter
Definition: h2_stream.h:76
Definition: apr_tables.h:62
int h2_stream_is_scheduled(const h2_stream *stream)
apr_time_t created
Definition: h2_stream.h:47
apr_status_t h2_stream_write_data(h2_stream *stream, const char *data, size_t len, int eos)
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:556
apr_status_t h2_stream_close_input(h2_stream *stream)
h2_stream * h2_stream_open(int id, apr_pool_t *pool, struct h2_session *session, int initiated_on)
Definition: h2.h:71
struct h2_request * rtmp
Definition: h2_stream.h:53
Definition: h2.h:118
apr_table_t * trailers
Definition: h2_stream.h:54
int request_headers_added
Definition: h2_stream.h:55
apr_status_t h2_stream_schedule(h2_stream *stream, int eos, int push_enabled, h2_stream_pri_cmp *cmp, void *ctx)
Definition: h2_bucket_beam.h:177
apr_bucket_brigade * out_buffer
Definition: h2_stream.h:59
const h2_priority * pref_priority
Definition: h2_stream.h:70
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:52
apr_status_t h2_stream_set_request_rec(h2_stream *stream, request_rec *r)
apr_off_t in_data_octets
Definition: h2_stream.h:74
void h2_stream_cleanup(h2_stream *stream)
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_off_t in_data_frames
Definition: h2_stream.h:73
apr_bucket_brigade * bb
Definition: mod_dav.h:556
int h2_stream_input_is_open(const h2_stream *stream)
apr_status_t h2_stream_add_header(h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen)
apr_off_t out_data_octets
Definition: h2_stream.h:72
int initiated_on
Definition: h2_stream.h:46
unsigned int push_policy
Definition: h2_stream.h:67
Definition: h2_stream.h:44
unsigned int can_be_cleaned
Definition: h2_stream.h:68
h2_stream_state_t
Definition: h2.h:83
unsigned int has_response
Definition: h2_stream.h:66
dav_error dav_response * response
Definition: mod_dav.h:203
int h2_stream_pri_cmp(int stream_id1, int stream_id2, void *ctx)
Definition: h2.h:140
apr_pool_t * h2_stream_detach_pool(h2_stream *stream)
const char * h2_stream_state_str(h2_stream *stream)
A structure that represents the current request.
Definition: httpd.h:805
Definition: h2.h:132
apr_status_t h2_stream_set_error(h2_stream *stream, int http_status)
struct h2_bucket_beam * input
Definition: h2_stream.h:57
void h2_stream_rst(h2_stream *stream, int error_code)
int rst_error
Definition: h2_stream.h:62
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
unsigned int aborted
Definition: h2_stream.h:63
const char * name
Definition: mod_dav.h:730
unsigned int started
Definition: h2_stream.h:65
apr_table_t * h2_stream_get_trailers(h2_stream *stream)
apr_off_t out_data_frames
Definition: h2_stream.h:71
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
unsigned int scheduled
Definition: h2_stream.h:64
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:519
void h2_stream_destroy(h2_stream *stream)
int h2_stream_is_ready(h2_stream *stream)
Definition: h2_session.h:76
off_t apr_off_t
Definition: apr.h:377
void h2_stream_eos_destroy(h2_stream *stream)
apr_status_t h2_stream_out_prepare(h2_stream *stream, apr_off_t *plen, int *peos, h2_headers **presponse)