1
0
mirror of https://github.com/pcvolkmer/checkbar.git synced 2025-04-19 19:16:50 +00:00

Check if tcp connection is ready

This commit is contained in:
Paul-Christian Volkmer 2023-02-26 12:54:37 +01:00
parent fa24ae712c
commit f4a5ac568b

View File

@ -1,6 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use reqwest::Url; use reqwest::Url;
use tokio::io::Interest;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use crate::checker::{CheckResult, CheckState}; use crate::checker::{CheckResult, CheckState};
@ -25,7 +26,21 @@ impl Checker<'_> {
)) ))
.await .await
{ {
Ok(_) => CheckState::Up, Ok(tcp_stream) => {
match tcp_stream
.ready(Interest::READABLE | Interest::WRITABLE)
.await
{
Ok(ready) => {
if !ready.is_empty() {
CheckState::Up
} else {
CheckState::Warn
}
}
_ => CheckState::Warn,
}
}
_ => CheckState::Down, _ => CheckState::Down,
}; };
return CheckResult { return CheckResult {