Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / ext / transport / chttp2 / transport / incoming_metadata.cc
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/core/ext/transport/chttp2/transport/incoming_metadata.h"
22
23 #include <string.h>
24
25 #include "src/core/ext/transport/chttp2/transport/internal.h"
26
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
29
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];
36     buffer->count++;
37   } else {
38     storage = static_cast<grpc_linked_mdelem*>(
39         buffer->arena->Alloc(sizeof(grpc_linked_mdelem)));
40   }
41   storage->md = elem;
42   return grpc_metadata_batch_link_tail(&buffer->batch, storage);
43 }
44
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;
48        l = l->next) {
49     if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) {
50       GRPC_MDELEM_UNREF(l->md);
51       l->md = elem;
52       return GRPC_ERROR_NONE;
53     }
54   }
55   return grpc_chttp2_incoming_metadata_buffer_add(buffer, elem);
56 }
57
58 void grpc_chttp2_incoming_metadata_buffer_set_deadline(
59     grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline) {
60   buffer->batch.deadline = deadline;
61 }
62
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);
66 }