Skip to content

Commit

Permalink
Implement read/write timeout (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM authored Dec 6, 2023
1 parent 50216b1 commit 603fead
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hms2mqtt/src/inverter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::protos::hoymiles::RealData::{HMSStateResponse, RealDataResDTO};
use crc16::{State, MODBUS};
use log::{debug, info};
use log::{debug, info, warn};
use protobuf::Message;
use std::io::{Read, Write};
use std::net::TcpStream;
Expand Down Expand Up @@ -71,6 +71,12 @@ impl<'a> Inverter<'a> {
}

let mut stream = stream.unwrap();
if let Err(e) = stream.set_write_timeout(Some(Duration::new(5, 0))) {
warn!("could not set write timeout: {e}");
}
if let Err(e) = stream.set_read_timeout(Some(Duration::new(5, 0))) {
warn!("could not set read timeout: {e}");
}
if let Err(e) = stream.write(&message) {
debug!(r#"{e}"#);
self.set_state(NetworkState::Offline);
Expand Down

0 comments on commit 603fead

Please sign in to comment.