Struct SendChannel

Source
pub struct SendChannel { /* private fields */ }

Implementations§

Source§

impl SendChannel

Source

pub fn send(&mut self, body: &[u8]) -> Result<(), Error>

Examples found in repository?
examples/split_channel-benchmark-client.rs (line 46)
10fn main() {
11    std::thread::spawn(|| {
12        let mut collector = Collector::new();
13        split_channel::register_biometrics(&mut collector);
14        let fout = File::create("/dev/stdout").unwrap();
15        let mut emit = PlainTextEmitter::new(fout);
16        loop {
17            let now = SystemTime::now()
18                .duration_since(SystemTime::UNIX_EPOCH)
19                .expect("clock should never fail")
20                .as_millis()
21                .try_into()
22                .expect("millis since epoch should fit u64");
23            if let Err(e) = collector.emit(&mut emit, now) {
24                eprintln!("collector error: {}", e);
25            }
26            std::thread::sleep(std::time::Duration::from_millis(249));
27        }
28    });
29    let (options, free) = SplitChannelOptions::from_command_line_relaxed(
30        "Usage: split_channel-benchmark-client [OPTIONS]",
31    );
32    if !free.is_empty() {
33        eprintln!("command ignores positional arguments");
34    }
35    let (mut recv_chan, mut send_chan) = match options.connect() {
36        Ok((recv_chan, send_chan)) => (recv_chan, send_chan),
37        Err(e) => {
38            panic!("err: {}", e);
39        }
40    };
41    let mut counter = 0u64;
42    loop {
43        let msg = format!("ping {}", counter);
44        let buf = msg.as_bytes();
45        counter += 1;
46        send_chan.send(buf).expect("send");
47        let _ = recv_chan.recv().expect("recv");
48    }
49}
More examples
Hide additional examples
examples/split_channel-benchmark-server.rs (line 40)
10fn main() {
11    std::thread::spawn(|| {
12        let mut collector = Collector::new();
13        split_channel::register_biometrics(&mut collector);
14        let fout = File::create("/dev/stdout").unwrap();
15        let mut emit = PlainTextEmitter::new(fout);
16        loop {
17            let now = SystemTime::now()
18                .duration_since(SystemTime::UNIX_EPOCH)
19                .expect("clock should never fail")
20                .as_millis()
21                .try_into()
22                .expect("millis since epoch should fit u64");
23            if let Err(e) = collector.emit(&mut emit, now) {
24                eprintln!("collector error: {}", e);
25            }
26            std::thread::sleep(std::time::Duration::from_millis(249));
27        }
28    });
29
30    let (options, free) = SplitChannelOptions::from_command_line_relaxed(
31        "Usage: split_channel-benchmark-server [OPTIONS]",
32    );
33    if !free.is_empty() {
34        eprintln!("command ignores positional arguments");
35    }
36    let listener = options.bind_to().expect("bind-to");
37
38    let handle_client = |mut recv_chan: RecvChannel, mut send_chan: SendChannel| loop {
39        let buf = recv_chan.recv().expect("recv");
40        send_chan.send(&buf).expect("send");
41    };
42    let mut threads = Vec::new();
43    for stream in listener {
44        match stream {
45            Ok((recv_chan, send_chan)) => {
46                threads.push(std::thread::spawn(move || {
47                    handle_client(recv_chan, send_chan);
48                }));
49            }
50            Err(e) => {
51                eprintln!("failure: {}", e);
52            }
53        }
54    }
55    for thread in threads.into_iter() {
56        thread.join().expect("join");
57    }
58}
Source

pub fn enqueue(&mut self, body: &[u8]) -> Result<(), Error>

Source

pub fn flush(&mut self, events: &mut u32) -> Result<(), Error>

Source

pub fn blocking_drain(&mut self) -> Result<(), Error>

Trait Implementations§

Source§

impl Debug for SendChannel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ProcessEvents for SendChannel

Source§

fn process_events(&mut self, events: &mut u32) -> Result<Option<Vec<u8>>, Error>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.