17 releases (10 breaking)

✓ Uses Rust 2018 edition

0.10.1 Mar 2, 2020
0.9.1 Feb 25, 2020
0.8.0 Nov 7, 2019
0.4.1 Jun 26, 2019

#291 in Network programming

Download history 1859/week @ 2019-12-02 2188/week @ 2019-12-09 1753/week @ 2019-12-16 726/week @ 2019-12-23 627/week @ 2019-12-30 1988/week @ 2020-01-06 2272/week @ 2020-01-13 2328/week @ 2020-01-20 2629/week @ 2020-01-27 2174/week @ 2020-02-03 2009/week @ 2020-02-10 2120/week @ 2020-02-17 3848/week @ 2020-02-24 3126/week @ 2020-03-02 2578/week @ 2020-03-09 3394/week @ 2020-03-16

8,764 downloads per month
Used in 13 crates (2 directly)

BSD-2-Clause and maybe MPL-2.0

21KB
421 lines

tcp-stream

Build Status Build status


lib.rs:

mio's TCP stream on steroids

tcp-stream is a library aiming at providing TLS and futures/tokio support to mio's TcpStream without forcibly using tokio-reactor

Examples

To connect to a remote server:

use tcp_stream::{HandshakeError, TcpStream};

use std::io::{self, Read, Write};

fn main() {
    let stream = TcpStream::connect("google.com:443").unwrap();
    let mut stream = stream.into_tls("google.com", None);

    while let Err(HandshakeError::WouldBlock(mid_handshake)) = stream {
        stream = mid_handshake.handshake();
    }

    let mut stream = stream.unwrap();

    while let Err(err) = stream.write_all(b"GET / HTTP/1.0\r\n\r\n") {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("error: {:?}", err);
        }
    }
    stream.flush().unwrap();
    let mut res = vec![];
    while let Err(err) = stream.read_to_end(&mut res) {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("stream error: {:?}", err);
        }
    }
    println!("{}", String::from_utf8_lossy(&res));
}

Dependencies

~0.4–3.5MB
~78K SLoC