GRPC Core  18.0.0
slice_allocator.h
Go to the documentation of this file.
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 #ifndef GRPC_EVENT_ENGINE_SLICE_ALLOCATOR_H
15 #define GRPC_EVENT_ENGINE_SLICE_ALLOCATOR_H
16 
18 
19 #include <functional>
20 
21 #include "absl/status/status.h"
22 
23 // forward-declaring an internal struct, not used publicly.
24 struct grpc_resource_quota;
25 struct grpc_resource_user;
26 struct grpc_slice_buffer;
27 
28 namespace grpc_event_engine {
29 namespace experimental {
30 
31 // TODO(hork): stubbed out here, to be replaced with a real version in next PR.
32 class SliceBuffer {
33  public:
34  SliceBuffer() { abort(); }
35  explicit SliceBuffer(grpc_slice_buffer*) { abort(); }
36 };
37 
39  public:
40  // gRPC-internal constructor
41  explicit SliceAllocator(grpc_resource_user* user);
42  // Not copyable
43  SliceAllocator(SliceAllocator& other) = delete;
44  SliceAllocator& operator=(const SliceAllocator& other) = delete;
45  // Moveable
46  SliceAllocator(SliceAllocator&& other) noexcept;
47  SliceAllocator& operator=(SliceAllocator&& other) noexcept;
49 
51  std::function<void(absl::Status, SliceBuffer* buffer)>;
60  absl::Status Allocate(size_t size, SliceBuffer* dest,
62 
63  private:
64  grpc_resource_user* resource_user_;
65 };
66 
68  public:
69  // gRPC-internal constructor
71  // Not copyable
74  // Moveable
78 
82  SliceAllocator CreateSliceAllocator(absl::string_view peer_name);
83 
84  private:
85  grpc_resource_quota* resource_quota_;
86 };
87 
88 } // namespace experimental
89 } // namespace grpc_event_engine
90 
91 #endif // GRPC_EVENT_ENGINE_SLICE_ALLOCATOR_H
SliceAllocatorFactory(SliceAllocatorFactory &other)=delete
~SliceAllocatorFactory()
Definition: slice_allocator.cc:63
SliceAllocatorFactory & operator=(const SliceAllocatorFactory &other)=delete
SliceAllocator CreateSliceAllocator(absl::string_view peer_name)
On Endpoint creation, call CreateSliceAllocator with the name of the endpoint peer (a URI string,...
Definition: slice_allocator.cc:82
SliceAllocatorFactory(grpc_resource_quota *quota)
Definition: slice_allocator.cc:58
Definition: slice_allocator.h:38
absl::Status Allocate(size_t size, SliceBuffer *dest, SliceAllocator::AllocateCallback cb)
Requests size bytes from gRPC, and populates dest with the allocated slices.
Definition: slice_allocator.cc:49
SliceAllocator(SliceAllocator &other)=delete
SliceAllocator & operator=(const SliceAllocator &other)=delete
std::function< void(absl::Status, SliceBuffer *buffer)> AllocateCallback
Definition: slice_allocator.h:51
SliceAllocator(grpc_resource_user *user)
Definition: slice_allocator.cc:27
~SliceAllocator()
Definition: slice_allocator.cc:32
Definition: slice_allocator.h:32
SliceBuffer()
Definition: slice_allocator.h:34
SliceBuffer(grpc_slice_buffer *)
Definition: slice_allocator.h:35
Definition: endpoint_config.h:24
Definition: resource_quota.cc:127
Definition: resource_quota.cc:65
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice.h:78