1 // Copyright 2021 The gRPC Authors
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.
14 #include <grpc/support/port_platform.h>
16 #include "src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h"
20 #include "absl/memory/memory.h"
21 #include "absl/status/status.h"
23 #include <grpc/event_engine/slice_allocator.h>
25 #include "src/core/lib/iomgr/resource_quota.h"
27 namespace grpc_event_engine {
28 namespace experimental {
30 Chttp2SliceAllocator::Chttp2SliceAllocator(grpc_resource_user* user)
31 : resource_user_(user) {}
33 Chttp2SliceAllocator::~Chttp2SliceAllocator() {
34 if (resource_user_ != nullptr) {
35 grpc_resource_user_unref(resource_user_);
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.
45 return absl::OkStatus();
48 Chttp2SliceAllocatorFactory::Chttp2SliceAllocatorFactory(
49 grpc_resource_quota* quota)
50 : resource_quota_(quota) {
51 grpc_resource_quota_ref_internal(resource_quota_);
54 Chttp2SliceAllocatorFactory::~Chttp2SliceAllocatorFactory() {
55 if (resource_quota_ != nullptr) {
56 grpc_resource_quota_unref_internal(resource_quota_);
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));
66 } // namespace experimental
67 } // namespace grpc_event_engine