34次发布
0.11.0 | 2023年6月23日 |
---|---|
0.10.1 | 2016年6月23日 |
0.9.6 | 2016年5月5日 |
0.3.5 | 2016年3月31日 |
0.1.0 | 2015年8月5日 |
#59 in 数据库实现
每月80次下载
42KB
853 行
simple-stream 
simple-stream是一个在实现std::io::Read和std::io::Write的任何事物之上的缓冲流包装器。它通过缓冲所有读取并检查缓冲区与FrameBuilder进行比对来工作,这将通知流已接收到完整的Frame,并将其从缓冲区中移除。
该软件包包含几种类型的封装选项,并通过rust-openssl提供纯文本和加密流。
示例用法
extern crate simple_stream as ss;
use std::net::TcpStream;
use ss::frame::{SimpleFrame, SimpleFrameBuilder};
use ss::{Plain, NonBlocking};
fn main() {
// Create some non-blocking type that implements Read + Write
let stream = TcpStream::connect("rust-lang.org:80").unwrap();
stream.set_nonblocking(true).unwrap();
// Create a Plain Text stream that sends and receives messages in the
// `SimpleFrame` format.
let mut plain_stream = Plain::<TcpStream, SimpleFrameBuilder>::new(stream);
// Perform a non-blocking write
let buf = vec!(1, 2, 3, 4);
let frame = SimpleFrame::new(&buf[..]);
match plain_stream.nb_send(&frame) {
Ok(_) => { }
Err(e) => println!("Error during write: {}", e)
};
// Perform a non-blocking read
match plain_stream.nb_recv() {
Ok(frames) => {
for _ in frames {
// Do stuff with received frames
}
}
Err(e) => println!("Error during read: {}", e)
};
}
作者
Nathan Sizemore,[email protected]
许可证
simple-stream可在MPL-2.0许可证下使用。有关更多信息,请参阅LICENSE文件。
依赖关系
~1.8–2.7MB
~60K SLoC