Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathansizemore/simple-stream
Plain text and secure stream abstraction with blocking and non-blocking I/O
https://github.com/nathansizemore/simple-stream
Last synced: 3 months ago
JSON representation
Plain text and secure stream abstraction with blocking and non-blocking I/O
- Host: GitHub
- URL: https://github.com/nathansizemore/simple-stream
- Owner: nathansizemore
- License: mpl-2.0
- Created: 2015-07-14T21:16:41.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-06-23T14:58:15.000Z (over 1 year ago)
- Last Synced: 2024-07-05T21:18:25.587Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 128 KB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-stream [][travis-badge]
[Documentation][docs]
---
simple-stream is a buffered stream wrapper over anything that implements
`std::io::Read` and `std::io::Write`. It works by buffering all reads and
checking the buffers against a `FrameBuilder`, which will inform the stream
that a complete `Frame` has been received, and removes it out of the buffer.The crate comes with a few types of Framing options, and provides both a plain
text and encrypted stream via [rust-openssl][rust-openssl-repo].---
## Example Usage
``` rust
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::::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)
};
}
```---
## Author
Nathan Sizemore, [email protected]
## License
simple-stream is available under the MPL-2.0 license. See the LICENSE file for more info.
[travis-badge]: https://travis-ci.org/nathansizemore/simple-stream
[docs]: https://nathansizemore.github.io/simple-stream/simple_stream/index.html
[rust-openssl-repo]: https://github.com/sfackler/rust-openssl