// spawn the threads for the async TCP sockets for each endpoint
spawn the threads for the async TCP sockets for each endpoint
spawn the threads for the async TCP sockets for each endpoint
pub fn measure_tcp_latency(config: structs::Config) {
    if config.tcp_endpoints.is_empty() {
        return;
    }
    // Iterate over the tcp targets
    for tcp_endpoint in config.tcp_endpoints.iter() {
        let p = String::from(":");
        // Split on the ':' pattern
        if tcp_endpoint.contains(&p) {
            let mut split = tcp_endpoint.split(&p);
            let ip_split = split.next().unwrap();
            let port = split.next().unwrap();
            let ip_lookup = resolve_host(ip_split);
            let ip_v4 = ip_lookup.unwrap();
            let endpoint_name = tcp_endpoint.to_string().clone();
            let join_socket = format!("{}:{}", ip_v4.to_string(), port);
            let sock_addr: SocketAddr =
                join_socket.parse().expect("Unable to parse socket address");
            let config_copy = config.clone();
            let handle = std::thread::spawn(move || {
                let instant_start = Instant::now();
                if TcpStream::connect_timeout(&sock_addr, Duration::new(5, 0)).is_ok() {
                    let instant_end = Instant::now();
                    let delay = instant_end - instant_start;
                    println!(
                        "TCP Target: {:?} Latency: {:?}ms",
                        endpoint_name,
                        delay.as_millis()
                    );
                    // Send the measurement to the TSDB module for formmating and shipping
                    tsdb::write_tsdb(&config_copy, endpoint_name, PROTO_TCP, delay);
                } else {
                    println!("Failed connection to {:?}", sock_addr);
                }
            });
            handle.join().unwrap();
        } else {
            println!("Pattern to split on '{}' not found", p);
        }
    }
}
pub fn measure_tcp_latency ( config : structs :: Config ) { if config . tcp_endpoints . is_empty ( ) { return ; } // Iterate over the tcp targets for tcp_endpoint in config . tcp_endpoints . iter ( ) { let p = String :: from ( " " ) ; // Split on the ':' pattern if tcp_endpoint . contains ( & p ) { let mut split = tcp_endpoint . split ( & p ) ; let ip_split = split . next ( ) . unwrap ( ) ; let port = split . next ( ) . unwrap ( ) ; let ip_lookup = resolve_host ( ip_split ) ; let ip_v4 = ip_lookup . unwrap ( ) ; let endpoint_name = tcp_endpoint . to_string ( ) . clone ( ) ; let join_socket = format ! ( " " ip_v4 to_string ( ) port ) ; let sock_addr : SocketAddr = join_socket . parse ( ) . expect ( " " ) ; let config_copy = config . clone ( ) ; let handle = std :: thread :: spawn ( move | | { let instant_start = Instant :: now ( ) ; if TcpStream :: connect_timeout ( & sock_addr , Duration :: new ( 5 , 0 ) ) . is_ok ( ) { let instant_end = Instant :: now ( ) ; let delay = instant_end - instant_start ; println ! ( " " endpoint_name delay as_millis ( ) ) ; // Send the measurement to the TSDB module for formmating and shipping tsdb :: write_tsdb ( & config_copy , endpoint_name , PROTO_TCP , delay ) ; } else { println ! ( " " sock_addr ) ; } } ) ; handle . join ( ) . unwrap ( ) ; } else { println ! ( " " p ) ; } } }
spawn the threads for the async TCP sockets for each endpoint
spawn the threads for the async TCP sockets for each endpoint
config
structs::Config