Improve multiplexer lib semantics
This commit is contained in:
parent
cca715cfc4
commit
bfc5ef786a
11 changed files with 76 additions and 51 deletions
|
|
@ -2,21 +2,25 @@ use std::{net::TcpListener, thread, time::Duration};
|
|||
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
||||
const PROTOCOLS: [u16; 2] = [0x8002u16, 0x8003u16];
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let server = TcpListener::bind("0.0.0.0:3001").unwrap();
|
||||
let (bearer, _) = server.accept().unwrap();
|
||||
|
||||
let handles =
|
||||
Multiplexer::new(bearer, &vec![0x8002u16, 0x8003u16][..]).unwrap();
|
||||
let mut muxer = Multiplexer::try_setup(bearer, &PROTOCOLS).unwrap();
|
||||
|
||||
for handle in handles {
|
||||
for protocol in PROTOCOLS {
|
||||
let handle = muxer.use_channel(protocol);
|
||||
|
||||
thread::spawn(move || {
|
||||
let (id, rx, tx) = handle;
|
||||
let (rx, _tx) = handle;
|
||||
|
||||
loop {
|
||||
let payload = rx.recv().unwrap();
|
||||
println!("id:{}, length:{}", id, payload.len());
|
||||
println!("id:{}, length:{}", protocol, payload.len());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,25 @@ use std::{net::TcpStream, thread, time::Duration};
|
|||
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
||||
const PROTOCOLS: [u16; 2] = [0x0002u16, 0x0003u16];
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let bearer = TcpStream::connect("127.0.0.1:3001").unwrap();
|
||||
let handles =
|
||||
Multiplexer::new(bearer, &vec![0x0002u16, 0x0003u16][..]).unwrap();
|
||||
let mut muxer = Multiplexer::try_setup(bearer, &PROTOCOLS).unwrap();
|
||||
|
||||
for protocol in PROTOCOLS {
|
||||
let handle = muxer.use_channel(protocol);
|
||||
|
||||
for (idx, handle) in handles.into_iter().enumerate() {
|
||||
thread::spawn(move || {
|
||||
let (id, rx, tx) = handle;
|
||||
let (_rx, tx) = handle;
|
||||
|
||||
loop {
|
||||
let payload = vec![1; 65545];
|
||||
tx.send(payload).unwrap();
|
||||
thread::sleep(Duration::from_millis(
|
||||
50u64 + (idx as u64 * 10u64),
|
||||
50u64 + (protocol as u64 * 10u64),
|
||||
));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue