1mod connection;
2mod error;
3mod stats;
4
5pub use connection::Connection;
6pub use error::Error;
7pub use stats::Stats;
8use std::sync::{Arc, Mutex};
9use tungstenite::handshake::client::Response;
10use tungstenite::stream::MaybeTlsStream;
11
12pub fn connect(url: &str) -> Result<(Connection, Response), Error> {
13 let (mut socket, res) = tungstenite::connect(url)?;
15
16 match socket.get_mut() {
18 MaybeTlsStream::Plain(stream) => stream.set_nonblocking(true)?,
19 MaybeTlsStream::Rustls(stream) => stream.get_mut().set_nonblocking(true)?,
20 _ => {}
21 }
22
23 let connection = Connection::new(Arc::new(Mutex::new(socket)));
25 Ok((connection, res))
26}