arete_sdk/
lib.rs

1mod connection;
2mod error;
3mod stats;
4mod system;
5
6pub use connection::Connection;
7pub use error::Error;
8pub use stats::Stats;
9use std::sync::{Arc, Mutex};
10use tungstenite::{handshake::client::Response, stream::MaybeTlsStream};
11
12pub fn connect(url: &str) -> Result<(Connection, Response), Error> {
13    // Connect
14    let (mut socket, res) = tungstenite::connect(url)?;
15
16    // Configure non-blocking reads
17    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    // Respond
24    let connection = Connection::new(Arc::new(Mutex::new(socket)));
25    Ok((connection, res))
26}