Skip to content

Commit

Permalink
fix: separate connection managers for Modbus and HTTP
Browse files Browse the repository at this point in the history
- Add dedicated stats_manager for HTTP API
- Keep connection_manager only for Modbus TCP connections
- Prevent HTTP connections from being tracked as Modbus connections
  • Loading branch information
aljen committed Dec 6, 2024
1 parent 94d61a1 commit f33dd84
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/modbus_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct ModbusRelay {
config: RelayConfig,
transport: Arc<RtuTransport>,
connection_manager: Arc<ConnectionManager>,
stats_manager: Arc<ConnectionManager>,
shutdown: broadcast::Sender<()>,
main_shutdown: tokio::sync::watch::Sender<bool>,
tasks: Arc<Mutex<Vec<JoinHandle<()>>>>,
Expand All @@ -37,13 +38,15 @@ impl ModbusRelay {

// Initialize connection manager with connection config from RelayConfig
let connection_manager = Arc::new(ConnectionManager::new(config.connection.clone()));
let stats_manager = Arc::new(ConnectionManager::new(config.connection.clone()));

let (main_shutdown, _) = tokio::sync::watch::channel(false);

Ok(Self {
config,
transport: Arc::new(transport),
connection_manager,
stats_manager,
shutdown: broadcast::channel(1).0,
main_shutdown,
tasks: Arc::new(Mutex::new(Vec::new())),
Expand Down Expand Up @@ -173,7 +176,7 @@ impl ModbusRelay {
// Start HTTP server if enabled
if self.config.http.enabled {
let http_server = {
let manager = Arc::clone(&self.connection_manager);
let manager = Arc::clone(&self.stats_manager);
let rx = self.shutdown.subscribe();
let config = self.config.clone();

Expand Down

0 comments on commit f33dd84

Please sign in to comment.