Struct split_channel::SendChannel
source · pub struct SendChannel { /* private fields */ }
Implementations§
source§impl SendChannel
impl SendChannel
sourcepub fn send(&mut self, body: &[u8]) -> Result<(), Error>
pub fn send(&mut self, body: &[u8]) -> Result<(), Error>
Examples found in repository?
examples/split_channel-benchmark-client.rs (line 46)
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 40)
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");
}
}
pub fn enqueue(&mut self, body: &[u8]) -> Result<(), Error>
pub fn flush(&mut self, events: &mut u32) -> Result<(), Error>
pub fn blocking_drain(&mut self) -> Result<(), Error>
Trait Implementations§
source§impl Debug for SendChannel
impl Debug for SendChannel
source§impl ProcessEvents for SendChannel
impl ProcessEvents for SendChannel
Auto Trait Implementations§
impl RefUnwindSafe for SendChannel
impl Send for SendChannel
impl Sync for SendChannel
impl Unpin for SendChannel
impl UnwindSafe for SendChannel
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