mirror of https://github.com/by-sonic/tglock.git
Improve error handling in tcp_check function
Handle potential errors when parsing socket address.
This commit is contained in:
parent
027188229d
commit
cd13fea790
|
|
@ -151,7 +151,10 @@ fn extract_ping_time(output: &str) -> Option<u64> {
|
||||||
// ===== TCP / HTTPS checks (cross-platform) =====
|
// ===== TCP / HTTPS checks (cross-platform) =====
|
||||||
|
|
||||||
pub fn tcp_check(ip: &str, port: u16) -> (bool, Option<u64>) {
|
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();
|
let start = Instant::now();
|
||||||
match TcpStream::connect_timeout(&addr, Duration::from_secs(5)) {
|
match TcpStream::connect_timeout(&addr, Duration::from_secs(5)) {
|
||||||
Ok(_stream) => {
|
Ok(_stream) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue