Crate simple_stream [−] [src]
The simple-stream crate provides a simple framing protocol over any type that implements the
SStream trait. It also provides built-in support for blocking and non-blocking streams over
Unix file descriptors in both plain-text and SSL through rust-openssl.
Usage
extern crate simple_stream as ss; use std::net::TcpStream; use std::os::unix::io::IntoRawFd; use ss::{Socket, Stream, SSend, SRecv, StreamShutdown}; use ss::nonblocking::plain::Plain; fn main() { // Starting with an established TcpStream let tcp_stream = TcpStream::connect("127.0.0.1").unwrap(); // Create a socket that takes ownership of the underlying fd let socket = Socket::new(tcp_stream.into_raw_fd()); // Pick a built-in stream type to wrap the socket let plain_text = Plain::new(socket); // Create a Stream let mut stream = Stream::new(Box::new(plain_text)); // Write a thing let buffer = "ping".as_bytes(); match stream.send(&buffer[..]) { Ok(num_written) => println!("Wrote: {} bytes", num_written), Err(e) => { println!("Error during write: {}", e); stream.shutdown().unwrap(); } } // Receive all the things match stream.recv() { Ok(()) => { let mut queue = stream.drain_rx_queue(); for msg in queue.drain(..) { println!("Received: {}", String::from_utf8(msg).unwrap()); } } Err(e) => { println!("Error during read: {}", e); stream.shutdown().unwrap(); } } }
Modules
| blocking |
Module containing blocking I/O stream types |
| nonblocking |
Module containing non-blocking I/O stream types |
Structs
| Socket |
Wrapper for file descriptor based sockets |
| Stream |
Generic wrapper for anything implementing the |
Traits
| CloneStream |
The |
| SRecv |
The |
| SSend |
The |
| SStream |
The |
| SocketOptions |
The |
| StreamShutdown |
The |
| TcpOptions |
The |