3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/ext/transport/chttp2/transport/incoming_metadata.h"
25 #include "src/core/ext/transport/chttp2/transport/internal.h"
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
30 grpc_error* grpc_chttp2_incoming_metadata_buffer_add(
31 grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) {
32 buffer->size += GRPC_MDELEM_LENGTH(elem);
33 grpc_linked_mdelem* storage;
34 if (buffer->count < buffer->kPreallocatedMDElem) {
35 storage = &buffer->preallocated_mdelems[buffer->count];
38 storage = static_cast<grpc_linked_mdelem*>(
39 buffer->arena->Alloc(sizeof(grpc_linked_mdelem)));
42 return grpc_metadata_batch_link_tail(&buffer->batch, storage);
45 grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add(
46 grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) {
47 for (grpc_linked_mdelem* l = buffer->batch.list.head; l != nullptr;
49 if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) {
50 GRPC_MDELEM_UNREF(l->md);
52 return GRPC_ERROR_NONE;
55 return grpc_chttp2_incoming_metadata_buffer_add(buffer, elem);
58 void grpc_chttp2_incoming_metadata_buffer_set_deadline(
59 grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline) {
60 buffer->batch.deadline = deadline;
63 void grpc_chttp2_incoming_metadata_buffer_publish(
64 grpc_chttp2_incoming_metadata_buffer* buffer, grpc_metadata_batch* batch) {
65 grpc_metadata_batch_move(&buffer->batch, batch);