Expand description
Trait system for facilitating non-blocking stream chaining with handshaking
§Example
use url2::prelude::*;
use in_stream::*;
let (send_binding, recv_binding) = crossbeam_channel::unbounded();
let server_thread = std::thread::spawn(move || {
let config = TcpBindConfig::default();
let config = TlsBindConfig::new(config).fake_certificate();
let config = WssBindConfig::new(config);
let mut listener:
InStreamListenerWss<InStreamListenerTls<InStreamListenerTcp>> =
InStreamListenerWss::bind(
&url2!("ws://127.0.0.1:0"),
config
).unwrap();
println!("bound to: {}", listener.binding());
send_binding.send(listener.binding()).unwrap();
let mut srv = loop {
match listener.accept() {
Ok(srv) => break srv,
Err(e) if e.would_block() => std::thread::yield_now(),
Err(e) => panic!("{:?}", e),
}
};
srv.write("hello from server".into()).unwrap();
srv.flush().unwrap();
std::thread::sleep(std::time::Duration::from_millis(100));
let mut res = WsFrame::default();
srv.read(&mut res).unwrap();
assert_eq!("hello from client", res.as_str());
});
let client_thread = std::thread::spawn(move || {
let binding = recv_binding.recv().unwrap();
println!("connect to: {}", binding);
let mut cli: InStreamWss<InStreamTls<InStreamTcp>> =
InStreamWss::connect(
&binding,
WssConnectConfig::new(
TlsConnectConfig::new(
TcpConnectConfig::default()))).unwrap();
cli.write("hello from client".into()).unwrap();
cli.flush().unwrap();
std::thread::sleep(std::time::Duration::from_millis(100));
let mut res = WsFrame::default();
cli.read(&mut res).unwrap();
assert_eq!("hello from server", res.as_str());
});
server_thread.join().unwrap();
client_thread.join().unwrap();
Re-exports§
pub use json_rpc::*;
Modules§
Structs§
- Close
Data - a close message, with a websocket close code https://www.iana.org/assignments/websocket/websocket.xml#close-code-number
- InStream
Listener Mem - bind to a virtual in-process ipc “interface”
- InStream
Listener Tcp - basic tcp socket server/listener
- InStream
Listener Tls - bind to a network interface to listen for TLS connections
- InStream
Listener Wss - bind to a network interface to listen for websocket connections
- InStream
Mem - a singleton memory transport could be used for unit testing or for in-process ipc
- InStream
Tcp - basic tcp socket stream
- InStream
Tls - basic tls wrapper stream
- InStream
Wss - websocket stream
- MemBind
Config - memory connection specific bind config
- MemConnect
Config - memory stream specific connect config
- StdStream
Adapter - provides std::io::{Read, Write} adapter for anything implementing InStreamStd
- TcpBind
Config - configuration options for the listener bind call
- TcpConnect
Config - configuration options for tcp connect
- TlsBind
Config - tls specific bind config
- TlsCertificate
- represents an encrypted TLS certificate, and the passphrase to decrypt it obviously, when serializing, you should only encode the data, not the passphrase
- TlsConnect
Config - tls specific connection config
- WssBind
Config - websocket specific bind configuration
- WssConnect
Config - websocket specific connect config
Enums§
- WsFrame
- enumerates the different websocket message types
Traits§
- InStream
- implement this trait to provide a stream endpoint / socket type connection works like combined std::io::{Read, Write}, but with generic types the underlying stream should be treated as non-blocking. For example, if this is a TLS stream, we may still need to complete a handshaking process before data can actually be written.
- InStream
Config - mixin helper for converting structs into an Any and back again
- InStream
Listener - implement this trait to provide listening/server socket type functionality
- InStream
Listener Std - implement this if your listener accepts std::io::{Read, Write} streams
- InStream
Std - implement this if your stream deals with binary u8 data
- IoError
Ext - provide some convenience functions for working with non-blocking IO
Type Aliases§
- InStream
Config Any - dynamic type for passing around in_stream configuration this is a stopgap until rust allows better constraints on associated types