snapview/tungstenite-rs

set stream property when connect to ws server

Closed this issue · 1 comments

tungstenite-0.17.2: client.rs

pub fn connect_with_config<Req: IntoClientRequest>(
    request: Req,
    config: Option<WebSocketConfig>,
    max_redirects: u8,
) -> Result<(WebSocket<MaybeTlsStream<TcpStream>>, Response)> {
    fn try_client_handshake(
        request: Request,
        config: Option<WebSocketConfig>,
    ) -> Result<(WebSocket<MaybeTlsStream<TcpStream>>, Response)> {
        let uri = request.uri();
        let mode = 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())?;
        NoDelay::set_nodelay(&mut stream, true)?;
      
       //ideally
      stream.set_non_blocking..
      stream.set...
       ....
}

I have searched that many people want non-blocking read instead of using tokio.
The most easiest way may be allow coders to set stream properties of stream.

The developers are free to choose the version that they prefer (it's up to the requirements of their project), we provide the flexibility of using either of them. But I did not quite get what you tried to convey in this issue: was it a question of how to change the stream?

Making stream non-blocking is a simple thing and has always been possible, see #281.