[−][src]Crate tcp_stream
std::net::TCP stream on steroids
tcp-stream is a library aiming at providing TLS support to std::net::TcpStream
Examples
To connect to a remote server:
use tcp_stream::{HandshakeError, TcpStream, TLSConfig}; use std::io::{self, Read, Write}; fn main() { let mut stream = TcpStream::connect("google.com:443").unwrap(); stream.set_nonblocking(true).unwrap(); while !stream.is_connected() { if stream.try_connect().unwrap() { break; } } let mut stream = stream.into_tls("google.com", TLSConfig::default()); 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)); }
Structs
Identity | Holds PKCS#12 DER-encoded identity and decryption password |
NativeTlsConnector | Reexport native-tls's |
OpenSslConnector | Reexport openssl's |
OpenSslMethod | Reexport openssl's |
OwnedIdentity | Holds PKCS#12 DER-encoded identity and decryption password |
OwnedTLSConfig | Holds extra TLS configuration |
RustlsConnector | Reexport rustls-connector's |
RustlsConnectorConfig | Reexport rustls-connector's |
TLSConfig | Holds extra TLS configuration |
Enums
HandshakeError | An error returned while performing the handshake |
MidHandshakeTlsStream | A TLS stream which has been interrupted during the handshake |
TcpStream | Wrapper around plain or TLS TCP streams |
Type Definitions
HandshakeResult | Holds either the TLS |
NativeTlsHandshakeError | A |
NativeTlsMidHandshakeTlsStream | A |
NativeTlsStream | A |
OpenSslErrorStack | An |
OpenSslHandshakeError | A |
OpenSslMidHandshakeTlsStream | A |
OpenSslStream | A |
RustlsHandshakeError | A |
RustlsMidHandshakeTlsStream | A |
RustlsStream | A |