pub struct RecvChannel { /* private fields */ }

Implementations§

source§

impl RecvChannel

source

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
Hide additional 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

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Debug for RecvChannel

source§

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

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

impl ProcessEvents for RecvChannel

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>,

§

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>,

§

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.