unilink  0.4.3
A simple C++ library for unified async communication
tcp_server_config.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 <cstdint>
20 #include <string>
21 
24 
25 namespace unilink {
26 namespace config {
27 
29  std::string bind_address = "0.0.0.0";
30  uint16_t port = 9000;
32  bool enable_memory_pool = true;
33  int max_connections = 100; // Maximum concurrent connections
34 
35  // Port binding retry configuration
36  bool enable_port_retry = false; // Enable port binding retry
37  int max_port_retries = 3; // Maximum number of retry attempts
38  int port_retry_interval_ms = 1000; // Retry interval in milliseconds
39 
40  int idle_timeout_ms = 0; // Idle connection timeout in milliseconds (0 = disabled)
41 
42  // Validation methods
43  bool is_valid() const {
46  backpressure_threshold <= common::constants::MAX_BACKPRESSURE_THRESHOLD && max_connections > 0 &&
47  idle_timeout_ms >= 0;
48  }
49 
50  // Apply validation and clamp values to valid ranges
56  }
57 
58  if (max_connections <= 0) {
59  max_connections = 1;
60  }
61 
62  if (idle_timeout_ms < 0) {
63  idle_timeout_ms = 0;
64  }
65  }
66 };
67 
68 } // namespace config
69 } // namespace unilink