Improve error handling in tcp_check function

Handle potential errors when parsing socket address.
This commit is contained in:
Saikari 2026-03-25 10:46:43 +03:00 committed by GitHub
parent 027188229d
commit cd13fea790
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -151,7 +151,10 @@ fn extract_ping_time(output: &str) -> Option<u64> {
// ===== TCP / HTTPS checks (cross-platform) =====
pub fn tcp_check(ip: &str, port: u16) -> (bool, Option<u64>) {
let addr: SocketAddr = format!("{}:{}", ip, port).parse().unwrap();
let addr: SocketAddr = match format!("{}:{}", ip, port).parse() {
Ok(a) => a,
Err(_) => return (false, None),
};
let start = Instant::now();
match TcpStream::connect_timeout(&addr, Duration::from_secs(5)) {
Ok(_stream) => {