Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / src / core / ext / transport / chttp2 / transport / chttp2_slice_allocator.cc
1 // Copyright 2021 The gRPC Authors
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 #include <grpc/support/port_platform.h>
15
16 #include "src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h"
17
18 #include <functional>
19
20 #include "absl/memory/memory.h"
21 #include "absl/status/status.h"
22
23 #include <grpc/event_engine/slice_allocator.h>
24
25 #include "src/core/lib/iomgr/resource_quota.h"
26
27 namespace grpc_event_engine {
28 namespace experimental {
29
30 Chttp2SliceAllocator::Chttp2SliceAllocator(grpc_resource_user* user)
31     : resource_user_(user) {}
32
33 Chttp2SliceAllocator::~Chttp2SliceAllocator() {
34   if (resource_user_ != nullptr) {
35     grpc_resource_user_unref(resource_user_);
36   }
37 }
38
39 absl::Status Chttp2SliceAllocator::Allocate(
40     size_t size, SliceBuffer* dest, SliceAllocator::AllocateCallback cb) {
41   // TODO(hork): merge the implementation from the uv-ee branch.
42   (void)size;
43   (void)dest;
44   (void)cb;
45   return absl::OkStatus();
46 }
47
48 Chttp2SliceAllocatorFactory::Chttp2SliceAllocatorFactory(
49     grpc_resource_quota* quota)
50     : resource_quota_(quota) {
51   grpc_resource_quota_ref_internal(resource_quota_);
52 }
53
54 Chttp2SliceAllocatorFactory::~Chttp2SliceAllocatorFactory() {
55   if (resource_quota_ != nullptr) {
56     grpc_resource_quota_unref_internal(resource_quota_);
57   }
58 }
59
60 std::unique_ptr<SliceAllocator>
61 Chttp2SliceAllocatorFactory::CreateSliceAllocator(absl::string_view peer_name) {
62   return absl::make_unique<Chttp2SliceAllocator>(
63       grpc_resource_user_create(resource_quota_, peer_name));
64 }
65
66 }  // namespace experimental
67 }  // namespace grpc_event_engine