unilink  0.4.3
A simple C++ library for unified async communication
constants.hpp
Go to the documentation of this file.
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 <cstddef>
20 #include <cstdint>
21 
22 namespace unilink {
23 namespace base {
24 
25 // Network and I/O constants
26 namespace constants {
27 
28 // Backpressure threshold constants
29 constexpr size_t DEFAULT_BACKPRESSURE_THRESHOLD = 1 << 20; // 1 MiB
30 constexpr size_t MIN_BACKPRESSURE_THRESHOLD = 1024; // 1 KiB minimum
31 constexpr size_t MAX_BACKPRESSURE_THRESHOLD = 100 << 20; // 100 MiB maximum
32 constexpr size_t DEFAULT_READ_BUFFER_SIZE = 4096; // 4 KiB
33 
34 // Retry and timeout constants
35 constexpr unsigned DEFAULT_RETRY_INTERVAL_MS = 3000; // 3 seconds
36 constexpr unsigned MIN_RETRY_INTERVAL_MS = 100; // 100ms minimum
37 constexpr unsigned MAX_RETRY_INTERVAL_MS = 300000; // 5 minutes maximum
38 constexpr unsigned DEFAULT_CONNECTION_TIMEOUT_MS = 5000; // 5 seconds
39 constexpr unsigned MIN_CONNECTION_TIMEOUT_MS = 100; // 100ms minimum
40 constexpr unsigned MAX_CONNECTION_TIMEOUT_MS = 300000; // 5 minutes maximum
41 
42 // Queue management constants
43 constexpr int DEFAULT_MAX_RETRIES = -1; // Unlimited retries
44 constexpr int MAX_RETRIES_LIMIT = 1000; // Maximum retry limit
45 
46 // Memory pool constants
47 constexpr size_t DEFAULT_MEMORY_POOL_SIZE = 100; // Number of pre-allocated buffers
48 constexpr size_t MIN_MEMORY_POOL_SIZE = 10; // Minimum pool size
49 constexpr size_t MAX_MEMORY_POOL_SIZE = 1000; // Maximum pool size
50 
51 // Buffer size constants
52 constexpr size_t MAX_BUFFER_SIZE = 64 * 1024 * 1024; // 64MB maximum buffer size
53 constexpr size_t MIN_BUFFER_SIZE = 1; // 1 byte minimum buffer size
54 constexpr size_t DEFAULT_BUFFER_SIZE = 4096; // 4KB default buffer size
55 constexpr size_t LARGE_BUFFER_THRESHOLD = 65536; // 64KB threshold for large buffers
56 
57 // Performance and cleanup constants
58 constexpr unsigned DEFAULT_CLEANUP_INTERVAL_MS = 100; // 100ms default cleanup interval
59 constexpr unsigned MIN_CLEANUP_INTERVAL_MS = 10; // 10ms minimum cleanup interval
60 constexpr unsigned MAX_CLEANUP_INTERVAL_MS = 1000; // 1s maximum cleanup interval
61 constexpr unsigned DEFAULT_HEALTH_CHECK_INTERVAL_MS = 1000; // 1s health check interval
62 
63 // Connection and session constants
64 constexpr size_t DEFAULT_MAX_CONNECTIONS = 1000; // Default maximum connections
65 constexpr size_t MAX_MAX_CONNECTIONS = 10000; // Maximum allowed connections
66 constexpr size_t DEFAULT_SESSION_TIMEOUT_MS = 30000; // 30s default session timeout
67 constexpr size_t MIN_SESSION_TIMEOUT_MS = 1000; // 1s minimum session timeout
68 constexpr size_t MAX_SESSION_TIMEOUT_MS = 300000; // 5m maximum session timeout
69 
70 // Error handling constants
71 constexpr size_t DEFAULT_MAX_RECENT_ERRORS = 1000; // Default max recent errors to track
72 constexpr size_t MAX_MAX_RECENT_ERRORS = 10000; // Maximum recent errors to track
73 constexpr size_t DEFAULT_ERROR_CLEANUP_INTERVAL_MS = 60000; // 1m error cleanup interval
74 
75 // Validation constants
76 constexpr size_t MAX_HOSTNAME_LENGTH = 253; // Maximum hostname length (RFC 1123)
77 constexpr size_t MAX_DEVICE_PATH_LENGTH = 256; // Maximum device path length
78 constexpr uint32_t MIN_BAUD_RATE = 50; // Minimum baud rate
79 constexpr uint32_t MAX_BAUD_RATE = 4000000; // Maximum baud rate
80 constexpr uint8_t MIN_DATA_BITS = 5; // Minimum data bits
81 constexpr uint8_t MAX_DATA_BITS = 8; // Maximum data bits
82 constexpr uint8_t MIN_STOP_BITS = 1; // Minimum stop bits
83 constexpr uint8_t MAX_STOP_BITS = 2; // Maximum stop bits
84 
85 // Threading and concurrency constants
86 constexpr size_t DEFAULT_THREAD_POOL_SIZE = 4; // Default thread pool size
87 constexpr size_t MIN_THREAD_POOL_SIZE = 1; // Minimum thread pool size
88 constexpr size_t MAX_THREAD_POOL_SIZE = 64; // Maximum thread pool size
89 constexpr unsigned DEFAULT_THREAD_STACK_SIZE = 1024 * 1024; // 1MB default stack size
90 
91 } // namespace constants
92 
93 } // namespace base
94 
95 // Compatibility alias while transitioning from legacy `common` namespace.
96 namespace common {
97 namespace constants = base::constants;
98 } // namespace common
99 } // namespace unilink