Tidy up multiplexer api

This commit is contained in:
Santiago Carmuega 2021-11-28 17:03:38 -03:00
parent d4acffaeca
commit dfe8693fbf
11 changed files with 52 additions and 50 deletions

View file

@ -1,6 +1,6 @@
use std::{net::TcpListener, os::unix::net::UnixListener, thread, time::Duration};
use pallas_multiplexer::Multiplexer;
use pallas_multiplexer::{Channel, Multiplexer};
const PROTOCOLS: [u16; 2] = [0x8002u16, 0x8003u16];
@ -11,13 +11,13 @@ fn main() {
let server = UnixListener::bind("/tmp/pallas").unwrap();
let (bearer, _) = server.accept().unwrap();
let mut muxer = Multiplexer::try_setup(bearer, &PROTOCOLS).unwrap();
let mut muxer = Multiplexer::setup(bearer, &PROTOCOLS).unwrap();
for protocol in PROTOCOLS {
let handle = muxer.use_channel(protocol);
thread::spawn(move || {
let (rx, _tx) = handle;
let Channel(_, rx) = handle;
loop {
let payload = rx.recv().unwrap();

View file

@ -1,6 +1,6 @@
use std::{net::TcpStream, os::unix::net::UnixStream, thread, time::Duration};
use pallas_multiplexer::Multiplexer;
use pallas_multiplexer::{Channel, Multiplexer};
const PROTOCOLS: [u16; 2] = [0x0002u16, 0x0003u16];
@ -9,13 +9,13 @@ fn main() {
//let bearer = TcpStream::connect("127.0.0.1:3001").unwrap();
let bearer = UnixStream::connect("/tmp/pallas").unwrap();
let mut muxer = Multiplexer::try_setup(bearer, &PROTOCOLS).unwrap();
let mut muxer = Multiplexer::setup(bearer, &PROTOCOLS).unwrap();
for protocol in PROTOCOLS {
let handle = muxer.use_channel(protocol);
thread::spawn(move || {
let (_rx, tx) = handle;
let Channel(tx, _) = handle;
loop {
let payload = vec![1; 65545];