]> granicus.if.org Git - apache/blob - modules/http2/h2_io.h
merged latest changes in 2.4.x
[apache] / modules / http2 / h2_io.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_io__
17 #define __mod_h2__h2_io__
18
19 struct h2_response;
20 struct apr_thread_cond_t;
21 struct h2_task;
22
23
24 typedef apr_status_t h2_io_data_cb(void *ctx, 
25                                    const char *data, apr_size_t len);
26
27
28 typedef struct h2_io h2_io;
29
30 struct h2_io {
31     int id;                      /* stream identifier */
32     apr_pool_t *pool;            /* stream pool */
33     apr_bucket_brigade *bbin;    /* input data for stream */
34     int eos_in;
35     int task_done;
36     
37     apr_size_t input_consumed;   /* how many bytes have been read */
38     struct apr_thread_cond_t *input_arrived; /* block on reading */
39     
40     apr_bucket_brigade *bbout;   /* output data from stream */
41     struct apr_thread_cond_t *output_drained; /* block on writing */
42     
43     struct h2_response *response;/* submittable response created */
44     int files_handles_owned;
45 };
46
47 /*******************************************************************************
48  * Object lifecycle and information.
49  ******************************************************************************/
50
51 /**
52  * Creates a new h2_io for the given stream id. 
53  */
54 h2_io *h2_io_create(int id, apr_pool_t *pool, apr_bucket_alloc_t *bucket_alloc);
55
56 /**
57  * Frees any resources hold by the h2_io instance. 
58  */
59 void h2_io_destroy(h2_io *io);
60
61 /**
62  * The input data is completely queued. Blocked reads will return immediately
63  * and give either data or EOF.
64  */
65 int h2_io_in_has_eos_for(h2_io *io);
66 /**
67  * Output data is available.
68  */
69 int h2_io_out_has_data(h2_io *io);
70
71 /*******************************************************************************
72  * Input handling of streams.
73  ******************************************************************************/
74 /**
75  * Reads the next bucket from the input. Returns APR_EAGAIN if none
76  * is currently available, APR_EOF if end of input has been reached.
77  */
78 apr_status_t h2_io_in_read(h2_io *io, apr_bucket_brigade *bb, 
79                            apr_size_t maxlen);
80
81 /**
82  * Appends given bucket to the input.
83  */
84 apr_status_t h2_io_in_write(h2_io *io, apr_bucket_brigade *bb);
85
86 /**
87  * Closes the input. After existing data has been read, APR_EOF will
88  * be returned.
89  */
90 apr_status_t h2_io_in_close(h2_io *io);
91
92 /*******************************************************************************
93  * Output handling of streams.
94  ******************************************************************************/
95
96 /**
97  * Read a bucket from the output head. Return APR_EAGAIN if non is available,
98  * APR_EOF if none available and output has been closed. 
99  * May be called with buffer == NULL in order to find out how much data
100  * is available.
101  * @param io the h2_io to read output from
102  * @param buffer the buffer to copy the data to, may be NULL
103  * @param plen the requested max len, set to amount of data on return
104  * @param peos != 0 iff the end of stream has been reached
105  */
106 apr_status_t h2_io_out_readx(h2_io *io,  
107                              h2_io_data_cb *cb, void *ctx, 
108                              apr_size_t *plen, int *peos);
109
110 apr_status_t h2_io_out_write(h2_io *io, apr_bucket_brigade *bb, 
111                              apr_size_t maxlen, int *pfile_buckets_allowed);
112
113 /**
114  * Closes the input. After existing data has been read, APR_EOF will
115  * be returned.
116  */
117 apr_status_t h2_io_out_close(h2_io *io);
118
119 /**
120  * Gives the overall length of the data that is currently queued for
121  * output.
122  */
123 apr_size_t h2_io_out_length(h2_io *io);
124
125
126 #endif /* defined(__mod_h2__h2_io__) */