Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 Jinwoo Sung
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.apache.org/licenses/LICENSE-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : #pragma once
18 : :
19 : : #include <array>
20 : : #include <cstddef>
21 : : #include <cstdint>
22 : : #include <stdexcept>
23 : :
24 : : namespace wirestead::wrapper {
25 : : // Bounds library-retained receive payloads and batch context records, not
26 : : // kernel buffers, allocator bookkeeping or copies retained by application code.
27 : : struct ReceiveLimits {
28 : : size_t max_bytes = 64 * 1024 * 1024;
29 : : size_t max_frame_bytes = 1024 * 1024;
30 : : size_t max_sessions = 1024;
31 : :
32 : 1918 : void validate() const {
33 [ + + + + : 1918 : if (!max_bytes || !max_frame_bytes || max_frame_bytes > max_bytes || !max_sessions)
+ + + + ]
34 : 11 : throw std::invalid_argument("receive limits must be positive and frame bytes must fit the total byte limit");
35 : 1907 : }
36 : : };
37 : :
38 : : enum class ReceiveOverflowReason { ByteLimit, FrameLimit, SessionLimit, AllocationFailure };
39 : :
40 : : struct ReceiveMemoryStats {
41 : : size_t reserved_bytes = 0;
42 : : size_t peak_reserved_bytes = 0;
43 : : size_t sessions = 0;
44 : : uint64_t overflow_events = 0;
45 : : uint64_t overflow_bytes = 0;
46 : : std::array<uint64_t, 4> overflow_by_reason{};
47 : : };
48 : : } // namespace wirestead::wrapper
|