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
22
#include "
unilink/base/constants.hpp
"
23
#include "
unilink/util/input_validator.hpp
"
24
25
namespace
unilink
{
26
namespace
config {
27
28
struct
TcpServerConfig
{
29
std::string
bind_address
=
"0.0.0.0"
;
30
uint16_t
port
= 9000;
31
size_t
backpressure_threshold
=
common::constants::DEFAULT_BACKPRESSURE_THRESHOLD
;
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
{
44
return
(
util::InputValidator::is_valid_ipv4
(
bind_address
) ||
util::InputValidator::is_valid_ipv6
(
bind_address
)) &&
45
port
> 0 &&
backpressure_threshold
>=
common::constants::MIN_BACKPRESSURE_THRESHOLD
&&
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
51
void
validate_and_clamp
() {
52
if
(
backpressure_threshold
<
common::constants::MIN_BACKPRESSURE_THRESHOLD
) {
53
backpressure_threshold
=
common::constants::MIN_BACKPRESSURE_THRESHOLD
;
54
}
else
if
(
backpressure_threshold
>
common::constants::MAX_BACKPRESSURE_THRESHOLD
) {
55
backpressure_threshold
=
common::constants::MAX_BACKPRESSURE_THRESHOLD
;
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
unilink::util::InputValidator::is_valid_ipv6
static bool is_valid_ipv6(const std::string &address)
Definition:
input_validator.cc:124
unilink::util::InputValidator::is_valid_ipv4
static bool is_valid_ipv4(std::string_view address)
Definition:
input_validator.cc:95
constants.hpp
input_validator.hpp
unilink::base::constants::MAX_BACKPRESSURE_THRESHOLD
constexpr size_t MAX_BACKPRESSURE_THRESHOLD
Definition:
constants.hpp:31
unilink::base::constants::MIN_BACKPRESSURE_THRESHOLD
constexpr size_t MIN_BACKPRESSURE_THRESHOLD
Definition:
constants.hpp:30
unilink::base::constants::DEFAULT_BACKPRESSURE_THRESHOLD
constexpr size_t DEFAULT_BACKPRESSURE_THRESHOLD
Definition:
constants.hpp:29
unilink
Definition:
common.hpp:37
unilink::config::TcpServerConfig
Definition:
tcp_server_config.hpp:28
unilink::config::TcpServerConfig::idle_timeout_ms
int idle_timeout_ms
Definition:
tcp_server_config.hpp:40
unilink::config::TcpServerConfig::max_connections
int max_connections
Definition:
tcp_server_config.hpp:33
unilink::config::TcpServerConfig::bind_address
std::string bind_address
Definition:
tcp_server_config.hpp:29
unilink::config::TcpServerConfig::validate_and_clamp
void validate_and_clamp()
Definition:
tcp_server_config.hpp:51
unilink::config::TcpServerConfig::backpressure_threshold
size_t backpressure_threshold
Definition:
tcp_server_config.hpp:31
unilink::config::TcpServerConfig::enable_memory_pool
bool enable_memory_pool
Definition:
tcp_server_config.hpp:32
unilink::config::TcpServerConfig::max_port_retries
int max_port_retries
Definition:
tcp_server_config.hpp:37
unilink::config::TcpServerConfig::is_valid
bool is_valid() const
Definition:
tcp_server_config.hpp:43
unilink::config::TcpServerConfig::port
uint16_t port
Definition:
tcp_server_config.hpp:30
unilink::config::TcpServerConfig::enable_port_retry
bool enable_port_retry
Definition:
tcp_server_config.hpp:36
unilink::config::TcpServerConfig::port_retry_interval_ms
int port_retry_interval_ms
Definition:
tcp_server_config.hpp:38
unilink
config
tcp_server_config.hpp
Generated on Wed Mar 25 2026 21:38:57 for unilink by
1.9.1