]> granicus.if.org Git - apache/blob - modules/http2/h2_bucket_eos.c
*) mod_http2: internal code cleanups and simplifications. Common output code for
[apache] / modules / http2 / h2_bucket_eos.c
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 #include <assert.h>
18 #include <stddef.h>
19
20 #include <httpd.h>
21 #include <http_core.h>
22 #include <http_connection.h>
23 #include <http_log.h>
24
25 #include "h2_private.h"
26 #include "h2.h"
27 #include "h2_ctx.h"
28 #include "h2_mplx.h"
29 #include "h2_session.h"
30 #include "h2_bucket_eos.h"
31
32 typedef struct {
33     apr_bucket_refcount refcount;
34     conn_rec *c;
35     int stream_id;
36 } h2_bucket_eos;
37
38 static apr_status_t bucket_read(apr_bucket *b, const char **str,
39                                 apr_size_t *len, apr_read_type_e block)
40 {
41     (void)b;
42     (void)block;
43     *str = NULL;
44     *len = 0;
45     return APR_SUCCESS;
46 }
47
48 apr_bucket *h2_bucket_eos_make(apr_bucket *b, conn_rec *c, int stream_id)
49 {
50     h2_bucket_eos *h;
51
52     h = apr_bucket_alloc(sizeof(*h), b->list);
53     h->c = c;
54     h->stream_id = stream_id;
55
56     b = apr_bucket_shared_make(b, h, 0, 0);
57     b->type = &h2_bucket_type_eos;
58     
59     return b;
60 }
61
62 apr_bucket *h2_bucket_eos_create(apr_bucket_alloc_t *list, conn_rec *c, int stream_id)
63 {
64     apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
65
66     APR_BUCKET_INIT(b);
67     b->free = apr_bucket_free;
68     b->list = list;
69     b = h2_bucket_eos_make(b, c, stream_id);
70     return b;
71 }
72
73 static void bucket_destroy(void *data)
74 {
75     h2_bucket_eos *h = data;
76     h2_session *session;
77     
78     if (apr_bucket_shared_destroy(h)) {
79         if ((session = h2_ctx_get_session(h->c))) {
80             h2_session_eos_sent(session, h->stream_id);
81         }
82         apr_bucket_free(h);
83     }
84 }
85
86 const apr_bucket_type_t h2_bucket_type_eos = {
87     "H2EOS", 5, APR_BUCKET_METADATA,
88     bucket_destroy,
89     bucket_read,
90     apr_bucket_setaside_noop,
91     apr_bucket_split_notimpl,
92     apr_bucket_shared_copy
93 };
94