summaryrefslogtreecommitdiff
path: root/crates/utils/tcp_connection/src/target_configure.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-09-14 22:42:08 +0800
committer魏曹先生 <1992414357@qq.com>2025-09-14 22:42:08 +0800
commitbd923afe53de552c1f69e0db5a4490c73a294b91 (patch)
treebddb85086caa22042281abaf6a73ad5e9bf71e8a /crates/utils/tcp_connection/src/target_configure.rs
parent04253967b5926ff636e3148be62846874c3600aa (diff)
Add TcpServerConfigs
Diffstat (limited to 'crates/utils/tcp_connection/src/target_configure.rs')
-rw-r--r--crates/utils/tcp_connection/src/target_configure.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/utils/tcp_connection/src/target_configure.rs b/crates/utils/tcp_connection/src/target_configure.rs
new file mode 100644
index 0000000..09c4d0d
--- /dev/null
+++ b/crates/utils/tcp_connection/src/target_configure.rs
@@ -0,0 +1,51 @@
+#[derive(Default, Debug, Clone, Copy)]
+pub struct ServerTargetConfig {
+ /// Only process a single connection, then shut down the server.
+ once: bool,
+
+ /// Timeout duration in milliseconds. (0 is Closed)
+ timeout: u64,
+}
+
+impl ServerTargetConfig {
+ /// Set `once` to True
+ /// This method configures the `once` field of `ServerTargetConfig`.
+ pub fn once(mut self) -> Self {
+ self.once = true;
+ self
+ }
+
+ /// Set `timeout` to the given value
+ /// This method configures the `timeout` field of `ServerTargetConfig`.
+ pub fn timeout(mut self, timeout: u64) -> Self {
+ self.timeout = timeout;
+ self
+ }
+
+ /// Set `once` to the given value
+ /// This method configures the `once` field of `ServerTargetConfig`.
+ pub fn set_once(&mut self, enable: bool) {
+ self.once = enable;
+ }
+
+ /// Set `timeout` to the given value
+ /// This method configures the `timeout` field of `ServerTargetConfig`.
+ pub fn set_timeout(&mut self, timeout: u64) {
+ self.timeout = timeout;
+ }
+
+ /// Check if the server is configured to process only a single connection.
+ /// Returns `true` if the server will shut down after processing one connection.
+ pub fn is_once(&self) -> bool {
+ self.once
+ }
+
+ /// Get the current timeout value in milliseconds.
+ /// Returns the timeout duration. A value of 0 indicates the connection is closed.
+ pub fn get_timeout(&self) -> u64 {
+ self.timeout
+ }
+}
+
+#[derive(Default, Debug, Clone, Copy)]
+pub struct ClientTargetConfig {}