1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __mod_h2__h2_io__
17 #define __mod_h2__h2_io__
20 struct apr_thread_cond_t;
24 typedef apr_status_t h2_io_data_cb(void *ctx,
25 const char *data, apr_size_t len);
28 typedef struct h2_io h2_io;
31 int id; /* stream identifier */
32 apr_pool_t *pool; /* stream pool */
33 apr_bucket_brigade *bbin; /* input data for stream */
37 apr_size_t input_consumed; /* how many bytes have been read */
38 struct apr_thread_cond_t *input_arrived; /* block on reading */
40 apr_bucket_brigade *bbout; /* output data from stream */
41 struct apr_thread_cond_t *output_drained; /* block on writing */
43 struct h2_response *response;/* submittable response created */
44 int files_handles_owned;
47 /*******************************************************************************
48 * Object lifecycle and information.
49 ******************************************************************************/
52 * Creates a new h2_io for the given stream id.
54 h2_io *h2_io_create(int id, apr_pool_t *pool, apr_bucket_alloc_t *bucket_alloc);
57 * Frees any resources hold by the h2_io instance.
59 void h2_io_destroy(h2_io *io);
62 * The input data is completely queued. Blocked reads will return immediately
63 * and give either data or EOF.
65 int h2_io_in_has_eos_for(h2_io *io);
67 * Output data is available.
69 int h2_io_out_has_data(h2_io *io);
71 /*******************************************************************************
72 * Input handling of streams.
73 ******************************************************************************/
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.
78 apr_status_t h2_io_in_read(h2_io *io, apr_bucket_brigade *bb,
82 * Appends given bucket to the input.
84 apr_status_t h2_io_in_write(h2_io *io, apr_bucket_brigade *bb);
87 * Closes the input. After existing data has been read, APR_EOF will
90 apr_status_t h2_io_in_close(h2_io *io);
92 /*******************************************************************************
93 * Output handling of streams.
94 ******************************************************************************/
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
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
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);
110 apr_status_t h2_io_out_write(h2_io *io, apr_bucket_brigade *bb,
111 apr_size_t maxlen, int *pfile_buckets_allowed);
114 * Closes the input. After existing data has been read, APR_EOF will
117 apr_status_t h2_io_out_close(h2_io *io);
120 * Gives the overall length of the data that is currently queued for
123 apr_size_t h2_io_out_length(h2_io *io);
126 #endif /* defined(__mod_h2__h2_io__) */