Struct ethrecv::Controller

source ·
pub struct Controller<E> { /* private fields */ }
Expand description

A controller that can be used to interact with the receiver thread.

Implementations§

source§

impl<E> Controller<E>
where E: 'static,

source

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

Available on crate feature inspect only.

Signal the receiver thread that it should call the PacketHandler::inspect() callback.

This call is asynchronous with regards to the callback; the call may return to the caller before the receiver has received the request.

Examples found in repository?
examples/simple-demo.rs (line 55)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
fn main() {
  let args: Vec<String> = env::args().skip(1).collect();

  let rt = RecvThread::new(&args[0]);

  #[cfg(feature = "idle")]
  let rt = rt.idle_duration(std::time::Duration::from_secs(4));

  let pp = PktProc::default();

  #[cfg(feature = "inspect")]
  let mut ctrl = rt.run(pp).unwrap();

  #[cfg(not(feature = "inspect"))]
  let ctrl = rt.run(pp).unwrap();

  std::thread::sleep(std::time::Duration::from_secs(10));

  #[cfg(feature = "inspect")]
  ctrl.signal_inspect().unwrap();

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  std::thread::sleep(std::time::Duration::from_secs(30));

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  println!("Killing receiver thread..");

  ctrl.shutdown().unwrap();
}
source

pub fn inspect(&self) -> Result<RecvInfo, Error<E>>

Available on crate feature inspect only.
Examples found in repository?
examples/simple-demo.rs (line 59)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
fn main() {
  let args: Vec<String> = env::args().skip(1).collect();

  let rt = RecvThread::new(&args[0]);

  #[cfg(feature = "idle")]
  let rt = rt.idle_duration(std::time::Duration::from_secs(4));

  let pp = PktProc::default();

  #[cfg(feature = "inspect")]
  let mut ctrl = rt.run(pp).unwrap();

  #[cfg(not(feature = "inspect"))]
  let ctrl = rt.run(pp).unwrap();

  std::thread::sleep(std::time::Duration::from_secs(10));

  #[cfg(feature = "inspect")]
  ctrl.signal_inspect().unwrap();

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  std::thread::sleep(std::time::Duration::from_secs(30));

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  println!("Killing receiver thread..");

  ctrl.shutdown().unwrap();
}
source

pub fn signal_shutdown(&self) -> Result<(), Error<E>>

Signal receiver thread to terminate.

This call is asynchronous; at the time this function returns to the caller the termination request may not have reached the receiver thread.

A call to this method should be followed by a call to Controller::wait() to wait for the receiver to report termination.

source

pub fn wait(self) -> Result<(), Error<E>>

Wait for receiver to shut down.

Blocks the calling thread, and assumes that the receiver will be killed by another source.

Use Controller::signal_shutdown() to signal the receiver thread to shut down before calling Controller::wait().

To avoid having the application need perform the two-stage shutdown, use Controller::shutdown() instead.

source

pub fn shutdown(self) -> Result<(), Error<E>>

Tell receiver thread to terminate and wait for for it to end.

Examples found in repository?
examples/simple-demo.rs (line 73)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
fn main() {
  let args: Vec<String> = env::args().skip(1).collect();

  let rt = RecvThread::new(&args[0]);

  #[cfg(feature = "idle")]
  let rt = rt.idle_duration(std::time::Duration::from_secs(4));

  let pp = PktProc::default();

  #[cfg(feature = "inspect")]
  let mut ctrl = rt.run(pp).unwrap();

  #[cfg(not(feature = "inspect"))]
  let ctrl = rt.run(pp).unwrap();

  std::thread::sleep(std::time::Duration::from_secs(10));

  #[cfg(feature = "inspect")]
  ctrl.signal_inspect().unwrap();

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  std::thread::sleep(std::time::Duration::from_secs(30));

  #[cfg(feature = "inspect")]
  {
    let stats = ctrl.inspect().unwrap();
    println!("{stats:#?}");
  }

  println!("Killing receiver thread..");

  ctrl.shutdown().unwrap();
}

Trait Implementations§

source§

impl<E> Drop for Controller<E>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Controller<E>

§

impl<E> !RefUnwindSafe for Controller<E>

§

impl<E> Send for Controller<E>

§

impl<E> Sync for Controller<E>

§

impl<E> Unpin for Controller<E>

§

impl<E> !UnwindSafe for Controller<E>

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.