Struct split_channel::RecvChannel
source · pub struct RecvChannel { /* private fields */ }
Implementations§
source§impl RecvChannel
impl RecvChannel
sourcepub fn recv(&mut self) -> Result<Vec<u8>, Error>
pub fn recv(&mut self) -> Result<Vec<u8>, Error>
Examples found in repository?
examples/split_channel-benchmark-client.rs (line 47)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
std::thread::spawn(|| {
let mut collector = Collector::new();
split_channel::register_biometrics(&mut collector);
let fout = File::create("/dev/stdout").unwrap();
let mut emit = PlainTextEmitter::new(fout);
loop {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("clock should never fail")
.as_millis()
.try_into()
.expect("millis since epoch should fit u64");
if let Err(e) = collector.emit(&mut emit, now) {
eprintln!("collector error: {}", e);
}
std::thread::sleep(std::time::Duration::from_millis(249));
}
});
let (options, free) = SplitChannelOptions::from_command_line_relaxed(
"Usage: split_channel-benchmark-client [OPTIONS]",
);
if !free.is_empty() {
eprintln!("command ignores positional arguments");
}
let (mut recv_chan, mut send_chan) = match options.connect() {
Ok((recv_chan, send_chan)) => (recv_chan, send_chan),
Err(e) => {
panic!("err: {}", e);
}
};
let mut counter = 0u64;
loop {
let msg = format!("ping {}", counter);
let buf = msg.as_bytes();
counter += 1;
send_chan.send(buf).expect("send");
let _ = recv_chan.recv().expect("recv");
}
}
More examples
examples/split_channel-benchmark-server.rs (line 39)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn main() {
std::thread::spawn(|| {
let mut collector = Collector::new();
split_channel::register_biometrics(&mut collector);
let fout = File::create("/dev/stdout").unwrap();
let mut emit = PlainTextEmitter::new(fout);
loop {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("clock should never fail")
.as_millis()
.try_into()
.expect("millis since epoch should fit u64");
if let Err(e) = collector.emit(&mut emit, now) {
eprintln!("collector error: {}", e);
}
std::thread::sleep(std::time::Duration::from_millis(249));
}
});
let (options, free) = SplitChannelOptions::from_command_line_relaxed(
"Usage: split_channel-benchmark-server [OPTIONS]",
);
if !free.is_empty() {
eprintln!("command ignores positional arguments");
}
let listener = options.bind_to().expect("bind-to");
let handle_client = |mut recv_chan: RecvChannel, mut send_chan: SendChannel| loop {
let buf = recv_chan.recv().expect("recv");
send_chan.send(&buf).expect("send");
};
let mut threads = Vec::new();
for stream in listener {
match stream {
Ok((recv_chan, send_chan)) => {
threads.push(std::thread::spawn(move || {
handle_client(recv_chan, send_chan);
}));
}
Err(e) => {
eprintln!("failure: {}", e);
}
}
}
for thread in threads.into_iter() {
thread.join().expect("join");
}
}
Trait Implementations§
source§impl AsRawFd for RecvChannel
impl AsRawFd for RecvChannel
source§impl Debug for RecvChannel
impl Debug for RecvChannel
source§impl ProcessEvents for RecvChannel
impl ProcessEvents for RecvChannel
Auto Trait Implementations§
impl RefUnwindSafe for RecvChannel
impl Send for RecvChannel
impl Sync for RecvChannel
impl Unpin for RecvChannel
impl UnwindSafe for RecvChannel
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more