From 7e1eb27a06e5545b3d1b77b5998dc0463df27d70 Mon Sep 17 00:00:00 2001 From: daniloaz Date: Sun, 24 Mar 2024 20:39:38 +0100 Subject: Created structure and scaffolding for the Lightstreamer client. --- src/connection_options.rs | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/connection_options.rs (limited to 'src/connection_options.rs') diff --git a/src/connection_options.rs b/src/connection_options.rs new file mode 100644 index 0000000..aefb0c0 --- /dev/null +++ b/src/connection_options.rs @@ -0,0 +1,147 @@ +use crate::proxy::Proxy; + +/// Used by LightstreamerClient to provide an extra connection properties data object. +/// Data struct that contains the policy settings used to connect to a Lightstreamer Server. +/// An instance of this struct is attached to every LightstreamerClient as connection_options. +pub struct ConnectionOptions { + content_length: Option, + first_retry_max_delay: Option, + forced_transport: Option, + http_extra_headers: Option>, + http_extra_headers_on_session_creation_only: Option, + idle_timeout: Option, + keepalive_interval: Option, + polling_interval: Option, + proxy: Option, + real_max_bandwidth: Option, + reconnect_timeout: Option, + requested_max_bandwidth: Option, + retry_delay: Option, + reverse_heartbeat_interval: Option, + server_instance_address_ignored: Option, + session_recovery_timeout: Option, + slowing_enabled: Option, + stalled_timeout: Option, +} + +impl ConnectionOptions { + /// Creates a new ConnectionOptions object with default values. + pub fn new() -> ConnectionOptions { + ConnectionOptions::default() + } + + /// Sets the content length. + pub fn set_content_length(&mut self, content_length: usize) { + self.content_length = Some(content_length); + } + + /// Sets the first retry max delay. + pub fn set_first_retry_max_delay(&mut self, first_retry_max_delay: u64) { + self.first_retry_max_delay = Some(first_retry_max_delay); + } + + /// Sets the forced transport. + pub fn set_forced_transport(&mut self, forced_transport: String) { + self.forced_transport = Some(forced_transport); + } + + /// Sets the HTTP extra headers. + pub fn set_http_extra_headers(&mut self, http_extra_headers: Vec<(String, String)>) { + self.http_extra_headers = Some(http_extra_headers); + } + + /// Sets the HTTP extra headers on session creation only. + pub fn set_http_extra_headers_on_session_creation_only(&mut self, http_extra_headers_on_session_creation_only: bool) { + self.http_extra_headers_on_session_creation_only = Some(http_extra_headers_on_session_creation_only); + } + + /// Sets the idle timeout. + pub fn set_idle_timeout(&mut self, idle_timeout: u64) { + self.idle_timeout = Some(idle_timeout); + } + + /// Sets the keepalive interval. + pub fn set_keepalive_interval(&mut self, keepalive_interval: u64) { + self.keepalive_interval = Some(keepalive_interval); + } + + /// Sets the polling interval. + pub fn set_polling_interval(&mut self, polling_interval: u64) { + self.polling_interval = Some(polling_interval); + } + + /// Sets the proxy. + pub fn set_proxy(&mut self, proxy: Proxy) { + self.proxy = Some(proxy); + } + + /// Sets the real max bandwidth. + pub fn set_real_max_bandwidth(&mut self, real_max_bandwidth: u64) { + self.real_max_bandwidth = Some(real_max_bandwidth); + } + + /// Sets the reconnect timeout. + pub fn set_reconnect_timeout(&mut self, reconnect_timeout: u64) { + self.reconnect_timeout = Some(reconnect_timeout); + } + + /// Sets the requested max bandwidth. + pub fn set_requested_max_bandwidth(&mut self, requested: u64) { + self.requested_max_bandwidth = Some(requested); + } + + /// Sets the retry delay. + pub fn set_retry_delay(&mut self, retry_delay: u64) { + self.retry_delay = Some(retry_delay); + } + + /// Sets the reverse heartbeat interval. + pub fn set_reverse_heartbeat_interval(&mut self, reverse_heartbeat_interval: u64) { + self.reverse_heartbeat_interval = Some(reverse_heartbeat_interval); + } + + /// Sets the server instance address ignored. + pub fn set_server_instance_address_ignored(&mut self, server_instance_address_ignored: bool) { + self.server_instance_address_ignored = Some(server_instance_address_ignored); + } + + /// Sets the session recovery timeout. + pub fn set_session_recovery_timeout(&mut self, session_recovery_timeout: u64) { + self.session_recovery_timeout = Some(session_recovery_timeout); + } + + /// Sets the slowing enabled. + pub fn set_slowing_enabled(&mut self, slowing_enabled: bool) { + self.slowing_enabled = Some(slowing_enabled); + } + + /// Sets the stalled timeout. + pub fn set_stalled_timeout(&mut self, stalled_timeout: u64) { + self.stalled_timeout = Some(stalled_timeout); + } +} + +impl Default for ConnectionOptions { + fn default() -> Self { + ConnectionOptions { + content_length: None, + first_retry_max_delay: Some(100), + forced_transport: None, + http_extra_headers: None, + http_extra_headers_on_session_creation_only: Some(false), + idle_timeout: Some(19000), + keepalive_interval: Some(0), + polling_interval: Some(0), + proxy: None, + real_max_bandwidth: None, + reconnect_timeout: Some(3000), + requested_max_bandwidth: None, + retry_delay: Some(4000), + reverse_heartbeat_interval: Some(0), + server_instance_address_ignored: Some(false), + session_recovery_timeout: Some(15000), + slowing_enabled: Some(false), + stalled_timeout: Some(2000), + } + } +} \ No newline at end of file -- cgit v1.2.3