Struct split_channel::SplitChannelOptions
source · pub struct SplitChannelOptions { /* private fields */ }
Implementations§
source§impl SplitChannelOptions
impl SplitChannelOptions
sourcepub fn connect(&self) -> Result<(RecvChannel, SendChannel), Error>
pub fn connect(&self) -> Result<(RecvChannel, SendChannel), Error>
Examples found in repository?
examples/split_channel-benchmark-client.rs (line 35)
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");
}
}
sourcepub fn bind_to(&self) -> Result<Listener, Error>
pub fn bind_to(&self) -> Result<Listener, Error>
Examples found in repository?
examples/split_channel-benchmark-server.rs (line 36)
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 Clone for SplitChannelOptions
impl Clone for SplitChannelOptions
source§fn clone(&self) -> SplitChannelOptions
fn clone(&self) -> SplitChannelOptions
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl CommandLine for SplitChannelOptions
impl CommandLine for SplitChannelOptions
source§fn add_opts(&self, prefix: Option<&str>, opts: &mut Options)
fn add_opts(&self, prefix: Option<&str>, opts: &mut Options)
Add options to the getopts parser.
source§fn matches(&mut self, prefix: Option<&str>, matches: &Matches)
fn matches(&mut self, prefix: Option<&str>, matches: &Matches)
Assign values to self using the provided getopts matches.
source§fn canonical_command_line(&self, prefix: Option<&str>) -> Vec<String>
fn canonical_command_line(&self, prefix: Option<&str>) -> Vec<String>
Return the canonical command line for this CommandLine.
source§fn from_command_line(usage: &str) -> (Self, Vec<String>)
fn from_command_line(usage: &str) -> (Self, Vec<String>)
Parse from the command line. This function will panic if a non-canonical command line is
provided.
source§fn from_command_line_relaxed(usage: &str) -> (Self, Vec<String>)
fn from_command_line_relaxed(usage: &str) -> (Self, Vec<String>)
Parse from the command line. This function will allow a non-canonical command line to
execute.
source§fn from_arguments(usage: &str, args: &[&str]) -> (Self, Vec<String>)
fn from_arguments(usage: &str, args: &[&str]) -> (Self, Vec<String>)
Parse from the provided arguments. This function will panic if a non-canonical command
line is provided.
source§impl Debug for SplitChannelOptions
impl Debug for SplitChannelOptions
source§impl Default for SplitChannelOptions
impl Default for SplitChannelOptions
source§fn default() -> SplitChannelOptions
fn default() -> SplitChannelOptions
Returns the “default value” for a type. Read more
source§impl PartialEq for SplitChannelOptions
impl PartialEq for SplitChannelOptions
source§fn eq(&self, other: &SplitChannelOptions) -> bool
fn eq(&self, other: &SplitChannelOptions) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Eq for SplitChannelOptions
impl StructuralPartialEq for SplitChannelOptions
Auto Trait Implementations§
impl RefUnwindSafe for SplitChannelOptions
impl Send for SplitChannelOptions
impl Sync for SplitChannelOptions
impl Unpin for SplitChannelOptions
impl UnwindSafe for SplitChannelOptions
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