fn connect_with_timeout(
    url: &str,
    timeout: Option<u64>,
) -> Result<(WebSocket<AutoStream>, Response)> {
    let request = url.into_client_request()?;

    let uri = request.uri();
    let mode = client::uri_mode(uri)?;
    let host = request
        .uri()
        .host()
        .ok_or(Error::Url(UrlError::NoHostName))?;
    let port = uri.port_u16().unwrap_or(match mode {
        Mode::Plain => 80,
        Mode::Tls => 443,
    });
    let addrs = (host, port).to_socket_addrs()?;
    let mut stream = connect_to_some(addrs.as_slice(), &request.uri(), mode, timeout)?;
    NoDelay::set_nodelay(&mut stream, true)?;
    tungstenite::client(request, stream).map_err(|e| match e {
        HandshakeError::Failure(f) => f,
        HandshakeError::Interrupted(_) => panic!("Bug: blocking handshake not blocked"),
    })
}
// Usually ws_stream.read_message() blocks forever,
// with this function, it returns after `timeout` seconds if no data comming in
Usually ws_stream.read_message() blocks forever,
with this function, it returns after `timeout` seconds if no data comming in
Usually ws_stream . read_message () blocks forever with this function it returns after ` timeout ` seconds if no data comming in
fn connect_with_timeout(
    url: &str,
    timeout: Option<u64>,
) -> Result<(WebSocket<AutoStream>, Response)> {
    let request = url.into_client_request()?;
    let uri = request.uri();
    let mode = client::uri_mode(uri)?;
    let host = request
        .uri()
        .host()
        .ok_or(Error::Url(UrlError::NoHostName))?;
    let port = uri.port_u16().unwrap_or(match mode {
        Mode::Plain => 80,
        Mode::Tls => 443,
    });
    let addrs = (host, port).to_socket_addrs()?;
    let mut stream = connect_to_some(addrs.as_slice(), &request.uri(), mode, timeout)?;
    NoDelay::set_nodelay(&mut stream, true)?;
    tungstenite::client(request, stream).map_err(|e| match e {
        HandshakeError::Failure(f) => f,
        HandshakeError::Interrupted(_) => panic!("Bug: blocking handshake not blocked"),
    })
}
fn connect_with_timeout ( url : & str , timeout : Option < u64 > , ) -> Result < ( WebSocket < AutoStream > , Response ) > { let request = url . into_client_request ( ) ? ; let uri = request . uri ( ) ; let mode = client :: uri_mode ( uri ) ? ; let host = request . uri ( ) . host ( ) . ok_or ( Error :: Url ( UrlError :: NoHostName ) ) ? ; let port = uri . port_u16 ( ) . unwrap_or ( match mode { Mode :: Plain => 80 , Mode :: Tls => 443 , } ) ; let addrs = ( host , port ) . to_socket_addrs ( ) ? ; let mut stream = connect_to_some ( addrs . as_slice ( ) , & request . uri ( ) , mode , timeout ) ? ; NoDelay :: set_nodelay ( & mut stream , true ) ? ; tungstenite :: client ( request , stream ) . map_err ( | e | match e { HandshakeError :: Failure ( f ) => f , HandshakeError :: Interrupted ( _ ) => panic ! ( " " ) , } ) }
Usually ws_stream.read_message() blocks forever,
with this function, it returns after `timeout` seconds if no data comming in
Usually ws_stream . read_message () blocks forever with this function it returns after ` timeout ` seconds if no data comming in
url
&str
timeout
Option<u64>