Increase timeout from 5 s to 7 s.
const PING_PERIOD: Duration = Duration::from_secs(5); // 5 s.
const EMAIL_RESEND_PERIOD: Duration = Duration::from_secs(2 * 60 * 60); // 2 h.
const STATE_PRINT_PERIOD: Duration = Duration::from_secs(15 * 60); // 15 min.
const PING_PERIOD: Duration = Duration::from_secs(5); // 5 s.
const EMAIL_RESEND_PERIOD: Duration = Duration::from_secs(2 * 60 * 60); // 2 h.
const STATE_PRINT_PERIOD: Duration = Duration::from_secs(15 * 60); // 15 min.
+const SOCKET_TIMEOUT: Duration = Duration::from_secs(7);
fn main() -> Result<()> {
println!("Staking Watchdog Watchdog");
fn main() -> Result<()> {
println!("Staking Watchdog Watchdog");
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.connect("192.168.2.102:8739").unwrap();
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.connect("192.168.2.102:8739").unwrap();
- socket
- .set_read_timeout(Some(Duration::from_secs(5)))
- .unwrap();
- socket
- .set_write_timeout(Some(Duration::from_secs(5)))
- .unwrap();
+ socket.set_nonblocking(false).unwrap();
+ socket.set_read_timeout(Some(SOCKET_TIMEOUT)).unwrap();
+ socket.set_write_timeout(Some(SOCKET_TIMEOUT)).unwrap();
loop {
let time_beginning_loop = time::Instant::now();
loop {
let time_beginning_loop = time::Instant::now();
// Send e-mail.
println!("Sending email...");
match send_email(
// Send e-mail.
println!("Sending email...");
match send_email(
+ "Watchdog Watchdog ERROR",
&format!("Error: {:?}", error),
&config.smtp_login,
&config.smtp_password,
&format!("Error: {:?}", error),
&config.smtp_login,
&config.smtp_password,
#[derive(Debug)]
enum PingError {
#[derive(Debug)]
enum PingError {
- SocketError(std::io::Error),
+ SocketReceiveError(std::io::Error),
+ SocketSendError(std::io::Error),
WrongMessageReceived(String),
}
WrongMessageReceived(String),
}
- Err(error) => return Err(PingError::SocketError(error)),
+ Err(error) => return Err(PingError::SocketReceiveError(error)),
- Err(error) => return Err(PingError::SocketError(error)),
+ Err(error) => return Err(PingError::SocketSendError(error)),
}
Ok(time::Instant::now() - now)
}
Ok(time::Instant::now() - now)
fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
let email = Message::builder()
.message_id(None)
fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
let email = Message::builder()
.message_id(None)
- .from("Staking Watchdog <redmine@d-lan.net>".parse()?)
+ .from("Staking Watchdog Watchdog <redmine@d-lan.net>".parse()?)
.to("Greg Burri <greg.burri@gmail.com>".parse()?)
.subject(title)
.header(ContentType::TEXT_PLAIN)
.to("Greg Burri <greg.burri@gmail.com>".parse()?)
.subject(title)
.header(ContentType::TEXT_PLAIN)